Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('sends erase write ack messages for erase after when ready', async () => {
const ackCallback = spy()
services.storageMock
.expects('set')
.once()
.withExactArgs(name, 2, {}, match.func)
recordCore.set({ path: 'firstname', callback: ackCallback })
await BBPromise.delay(0)
assert.calledOnce(ackCallback)
assert.calledWithExactly(ackCallback, EVENT.CLIENT_OFFLINE, name)
})
it('triggers ready callback on load', () => {
const readySpy = spy()
recordCore.whenReady(null, readySpy)
assert.calledOnce(readySpy)
assert.calledWithExactly(readySpy, null)
})
it('calls callbackAck with error', async () => {
recordHandler.setDataWithAck(name, data, ackCallback)
handle(errorMsg)
await BBPromise.delay(1)
assert.calledOnce(ackCallback)
assert.calledWithExactly(ackCallback, RECORD_ACTION[errorMsg.action])
})
it('calls callbackAck for setData deleting values', async () => {
recordHandler.setDataWithAck(name, path, undefined, ackCallback)
handle(eraseAckMsg)
await BBPromise.delay(1)
assert.calledOnce(ackCallback)
assert.calledWithExactly(ackCallback, null)
})
it('handles record not found error messages', async () => {
handle({
topic: TOPIC.RECORD,
action: RECORD_ACTION.HEAD_RESPONSE,
originalAction: RECORD_ACTION.HEAD,
version: -1,
name
})
await BBPromise.delay(1)
assert.calledOnce(callbackSpy)
assert.calledWithExactly(callbackSpy, null, false)
assert.calledOnce(resolveSpy)
assert.calledWithExactly(resolveSpy, false)
assert.notCalled(rejectSpy)
})
it('calls query for specific users callback with error message when connection is lost', async () => {
const users = ['userA', 'userB']
presenceHandler.getAll(users, callbackSpy)
const promise = presenceHandler.getAll(users)
promise.then(promiseSuccess).catch(promiseError)
services.simulateConnectionLost()
await BBPromise.delay(1)
assert.calledOnce(callbackSpy)
assert.calledWithExactly(callbackSpy, EVENT.CLIENT_OFFLINE)
assert.notCalled(promiseSuccess)
assert.calledOnce(promiseError)
assert.calledWithExactly(promiseError, EVENT.CLIENT_OFFLINE)
})
it('fails to load maxRuleIterations less than zero initialization', async () => {
const permission = new ConfigPermission({
permissions: testHelper.getBasePermissions(),
cacheEvacuationInterval: 60000,
maxRuleIterations: 0
}, services, config)
assert.calledOnce(services.logger.fatal)
assert.calledWithExactly(services.logger.fatal, EVENT.PLUGIN_INITIALIZATION_ERROR, 'Maximum rule iteration has to be at least one')
})
it('calls callbackAck for setData without path', async () => {
recordHandler.setDataWithAck(name, data, ackCallback)
handle(createUpdateAckMsg)
await BBPromise.delay(1)
assert.calledOnce(ackCallback)
assert.calledWithExactly(ackCallback, null, name)
})
it('handles successful authentication', async () => {
await awaitConnectionAck()
await sendChallenge()
await receiveChallengeAccept()
await sendAuth()
await receiveAuthResponse()
assert.calledOnce(authCallback)
assert.calledWithExactly(authCallback, true, clientData)
})
emitterMock
.expects('emit')
.once()
.withExactArgs(
EVENT.CONNECTION_STATE_CHANGED,
CONNECTION_STATE.AWAITING_AUTHENTICATION
)
await awaitConnectionAck()
await sendChallenge()
await receiveChallengeAccept()
await sendAuth()
await receiveAuthRejectResponse()
assert.calledOnce(authCallback)
assert.calledWithExactly(authCallback, false, { reason: EVENT.INVALID_AUTHENTICATION_DETAILS })
})