Add coverage for standard params on push subs create (#34092)

This commit is contained in:
Matt Jankowski 2025-03-12 10:29:19 -04:00 committed by GitHub
parent fef446d22c
commit f71a855e2d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 5 deletions

View File

@ -15,6 +15,7 @@ RSpec.describe Api::Web::PushSubscriptionsController do
p256dh: 'BEm_a0bdPDhf0SOsrnB2-ategf1hHoCnpXgQsFj5JCkcoMrMt2WHoPfEYOYPzOIs9mZE8ZUaD7VA5vouy0kEkr8=', p256dh: 'BEm_a0bdPDhf0SOsrnB2-ategf1hHoCnpXgQsFj5JCkcoMrMt2WHoPfEYOYPzOIs9mZE8ZUaD7VA5vouy0kEkr8=',
auth: 'eH_C8rq2raXqlcBVDa1gLg==', auth: 'eH_C8rq2raXqlcBVDa1gLg==',
}, },
standard: standard,
}, },
} }
end end
@ -36,6 +37,7 @@ RSpec.describe Api::Web::PushSubscriptionsController do
}, },
} }
end end
let(:standard) { '1' }
before do before do
sign_in(user) sign_in(user)
@ -51,14 +53,27 @@ RSpec.describe Api::Web::PushSubscriptionsController do
user.reload user.reload
expect(created_push_subscription).to have_attributes( expect(created_push_subscription)
endpoint: eq(create_payload[:subscription][:endpoint]), .to have_attributes(
key_p256dh: eq(create_payload[:subscription][:keys][:p256dh]), endpoint: eq(create_payload[:subscription][:endpoint]),
key_auth: eq(create_payload[:subscription][:keys][:auth]) key_p256dh: eq(create_payload[:subscription][:keys][:p256dh]),
) key_auth: eq(create_payload[:subscription][:keys][:auth])
)
.and be_standard
expect(user.session_activations.first.web_push_subscription).to eq(created_push_subscription) expect(user.session_activations.first.web_push_subscription).to eq(created_push_subscription)
end end
context 'when standard is provided as false value' do
let(:standard) { '0' }
it 'saves push subscription with standard as false' do
post :create, format: :json, params: create_payload
expect(created_push_subscription)
.to_not be_standard
end
end
context 'with a user who has a session with a prior subscription' do context 'with a user who has a session with a prior subscription' do
let!(:prior_subscription) { Fabricate(:web_push_subscription, session_activation: user.session_activations.last) } let!(:prior_subscription) { Fabricate(:web_push_subscription, session_activation: user.session_activations.last) }

View File

@ -16,6 +16,7 @@ RSpec.describe 'API V1 Push Subscriptions' do
subscription: { subscription: {
endpoint: endpoint, endpoint: endpoint,
keys: keys, keys: keys,
standard: standard,
}, },
}.with_indifferent_access }.with_indifferent_access
end end
@ -36,6 +37,7 @@ RSpec.describe 'API V1 Push Subscriptions' do
}, },
}.with_indifferent_access }.with_indifferent_access
end end
let(:standard) { '1' }
let(:scopes) { 'push' } let(:scopes) { 'push' }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) } let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } } let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
@ -66,6 +68,7 @@ RSpec.describe 'API V1 Push Subscriptions' do
user_id: eq(user.id), user_id: eq(user.id),
access_token_id: eq(token.id) access_token_id: eq(token.id)
) )
.and be_standard
expect(response.parsed_body.with_indifferent_access) expect(response.parsed_body.with_indifferent_access)
.to include( .to include(
@ -73,6 +76,17 @@ RSpec.describe 'API V1 Push Subscriptions' do
) )
end end
context 'when standard is provided as false value' do
let(:standard) { '0' }
it 'saves push subscription with standard as false' do
subject
expect(endpoint_push_subscription)
.to_not be_standard
end
end
it 'replaces old subscription on repeat calls' do it 'replaces old subscription on repeat calls' do
2.times { subject } 2.times { subject }