Skip to content

Commit 169d9b4

Browse files
committed
unit tests for snapshot updated audit logging
1 parent 44ed441 commit 169d9b4

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

test/unit/forge/auditLog/application_spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,24 @@ describe('Audit Log > Application', async function () {
151151
logEntry.body.snapshot.id.should.equal(SNAPSHOT.hashid)
152152
})
153153

154+
it('Provides a logger for application device snapshot updated', async function () {
155+
const updates = new UpdatesCollection()
156+
updates.pushDifferences({ name: 'snapshot' }, { name: 'snapshot-new-name' })
157+
await logger.application.device.snapshot.updated(ACTIONED_BY, null, APPLICATION, DEVICE, SNAPSHOT, updates)
158+
// check log stored
159+
const logEntry = await getLog()
160+
logEntry.should.have.property('event', 'application.device.snapshot.updated')
161+
logEntry.should.have.property('scope', { id: APPLICATION.hashid, type: 'application' })
162+
logEntry.should.have.property('trigger', { id: ACTIONED_BY.hashid, type: 'user', name: ACTIONED_BY.username })
163+
logEntry.should.have.property('body')
164+
logEntry.body.should.only.have.keys('device', 'snapshot', 'updates')
165+
logEntry.body.device.should.only.have.keys('id', 'name')
166+
logEntry.body.device.id.should.equal(DEVICE.hashid)
167+
logEntry.body.snapshot.should.only.have.keys('id', 'name')
168+
logEntry.body.snapshot.id.should.equal(SNAPSHOT.hashid)
169+
logEntry.body.updates.should.be.an.Array().and.have.length(1)
170+
})
171+
154172
it('Provides a logger for application device snapshot deleted', async function () {
155173
await logger.application.device.snapshot.deleted(ACTIONED_BY, null, APPLICATION, DEVICE, SNAPSHOT)
156174
// check log stored

test/unit/forge/auditLog/project_spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const should = require('should') // eslint-disable-line
2+
const { UpdatesCollection } = require('../../../../forge/auditLog/formatters')
3+
24
const FF_UTIL = require('flowforge-test-utils')
35
// Declare a dummy getLoggers function for type hint only
46
/** @type {import('../../../../forge/auditLog/project').getLoggers} */
@@ -286,6 +288,25 @@ describe('Audit Log > Project', async function () {
286288
logEntry.body.snapshot.id.should.equal(SNAPSHOT.hashid)
287289
})
288290

291+
it('Provides a logger for updating snapshots of a project', async function () {
292+
const updates = new UpdatesCollection()
293+
updates.pushDifferences({ name: 'old' }, { name: 'new' })
294+
await projectLogger.project.snapshot.updated(ACTIONED_BY, null, PROJECT, SNAPSHOT, updates)
295+
// check log stored
296+
const logEntry = await getLog()
297+
logEntry.should.have.property('event', 'project.snapshot.updated')
298+
logEntry.should.have.property('scope', { id: PROJECT.id, type: 'project' })
299+
logEntry.should.have.property('trigger', { id: ACTIONED_BY.hashid, type: 'user', name: ACTIONED_BY.username })
300+
logEntry.should.have.property('body')
301+
logEntry.body.should.only.have.keys('project', 'snapshot', 'updates')
302+
logEntry.body.project.should.only.have.keys('id', 'name')
303+
logEntry.body.project.id.should.equal(PROJECT.id)
304+
logEntry.body.snapshot.should.only.have.keys('id', 'name')
305+
logEntry.body.snapshot.id.should.equal(SNAPSHOT.hashid)
306+
logEntry.body.updates.should.have.length(1)
307+
logEntry.body.updates[0].should.eql({ key: 'name', old: 'old', new: 'new', dif: 'updated' })
308+
})
309+
289310
it('Provides a logger for rolling back a snapshot of a project', async function () {
290311
await projectLogger.project.snapshot.rolledBack(ACTIONED_BY, null, PROJECT, SNAPSHOT)
291312
// check log stored

0 commit comments

Comments
 (0)