test(audit-logs): audit log changes (#1928)

* test: audit log changes

* chore: test
This commit is contained in:
ChengLei Shao 2023-05-28 07:57:59 +08:00 committed by GitHub
parent 29e66f675e
commit ebae59507f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,7 @@ describe('hook', () => {
beforeEach(async () => {
api = mockServer();
await api.db.clean({ drop: true });
api.plugin(logPlugin, { name: 'audit-logs' });
await api.load();
db = api.db;
@ -46,9 +47,22 @@ describe('hook', () => {
const post = await Post.create({ title: 't1' });
await post.update({ title: 't2' });
await post.destroy();
const AuditLog = db.getCollection('auditLogs').model;
const count = await AuditLog.count();
expect(count).toBe(3);
const auditLogs = await db.getCollection('auditLogs').repository.find({
appends: ['changes'],
});
expect(auditLogs.length).toBe(3);
const titleChange = (changes) => {
return changes.find((item) => item.field.name === 'title');
};
expect(titleChange(auditLogs[0].changes).before).toBeNull();
expect(titleChange(auditLogs[0].changes).after).toBe('t1');
expect(titleChange(auditLogs[1].changes).before).toBe('t1');
expect(titleChange(auditLogs[1].changes).after).toBe('t2');
expect(titleChange(auditLogs[2].changes).before).toBe('t2');
});
it('repository', async () => {