mirror of
https://github.com/overleaf/overleaf.git
synced 2025-03-22 02:04:31 +00:00
fix unit tests
GitOrigin-RevId: 34b2aad1b2f4a59909265b60e415d31fd178e9ee
This commit is contained in:
parent
58077c4eff
commit
c2eb3c1caa
2 changed files with 16 additions and 8 deletions
|
@ -4,16 +4,24 @@ const logger = require('logger-sharelatex')
|
|||
function log(providerId, sessionId, data) {
|
||||
try {
|
||||
const samlLog = new SamlLog()
|
||||
samlLog.providerId = (providerId || '').toString()
|
||||
samlLog.sessionId = (sessionId || '').toString().substr(0, 8)
|
||||
samlLog.jsonData = JSON.stringify(data)
|
||||
samlLog.providerId = providerId = (providerId || '').toString()
|
||||
samlLog.sessionId = sessionId = (sessionId || '').toString().substr(0, 8)
|
||||
try {
|
||||
samlLog.jsonData = JSON.stringify(data)
|
||||
} catch (err) {
|
||||
// log but continue on data errors
|
||||
logger.error(
|
||||
{ err, sessionId, providerId },
|
||||
'SamlLog JSON.stringify Error'
|
||||
)
|
||||
}
|
||||
samlLog.save(err => {
|
||||
if (err) {
|
||||
logger.error({ err, sessionId, providerId }, 'SamlLog Error')
|
||||
}
|
||||
})
|
||||
} catch (err) {
|
||||
logger.error({ err, sessionId, providerId }, 'SamlLog JSON.stringify Error')
|
||||
logger.error({ err, sessionId, providerId }, 'SamlLog Error')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ describe('SamlLogHandler', function() {
|
|||
|
||||
it('should log data', function() {
|
||||
samlLog.providerId.should.equal(providerId)
|
||||
samlLog.sessionId.should.equal(sessionId)
|
||||
samlLog.sessionId.should.equal(sessionId.substr(0, 8))
|
||||
samlLog.jsonData.should.equal('{"foo":true}')
|
||||
expect(samlLog.data).to.be.undefined
|
||||
samlLog.save.should.have.been.calledOnce
|
||||
|
@ -62,12 +62,12 @@ describe('SamlLogHandler', function() {
|
|||
|
||||
it('should log without data and log error', function() {
|
||||
samlLog.providerId.should.equal(providerId)
|
||||
samlLog.sessionId.should.equal(sessionId)
|
||||
samlLog.sessionId.should.equal(sessionId.substr(0, 8))
|
||||
expect(samlLog.data).to.be.undefined
|
||||
expect(samlLog.jsonData).to.be.undefined
|
||||
samlLog.save.should.have.been.calledOnce
|
||||
LoggerSharelatex.error.should.have.been.calledOnce.and.calledWithMatch(
|
||||
{ providerId, sessionId },
|
||||
{ providerId, sessionId: sessionId.substr(0, 8) },
|
||||
'SamlLog JSON.stringify Error'
|
||||
)
|
||||
})
|
||||
|
@ -82,7 +82,7 @@ describe('SamlLogHandler', function() {
|
|||
|
||||
it('should log error', function() {
|
||||
LoggerSharelatex.error.should.have.been.calledOnce.and.calledWithMatch(
|
||||
{ err: 'error', providerId, sessionId },
|
||||
{ err: 'error', providerId, sessionId: sessionId.substr(0, 8) },
|
||||
'SamlLog Error'
|
||||
)
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue