feat: Audit log APIs (#6434)

- Adds the appropriate APIs for Audit Logs.

ref: #6015
This commit is contained in:
Vishnu Narayanan
2023-03-01 20:02:58 +05:30
committed by GitHub
parent daf17046e9
commit d870b0815a
21 changed files with 261 additions and 1 deletions

View File

@@ -10,6 +10,13 @@ RSpec.describe Account do
let!(:account) { create(:account) }
describe 'audit logs' do
it 'returns audit logs' do
# checking whether associated_audits method is present
expect(account.associated_audits.present?).to be false
end
end
it 'returns max limits from global config when enterprise version' do
expect(account.usage_limits).to eq(
{

View File

@@ -0,0 +1,29 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe AutomationRule do
let!(:automation_rule) { create(:automation_rule, name: 'automation rule 1') }
describe 'audit log' do
context 'when automation rule is created' do
it 'has associated audit log created' do
expect(Audited::Audit.where(auditable_type: 'AutomationRule', action: 'create').count).to eq 1
end
end
context 'when automation rule is updated' do
it 'has associated audit log created' do
automation_rule.update(name: 'automation rule 2')
expect(Audited::Audit.where(auditable_type: 'AutomationRule', action: 'update').count).to eq 1
end
end
context 'when automation rule is deleted' do
it 'has associated audit log created' do
automation_rule.destroy!
expect(Audited::Audit.where(auditable_type: 'AutomationRule', action: 'destroy').count).to eq 1
end
end
end
end

View File

@@ -3,8 +3,9 @@
require 'rails_helper'
RSpec.describe Inbox do
let!(:inbox) { create(:inbox) }
describe 'member_ids_with_assignment_capacity' do
let!(:inbox) { create(:inbox) }
let!(:inbox_member_1) { create(:inbox_member, inbox: inbox) }
let!(:inbox_member_2) { create(:inbox_member, inbox: inbox) }
let!(:inbox_member_3) { create(:inbox_member, inbox: inbox) }
@@ -35,4 +36,26 @@ RSpec.describe Inbox do
expect(inbox.member_ids_with_assignment_capacity).to eq(inbox.members.ids)
end
end
describe 'audit log' do
context 'when inbox is created' do
it 'has associated audit log created' do
expect(Audited::Audit.where(auditable_type: 'Inbox', action: 'create').count).to eq 1
end
end
context 'when inbox is updated' do
it 'has associated audit log created' do
inbox.update(auto_assignment_config: { max_assignment_limit: 2 })
expect(Audited::Audit.where(auditable_type: 'Inbox', action: 'update').count).to eq 1
end
end
context 'when inbox is deleted' do
it 'has associated audit log created' do
inbox.destroy!
expect(Audited::Audit.where(auditable_type: 'Inbox', action: 'destroy').count).to eq 1
end
end
end
end

View File

@@ -0,0 +1,30 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Webhook do
let(:account) { create(:account) }
let!(:webhook) { create(:webhook, account: account) }
describe 'audit log' do
context 'when webhook is created' do
it 'has associated audit log created' do
expect(Audited::Audit.where(auditable_type: 'Webhook', action: 'create').count).to eq 1
end
end
context 'when webhook is updated' do
it 'has associated audit log created' do
webhook.update(url: 'https://example.com')
expect(Audited::Audit.where(auditable_type: 'Webhook', action: 'update').count).to eq 1
end
end
context 'when webhook is deleted' do
it 'has associated audit log created' do
webhook.destroy!
expect(Audited::Audit.where(auditable_type: 'Webhook', action: 'destroy').count).to eq 1
end
end
end
end