Skip to content

Commit

Permalink
specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Thrillberg committed Dec 2, 2024
1 parent a65e30b commit cb05118
Showing 1 changed file with 14 additions and 40 deletions.
54 changes: 14 additions & 40 deletions modules/simple_forms_api/spec/services/notification_email_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
require 'rails_helper'
require SimpleFormsApi::Engine.root.join('spec', 'spec_helper.rb')

shared_examples 'an error notification email' do
it 'increments StatsD' do
allow(StatsD).to receive(:increment)

expect { described_class.new(config, notification_type: :error) }.to raise_error(ArgumentError)
expect(StatsD).to have_received(:increment).with('silent_failure', tags: anything)
end
end

describe SimpleFormsApi::NotificationEmail do
%i[confirmation error received].each do |notification_type|
describe '#initialize' do
Expand All @@ -27,14 +36,7 @@
expect { described_class.new(config, notification_type:) }.to raise_error(ArgumentError)
end

context 'error email', if: notification_type == :error do
it 'increments StatsD' do
allow(StatsD).to receive(:increment)

expect { described_class.new(config, notification_type:) }.to raise_error(ArgumentError)
expect(StatsD).to have_received(:increment).with('silent_failure', tags: anything)
end
end
it_behaves_like 'an error notification email' if notification_type == :error
end

context 'missing form_number' do
Expand All @@ -47,14 +49,7 @@
expect { described_class.new(config, notification_type:) }.to raise_error(ArgumentError)
end

context 'error email', if: notification_type == :error do
it 'increments StatsD' do
allow(StatsD).to receive(:increment)

expect { described_class.new(config, notification_type:) }.to raise_error(ArgumentError)
expect(StatsD).to have_received(:increment).with('silent_failure', tags: anything)
end
end
it_behaves_like 'an error notification email' if notification_type == :error
end

context 'missing confirmation_number' do
Expand All @@ -66,14 +61,7 @@
expect { described_class.new(config, notification_type:) }.to raise_error(ArgumentError)
end

context 'error email', if: notification_type == :error do
it 'increments StatsD' do
allow(StatsD).to receive(:increment)

expect { described_class.new(config, notification_type:) }.to raise_error(ArgumentError)
expect(StatsD).to have_received(:increment).with('silent_failure', tags: anything)
end
end
it_behaves_like 'an error notification email' if notification_type == :error
end

context 'missing date_submitted' do
Expand All @@ -85,14 +73,7 @@
expect { described_class.new(config, notification_type:) }.to raise_error(ArgumentError)
end

context 'error email', if: notification_type == :error do
it 'increments StatsD' do
allow(StatsD).to receive(:increment)

expect { described_class.new(config, notification_type:) }.to raise_error(ArgumentError)
expect(StatsD).to have_received(:increment).with('silent_failure', tags: anything)
end
end
it_behaves_like 'an error notification email' if notification_type == :error
end

context 'form not supported' do
Expand All @@ -105,14 +86,7 @@
expect { described_class.new(config, notification_type:) }.to raise_error(ArgumentError)
end

context 'error email', if: notification_type == :error do
it 'increments StatsD' do
allow(StatsD).to receive(:increment)

expect { described_class.new(config, notification_type:) }.to raise_error(ArgumentError)
expect(StatsD).to have_received(:increment).with('silent_failure', tags: anything)
end
end
it_behaves_like 'an error notification email' if notification_type == :error
end
end

Expand Down

0 comments on commit cb05118

Please sign in to comment.