Sha256: 8c78680928afeddbe19ef4d7bc4f4198fa3e4ec425dc0d41cc981bf1eb28d7b8

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

require 'functional_spec_helper'

describe 'Webpush' do
  let(:code) { 201 }
  let(:response) { instance_double('Net::HTTPResponse', code: code, body: '') }
  let(:http) { instance_double('Net::HTTP::Persistent', request: response, shutdown: nil) }
  let(:app) { Rpush::Webpush::App.create!(name: 'MyApp', vapid_keypair: VAPID_KEYPAIR) }

  let(:device_reg) {
    { endpoint: 'https://webpush-provider.example.org/push/some-id',
      keys: {'auth' => 'DgN9EBia1o057BdhCOGURA', 'p256dh' => 'BAtxJ--7vHq9IVm8utUB3peJ4lpxRqk1rukCIkVJOomS83QkCnrQ4EyYQsSaCRgy_c8XPytgXxuyAvRJdnTPK4A'} }
  }
  let(:notification) { Rpush::Webpush::Notification.create!(app: app, registration_ids: [device_reg], data: { message: 'test' }) }

  before do
    allow(Net::HTTP::Persistent).to receive_messages(new: http)
  end

  it 'deliveres a notification successfully' do
    expect { Rpush.push }.to change { notification.reload.delivered }.to(true)
  end

  context 'when delivery failed' do
    let(:code) { 404 }
    it 'marks a notification as failed' do
      expect { Rpush.push }.to change { notification.reload.failed }.to(true)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rpush-6.0.0 spec/functional/webpush_spec.rb
rpush-5.4.0 spec/functional/webpush_spec.rb
rpush-5.3.0 spec/functional/webpush_spec.rb