mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
fix unit tests
GitOrigin-RevId: 34b2aad1b2f4a59909265b60e415d31fd178e9ee
This commit is contained in:
@@ -4,16 +4,24 @@ const logger = require('logger-sharelatex')
|
|||||||
function log(providerId, sessionId, data) {
|
function log(providerId, sessionId, data) {
|
||||||
try {
|
try {
|
||||||
const samlLog = new SamlLog()
|
const samlLog = new SamlLog()
|
||||||
samlLog.providerId = (providerId || '').toString()
|
samlLog.providerId = providerId = (providerId || '').toString()
|
||||||
samlLog.sessionId = (sessionId || '').toString().substr(0, 8)
|
samlLog.sessionId = sessionId = (sessionId || '').toString().substr(0, 8)
|
||||||
samlLog.jsonData = JSON.stringify(data)
|
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 => {
|
samlLog.save(err => {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.error({ err, sessionId, providerId }, 'SamlLog Error')
|
logger.error({ err, sessionId, providerId }, 'SamlLog Error')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} 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() {
|
it('should log data', function() {
|
||||||
samlLog.providerId.should.equal(providerId)
|
samlLog.providerId.should.equal(providerId)
|
||||||
samlLog.sessionId.should.equal(sessionId)
|
samlLog.sessionId.should.equal(sessionId.substr(0, 8))
|
||||||
samlLog.jsonData.should.equal('{"foo":true}')
|
samlLog.jsonData.should.equal('{"foo":true}')
|
||||||
expect(samlLog.data).to.be.undefined
|
expect(samlLog.data).to.be.undefined
|
||||||
samlLog.save.should.have.been.calledOnce
|
samlLog.save.should.have.been.calledOnce
|
||||||
@@ -62,12 +62,12 @@ describe('SamlLogHandler', function() {
|
|||||||
|
|
||||||
it('should log without data and log error', function() {
|
it('should log without data and log error', function() {
|
||||||
samlLog.providerId.should.equal(providerId)
|
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.data).to.be.undefined
|
||||||
expect(samlLog.jsonData).to.be.undefined
|
expect(samlLog.jsonData).to.be.undefined
|
||||||
samlLog.save.should.have.been.calledOnce
|
samlLog.save.should.have.been.calledOnce
|
||||||
LoggerSharelatex.error.should.have.been.calledOnce.and.calledWithMatch(
|
LoggerSharelatex.error.should.have.been.calledOnce.and.calledWithMatch(
|
||||||
{ providerId, sessionId },
|
{ providerId, sessionId: sessionId.substr(0, 8) },
|
||||||
'SamlLog JSON.stringify Error'
|
'SamlLog JSON.stringify Error'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -82,7 +82,7 @@ describe('SamlLogHandler', function() {
|
|||||||
|
|
||||||
it('should log error', function() {
|
it('should log error', function() {
|
||||||
LoggerSharelatex.error.should.have.been.calledOnce.and.calledWithMatch(
|
LoggerSharelatex.error.should.have.been.calledOnce.and.calledWithMatch(
|
||||||
{ err: 'error', providerId, sessionId },
|
{ err: 'error', providerId, sessionId: sessionId.substr(0, 8) },
|
||||||
'SamlLog Error'
|
'SamlLog Error'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user