forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauditLogRepository.test.js
More file actions
26 lines (21 loc) · 1.17 KB
/
Copy pathauditLogRepository.test.js
File metadata and controls
26 lines (21 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
jest.mock('../db/index', () => ({ query: jest.fn() }));
const { query } = require('../db/index');
const auditLogRepo = require('../db/auditLogRepository');
describe('auditLogRepository', () => {
beforeEach(() => {
jest.clearAllMocks();
});
test('logAudit inserts and returns row', async () => {
query.mockResolvedValue({ rows: [{ id: 1, entity_type: 'user', action: 'create' }] });
const row = await auditLogRepo.logAudit({ entityType: 'user', action: 'create', performedBy: 1 });
expect(row).toEqual({ id: 1, entity_type: 'user', action: 'create' });
expect(query).toHaveBeenCalledWith(expect.stringContaining('INSERT INTO audit_logs'), ['user', null, 'create', 1, null, null]);
});
test('getAuditLogs returns paginated data', async () => {
query
.mockResolvedValueOnce({ rows: [{ total: '3' }] })
.mockResolvedValueOnce({ rows: [{ id: 1 }, { id: 2 }, { id: 3 }] });
const pageData = await auditLogRepo.getAuditLogs({ page: 1, limit: 3 });
expect(pageData).toEqual({ data: [{ id: 1 }, { id: 2 }, { id: 3 }], total: 3, page: 1, limit: 3 });
});
});