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

@@ -0,0 +1,44 @@
require 'rails_helper'
RSpec.describe 'Enterprise Audit API', type: :request do
let!(:account) { create(:account) }
let!(:inbox) { create(:inbox, account: account) }
let!(:admin) { create(:user, account: account, role: :administrator) }
describe 'GET /api/v1/accounts/{account.id}/audit_logs' do
context 'when it is an un-authenticated user' do
it 'does not fetch audit logs associated with the account' do
get "/api/v1/accounts/#{account.id}/audit_logs",
as: :json
expect(response).to have_http_status(:unauthorized)
end
end
context 'when it is an authenticated normal user' do
let(:user) { create(:user, account: account) }
it 'fetches audit logs associated with the account' do
get "/api/v1/accounts/#{account.id}/audit_logs",
headers: user.create_new_auth_token,
as: :json
expect(response).to have_http_status(:unauthorized)
end
end
# check for response in parse
context 'when it is an authenticated admin user' do
it 'fetches audit logs associated with the account' do
get "/api/v1/accounts/#{account.id}/audit_logs",
headers: admin.create_new_auth_token,
as: :json
expect(response).to have_http_status(:success)
json_response = JSON.parse(response.body)
expect(json_response[0]['auditable_type']).to eql('Inbox')
expect(json_response[0]['action']).to eql('create')
expect(json_response[0]['audited_changes']['name']).to eql(inbox.name)
expect(json_response[0]['associated_id']).to eql(account.id)
end
end
end
end