Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Chebotarov committed Nov 4, 2024
1 parent 9cafae7 commit 6f59356
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 0 additions & 1 deletion app/models/clickhouse/events_raw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def organization
# Table name: events_raw
#
# code :string not null
# ingested_at :datetime not null
# precise_total_amount_cents :decimal(40, 15)
# properties :string not null
# timestamp :datetime not null
Expand Down
10 changes: 9 additions & 1 deletion db/migrate/20241030123528_add_hmac_key_to_organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ def up
safety_assured do
execute <<-SQL
UPDATE organizations
SET hmac_key = organizations.api_key
SET hmac_key = first_api_key.value
FROM (
SELECT DISTINCT ON (organization_id)
organization_id,
value
FROM api_keys
ORDER BY organization_id, id ASC
) first_api_key
WHERE organizations.id = first_api_key.organization_id
SQL
end

Expand Down
10 changes: 9 additions & 1 deletion spec/mailers/api_key_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
let(:api_key) { create(:api_key) }
let(:organization) { api_key.organization }

before { create(:membership, organization:, role: :admin) }

describe 'subject' do
subject { mail.subject }

Expand All @@ -17,7 +19,13 @@
describe 'recipients' do
subject { mail.bcc }

it { is_expected.to eq organization.admins.pluck(:email) }
before { create(:membership, organization:, role: :manager) }

specify do
expect(subject)
.to be_present
.and eq organization.admins.pluck(:email)
end
end

describe 'body' do
Expand Down
8 changes: 8 additions & 0 deletions spec/services/api_keys/rotate_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
context 'when API key is missing' do
let(:api_key) { nil }

it 'does not creates a new API key for organization' do
expect { service_result }.not_to change(ApiKey, :count)
end

it 'does not send an API key rotated email' do
expect { service_result }.not_to have_enqueued_mail(ApiKeyMailer, :rotated)
end

it 'returns an error' do
aggregate_failures do
expect(service_result).not_to be_success
Expand Down

0 comments on commit 6f59356

Please sign in to comment.