Add coverage for standard params on push subs create (#34092)
				
					
				
			This commit is contained in:
		@@ -15,6 +15,7 @@ RSpec.describe Api::Web::PushSubscriptionsController do
 | 
			
		||||
          p256dh: 'BEm_a0bdPDhf0SOsrnB2-ategf1hHoCnpXgQsFj5JCkcoMrMt2WHoPfEYOYPzOIs9mZE8ZUaD7VA5vouy0kEkr8=',
 | 
			
		||||
          auth: 'eH_C8rq2raXqlcBVDa1gLg==',
 | 
			
		||||
        },
 | 
			
		||||
        standard: standard,
 | 
			
		||||
      },
 | 
			
		||||
    }
 | 
			
		||||
  end
 | 
			
		||||
@@ -36,6 +37,7 @@ RSpec.describe Api::Web::PushSubscriptionsController do
 | 
			
		||||
      },
 | 
			
		||||
    }
 | 
			
		||||
  end
 | 
			
		||||
  let(:standard) { '1' }
 | 
			
		||||
 | 
			
		||||
  before do
 | 
			
		||||
    sign_in(user)
 | 
			
		||||
@@ -51,14 +53,27 @@ RSpec.describe Api::Web::PushSubscriptionsController do
 | 
			
		||||
 | 
			
		||||
      user.reload
 | 
			
		||||
 | 
			
		||||
      expect(created_push_subscription).to have_attributes(
 | 
			
		||||
        endpoint: eq(create_payload[:subscription][:endpoint]),
 | 
			
		||||
        key_p256dh: eq(create_payload[:subscription][:keys][:p256dh]),
 | 
			
		||||
        key_auth: eq(create_payload[:subscription][:keys][:auth])
 | 
			
		||||
      )
 | 
			
		||||
      expect(created_push_subscription)
 | 
			
		||||
        .to have_attributes(
 | 
			
		||||
          endpoint: eq(create_payload[:subscription][:endpoint]),
 | 
			
		||||
          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)
 | 
			
		||||
    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
 | 
			
		||||
      let!(:prior_subscription) { Fabricate(:web_push_subscription, session_activation: user.session_activations.last) }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@ RSpec.describe 'API V1 Push Subscriptions' do
 | 
			
		||||
      subscription: {
 | 
			
		||||
        endpoint: endpoint,
 | 
			
		||||
        keys: keys,
 | 
			
		||||
        standard: standard,
 | 
			
		||||
      },
 | 
			
		||||
    }.with_indifferent_access
 | 
			
		||||
  end
 | 
			
		||||
@@ -36,6 +37,7 @@ RSpec.describe 'API V1 Push Subscriptions' do
 | 
			
		||||
      },
 | 
			
		||||
    }.with_indifferent_access
 | 
			
		||||
  end
 | 
			
		||||
  let(:standard) { '1' }
 | 
			
		||||
  let(:scopes) { 'push' }
 | 
			
		||||
  let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
 | 
			
		||||
  let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
 | 
			
		||||
@@ -66,6 +68,7 @@ RSpec.describe 'API V1 Push Subscriptions' do
 | 
			
		||||
          user_id: eq(user.id),
 | 
			
		||||
          access_token_id: eq(token.id)
 | 
			
		||||
        )
 | 
			
		||||
        .and be_standard
 | 
			
		||||
 | 
			
		||||
      expect(response.parsed_body.with_indifferent_access)
 | 
			
		||||
        .to include(
 | 
			
		||||
@@ -73,6 +76,17 @@ RSpec.describe 'API V1 Push Subscriptions' do
 | 
			
		||||
        )
 | 
			
		||||
    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
 | 
			
		||||
      2.times { subject }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user