|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 | 3 | require 'rails_helper'
|
| 4 | +require 'va_notify/default_callback' |
4 | 5 |
|
5 | 6 | RSpec.describe 'VANotify Callbacks', type: :request do
|
6 | 7 | let(:valid_token) { Settings.vanotify.status_callback.bearer_token }
|
|
18 | 19 |
|
19 | 20 | describe 'POST #notifications' do
|
20 | 21 | it 'with found notification' do
|
21 |
| - notification = VANotify::Notification.create(notification_id: notification_id) |
| 22 | + template_id = SecureRandom.uuid |
| 23 | + notification = VANotify::Notification.create(notification_id: notification_id, |
| 24 | + source_location: 'some_location', |
| 25 | + callback_metadata: 'some_callback_metadata', |
| 26 | + template_id: template_id) |
22 | 27 | expect(notification.status).to eq(nil)
|
| 28 | + allow(Rails.logger).to receive(:info) |
| 29 | + callback_obj = double('VANotify::DefaultCallback') |
| 30 | + allow(VANotify::DefaultCallback).to receive(:new).and_return(callback_obj) |
| 31 | + allow(callback_obj).to receive(:call) |
23 | 32 |
|
24 | 33 | post(callback_route,
|
25 | 34 | params: callback_params.to_json,
|
26 | 35 | headers: { 'Authorization' => "Bearer #{valid_token}", 'Content-Type' => 'application/json' })
|
27 | 36 |
|
| 37 | + expect(Rails.logger).to have_received(:info).with( |
| 38 | + "va_notify callbacks - Updating notification: #{notification.id}", |
| 39 | + { source_location: 'some_location', template_id: template_id, callback_metadata: 'some_callback_metadata', |
| 40 | + status: 'delivered' } |
| 41 | + ) |
28 | 42 | expect(response.body).to include('success')
|
29 | 43 | notification.reload
|
30 | 44 | expect(notification.status).to eq('delivered')
|
|
0 commit comments