mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-11 15:10:48 +02:00
Merge pull request #2255 from overleaf/em-audit-log
Project audit logs GitOrigin-RevId: 439add2959be140c4f56ce9b41b9f59d432c494d
This commit is contained in:
committed by
sharelatex
parent
f6e4be616c
commit
06de9233b8
@@ -0,0 +1,80 @@
|
||||
const sinon = require('sinon')
|
||||
const { expect } = require('chai')
|
||||
const { ObjectId } = require('mongodb')
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const { Project } = require('../helpers/models/Project')
|
||||
|
||||
const MODULE_PATH =
|
||||
'../../../../app/src/Features/Project/ProjectAuditLogHandler'
|
||||
|
||||
describe('ProjectAuditLogHandler', function() {
|
||||
beforeEach(function() {
|
||||
this.projectId = ObjectId()
|
||||
this.userId = ObjectId()
|
||||
this.ProjectMock = sinon.mock(Project)
|
||||
this.ProjectAuditLogHandler = SandboxedModule.require(MODULE_PATH, {
|
||||
requires: {
|
||||
'../../models/Project': { Project }
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
this.ProjectMock.restore()
|
||||
})
|
||||
|
||||
describe('addEntry', function() {
|
||||
describe('success', function() {
|
||||
beforeEach(async function() {
|
||||
this.dbUpdate = this.ProjectMock.expects('updateOne').withArgs(
|
||||
{ _id: this.projectId },
|
||||
{
|
||||
$push: {
|
||||
auditLog: {
|
||||
$each: [
|
||||
{
|
||||
operation: 'translate',
|
||||
initiatorId: this.userId,
|
||||
info: { destinationLanguage: 'tagalog' },
|
||||
timestamp: sinon.match.typeOf('date')
|
||||
}
|
||||
],
|
||||
$slice: -200
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
this.dbUpdate.chain('exec').resolves({ nModified: 1 })
|
||||
this.operationId = await this.ProjectAuditLogHandler.promises.addEntry(
|
||||
this.projectId,
|
||||
'translate',
|
||||
this.userId,
|
||||
{ destinationLanguage: 'tagalog' }
|
||||
)
|
||||
})
|
||||
|
||||
it('writes a log', async function() {
|
||||
this.ProjectMock.verify()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the project does not exist', function() {
|
||||
beforeEach(function() {
|
||||
this.ProjectMock.expects('updateOne')
|
||||
.chain('exec')
|
||||
.resolves({ nModified: 0 })
|
||||
})
|
||||
|
||||
it('throws an error', async function() {
|
||||
await expect(
|
||||
this.ProjectAuditLogHandler.promises.addEntry(
|
||||
this.projectId,
|
||||
'translate',
|
||||
this.userId,
|
||||
{ destinationLanguage: 'tagalog' }
|
||||
)
|
||||
).to.be.rejected
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user