Skip to content

Commit

Permalink
Allow admins to modify interview fields
Browse files Browse the repository at this point in the history
  • Loading branch information
zachlatta committed Jan 28, 2018
1 parent 6e44b2b commit 08300c7
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 5 deletions.
5 changes: 4 additions & 1 deletion api/app/controllers/v1/new_club_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ def club_application_params
:other_surprising_or_amusing_discovery,
:curious_what_convinced,
:curious_how_did_hear,
:point_of_contact_id
:point_of_contact_id,
:interviewed_at,
:interview_duration,
:interview_notes
)
end
end
Expand Down
6 changes: 5 additions & 1 deletion api/app/policies/new_club_application_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ def show?
end

def update?
user_added?
if user.admin?
true
else
user_added?
end
end

def add_user?
Expand Down
87 changes: 84 additions & 3 deletions api/spec/requests/v1/new_club_applications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@
end

describe 'PATCH /v1/new_club_applications/:id' do
let(:club_application) { create(:new_club_application) }

before { user.new_club_applications << club_application }
let(:club_application) do
app = create(:new_club_application)
app.users << user
app
end

it 'requires_authentication' do
patch "/v1/new_club_applications/#{club_application.id}", params: {
Expand Down Expand Up @@ -284,6 +286,85 @@
json['errors']['base']
).to include('cannot edit application after submit')
end

it 'fails to update interview fields' do
application = create(:completed_new_club_application)
create(:completed_leader_profile, new_club_application: application,
user: user)
application.update_attributes(point_of_contact: user)

# application must be submitted for any modification (even by admins) to
# be allowed
post "/v1/new_club_applications/#{application.id}/submit",
headers: auth_headers

patch "/v1/new_club_applications/#{application.id}",
headers: auth_headers,
params: {
interviewed_at: Time.current,
interview_duration: 30.minutes,
interview_notes: 'Went well.'
}

expect(response.status).to eq(422)
end

context 'when admin' do
let(:club_application) do
app = create(:completed_new_club_application)
app.submit!
app.save

app
end

before do
user.make_admin!
user.save
end

it 'allows updating interview fields' do
patch "/v1/new_club_applications/#{club_application.id}",
headers: auth_headers,
params: {
interviewed_at: Time.current,
interview_duration: 30.minutes,
interview_notes: 'Went well.'
}

expect(response.status).to eq(200)
expect(
Time.zone.parse(json['interviewed_at'])
).to be_within(3.seconds).of(Time.current)
expect(json).to include('interview_duration' => 30.minutes.to_s)
expect(json).to include('interview_notes' => 'Went well.')
end

it 'fails if not all interview fields are set' do
patch "/v1/new_club_applications/#{club_application.id}",
headers: auth_headers,
params: {
interviewed_at: Time.current
}

expect(response.status).to eq(422)
expect(json['errors']).to include('interview_duration')
expect(json['errors']).to include('interview_notes')
end

it 'fails if application is not submitted' do
club_application = create(:new_club_application)

patch "/v1/new_club_applications/#{club_application.id}",
headers: auth_headers,
params: {
interviewed_at: Time.current
}

expect(response.status).to eq(422)
expect(json['errors']['submitted_at']).to include("can't be blank")
end
end
end

describe 'POST /v1/new_club_applications/:id/add_user' do
Expand Down

0 comments on commit 08300c7

Please sign in to comment.