add submission update api
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe ProcessSubmissionExpiredJob do
|
||||
let(:account) { create(:account) }
|
||||
let(:user) { create(:user, account:) }
|
||||
let(:template) { create(:template, account:, author: user) }
|
||||
let(:expire_at) { 2.days.from_now.change(usec: 0) }
|
||||
let(:submission) do
|
||||
create(:submission, :with_submitters, template:, created_by_user: user, expire_at:)
|
||||
end
|
||||
|
||||
before { allow(WebhookUrls).to receive(:enqueue_events) }
|
||||
|
||||
describe '#perform' do
|
||||
it 'enqueues the expired event when the scheduled expire_at still matches' do
|
||||
described_class.new.perform('submission_id' => submission.id, 'expire_at' => expire_at.to_i)
|
||||
|
||||
expect(WebhookUrls).to have_received(:enqueue_events).with(submission, 'submission.expired')
|
||||
end
|
||||
|
||||
it 'enqueues the expired event for legacy jobs scheduled without an expire_at param' do
|
||||
described_class.new.perform('submission_id' => submission.id)
|
||||
|
||||
expect(WebhookUrls).to have_received(:enqueue_events).with(submission, 'submission.expired')
|
||||
end
|
||||
|
||||
it 'skips a stale job scheduled for an earlier expire_at that was extended' do
|
||||
submission.update!(expire_at: 3.days.from_now)
|
||||
|
||||
described_class.new.perform('submission_id' => submission.id, 'expire_at' => expire_at.to_i)
|
||||
|
||||
expect(WebhookUrls).not_to have_received(:enqueue_events)
|
||||
end
|
||||
|
||||
it 'skips a stale job scheduled for a later expire_at that was shortened' do
|
||||
submission.update!(expire_at: 1.day.from_now)
|
||||
|
||||
described_class.new.perform('submission_id' => submission.id, 'expire_at' => expire_at.to_i)
|
||||
|
||||
expect(WebhookUrls).not_to have_received(:enqueue_events)
|
||||
end
|
||||
|
||||
it 'skips a stale job when the expiration has been cleared' do
|
||||
submission.update!(expire_at: nil)
|
||||
|
||||
described_class.new.perform('submission_id' => submission.id, 'expire_at' => expire_at.to_i)
|
||||
|
||||
expect(WebhookUrls).not_to have_received(:enqueue_events)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -259,6 +259,62 @@ describe 'Submission API' do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT /api/submissions/:id' do
|
||||
it 'updates the submission name' do
|
||||
submission = create(:submission, :with_submitters, template: templates[0], created_by_user: author)
|
||||
|
||||
put "/api/submissions/#{submission.id}", headers: { 'x-auth-token': author.access_token.token }, params: {
|
||||
name: 'Updated Name'
|
||||
}.to_json
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(submission.reload.name).to eq('Updated Name')
|
||||
expect(response.parsed_body['name']).to eq('Updated Name')
|
||||
end
|
||||
|
||||
it 'updates the expiration date' do
|
||||
submission = create(:submission, :with_submitters, template: templates[0], created_by_user: author)
|
||||
expire_at = 1.week.from_now.change(usec: 0)
|
||||
|
||||
put "/api/submissions/#{submission.id}", headers: { 'x-auth-token': author.access_token.token }, params: {
|
||||
expire_at: expire_at.iso8601
|
||||
}.to_json
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(submission.reload.expire_at).to be_within(1.second).of(expire_at)
|
||||
end
|
||||
|
||||
it 'clears the expiration date when passed nil' do
|
||||
submission = create(:submission, :with_submitters, template: templates[0], created_by_user: author,
|
||||
expire_at: 1.week.from_now)
|
||||
|
||||
put "/api/submissions/#{submission.id}", headers: { 'x-auth-token': author.access_token.token }, params: {
|
||||
expire_at: nil
|
||||
}.to_json
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(submission.reload.expire_at).to be_nil
|
||||
end
|
||||
|
||||
it 'archives and unarchives the submission' do
|
||||
submission = create(:submission, :with_submitters, template: templates[0], created_by_user: author)
|
||||
|
||||
put "/api/submissions/#{submission.id}", headers: { 'x-auth-token': author.access_token.token }, params: {
|
||||
archived: true
|
||||
}.to_json
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(submission.reload.archived_at).not_to be_nil
|
||||
|
||||
put "/api/submissions/#{submission.id}", headers: { 'x-auth-token': author.access_token.token }, params: {
|
||||
archived: false
|
||||
}.to_json
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(submission.reload.archived_at).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'view-only (CC) party' do
|
||||
let(:viewer_template) { create(:template, account:, author:, submitter_count: 2, only_field_types: %w[text]) }
|
||||
let(:viewer_uuid) { viewer_template.submitters.second['uuid'] }
|
||||
|
||||
Reference in New Issue
Block a user