|
| 1 | +RSpec.describe NotificationToken do |
| 2 | + describe '#description' do |
| 3 | + subject { notification.description } |
| 4 | + |
| 5 | + let(:token) { create(:workflow_token, description: 'My API Token') } |
| 6 | + let(:notification) do |
| 7 | + create(:notification, type: 'NotificationToken', notifiable: token) |
| 8 | + end |
| 9 | + |
| 10 | + it { expect(subject).to include('My API Token') } |
| 11 | + it { expect(subject).to include('disabled') } |
| 12 | + |
| 13 | + context 'when token has no description' do |
| 14 | + let(:token) { create(:workflow_token, description: '') } |
| 15 | + |
| 16 | + it { expect(subject).to include('Token') } |
| 17 | + end |
| 18 | + end |
| 19 | + |
| 20 | + describe '#excerpt' do |
| 21 | + subject { notification.excerpt } |
| 22 | + |
| 23 | + let(:token) { create(:workflow_token) } |
| 24 | + let(:event_payload) do |
| 25 | + { 'summary' => 'Failed to report back to GitHub: Unauthorized request.' } |
| 26 | + end |
| 27 | + let(:notification) do |
| 28 | + create(:notification, type: 'NotificationToken', notifiable: token, event_payload: event_payload) |
| 29 | + end |
| 30 | + |
| 31 | + it { expect(subject).to eq('Failed to report back to GitHub: Unauthorized request.') } |
| 32 | + |
| 33 | + context 'when summary is missing' do |
| 34 | + let(:event_payload) { {} } |
| 35 | + |
| 36 | + it { expect(subject).to eq('Token was disabled due to authorization failure') } |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + describe '#avatar_objects' do |
| 41 | + subject { notification.avatar_objects } |
| 42 | + |
| 43 | + let(:token) { create(:workflow_token) } |
| 44 | + let(:notification) do |
| 45 | + create(:notification, type: 'NotificationToken', notifiable: token) |
| 46 | + end |
| 47 | + |
| 48 | + it { expect(subject).to contain_exactly(token.executor) } |
| 49 | + |
| 50 | + context 'when token is deleted' do |
| 51 | + before { token.destroy } |
| 52 | + |
| 53 | + it { expect(subject).to be_empty } |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + describe '#link_text' do |
| 58 | + subject { notification.link_text } |
| 59 | + |
| 60 | + let(:token) { create(:workflow_token) } |
| 61 | + let(:notification) do |
| 62 | + create(:notification, type: 'NotificationToken', notifiable: token) |
| 63 | + end |
| 64 | + |
| 65 | + it { expect(subject).to eq('Token') } |
| 66 | + end |
| 67 | + |
| 68 | + describe '#link_path' do |
| 69 | + subject { notification.link_path } |
| 70 | + |
| 71 | + let(:token) { create(:workflow_token) } |
| 72 | + let(:notification) do |
| 73 | + create(:notification, type: 'NotificationToken', notifiable: token) |
| 74 | + end |
| 75 | + |
| 76 | + it { expect(subject).to eq(Rails.application.routes.url_helpers.token_path(token)) } |
| 77 | + |
| 78 | + context 'when notifiable is blank' do |
| 79 | + let(:notification) do |
| 80 | + create(:notification, type: 'NotificationToken', notifiable: nil) |
| 81 | + end |
| 82 | + |
| 83 | + it { expect(subject).to be_nil } |
| 84 | + end |
| 85 | + end |
| 86 | +end |
0 commit comments