diff --git a/app/models/clickhouse/events_raw.rb b/app/models/clickhouse/events_raw.rb index 800507e5b9b2..4673fbe9733e 100644 --- a/app/models/clickhouse/events_raw.rb +++ b/app/models/clickhouse/events_raw.rb @@ -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 diff --git a/db/migrate/20241030123528_add_hmac_key_to_organizations.rb b/db/migrate/20241030123528_add_hmac_key_to_organizations.rb index 9935d6cc8ae3..8e2c3706ded5 100644 --- a/db/migrate/20241030123528_add_hmac_key_to_organizations.rb +++ b/db/migrate/20241030123528_add_hmac_key_to_organizations.rb @@ -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 diff --git a/spec/mailers/api_key_mailer_spec.rb b/spec/mailers/api_key_mailer_spec.rb index a1659a93bd2e..a628c07c3e9c 100644 --- a/spec/mailers/api_key_mailer_spec.rb +++ b/spec/mailers/api_key_mailer_spec.rb @@ -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 } @@ -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 diff --git a/spec/services/api_keys/rotate_service_spec.rb b/spec/services/api_keys/rotate_service_spec.rb index 92c52a35de7f..ed2e57109dac 100644 --- a/spec/services/api_keys/rotate_service_spec.rb +++ b/spec/services/api_keys/rotate_service_spec.rb @@ -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