diff options
author | Daniel M Brasil <danielmbrasil@protonmail.com> | 2024-06-10 10:33:48 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-10 13:33:48 +0000 |
commit | 77c2216e47c8ffba4dde91c1a300cf924a8e5c05 (patch) | |
tree | eb5cfc99dfeb7e25bdf2fce2329b7963bb19b252 /spec | |
parent | 0cf91213c93e87ce775453ae20a3d9a7f9b4e8d0 (diff) |
fix: Return HTTP 422 when scheduled status time is less than 5 minutes (#30584)
Diffstat (limited to 'spec')
-rw-r--r-- | spec/requests/api/v1/statuses_spec.rb | 26 | ||||
-rw-r--r-- | spec/services/post_status_service_spec.rb | 10 |
2 files changed, 36 insertions, 0 deletions
diff --git a/spec/requests/api/v1/statuses_spec.rb b/spec/requests/api/v1/statuses_spec.rb index 694861fb1c3..2f99b35e74f 100644 --- a/spec/requests/api/v1/statuses_spec.rb +++ b/spec/requests/api/v1/statuses_spec.rb @@ -193,6 +193,32 @@ describe '/api/v1/statuses' do expect(response).to have_http_status(404) end end + + context 'when scheduling a status' do + let(:params) { { status: 'Hello world', scheduled_at: 10.minutes.from_now } } + let(:account) { user.account } + + it 'returns HTTP 200' do + subject + + expect(response).to have_http_status(200) + end + + it 'creates a scheduled status' do + expect { subject }.to change { account.scheduled_statuses.count }.from(0).to(1) + end + + context 'when the scheduling time is less than 5 minutes' do + let(:params) { { status: 'Hello world', scheduled_at: 4.minutes.from_now } } + + it 'does not create a scheduled status', :aggregate_failures do + subject + + expect(response).to have_http_status(422) + expect(account.scheduled_statuses).to be_empty + end + end + end end describe 'DELETE /api/v1/statuses/:id' do diff --git a/spec/services/post_status_service_spec.rb b/spec/services/post_status_service_spec.rb index 11bf4c30ea3..f21548b5f2c 100644 --- a/spec/services/post_status_service_spec.rb +++ b/spec/services/post_status_service_spec.rb @@ -61,6 +61,16 @@ RSpec.describe PostStatusService do status2 = subject.call(account, text: 'test', idempotency: 'meepmeep', scheduled_at: future) expect(status2.id).to eq status1.id end + + context 'when scheduled_at is less than min offset' do + let(:invalid_scheduled_time) { 4.minutes.from_now } + + it 'raises invalid record error' do + expect do + subject.call(account, text: 'Hi future!', scheduled_at: invalid_scheduled_time) + end.to raise_error(ActiveRecord::RecordInvalid) + end + end end it 'creates response to the original status of boost' do |