Skip to content

Commit

Permalink
Merge branch 'deviceinfoupdate1115' of https://github.com/open-amt-cl…
Browse files Browse the repository at this point in the history
…oud-toolkit/mps into deviceinfoupdate1115
  • Loading branch information
Walt-Intel committed Nov 9, 2023
2 parents f2b4a09 + 387df9a commit cc199e6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/server/mpsserver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ describe('MPS Server', function () {
expect(deviceDisconnectSpy).toHaveBeenCalledWith('123')
expect(emitSpy).toHaveBeenCalledWith('disconnected', '123')
})
it('should handle onAPFKeepAliveRequest', async () => {
const lastSeenUpdateSpy = jest.spyOn(mps, 'handleLastSeenUpdate')
devices['123'] = { ciraSocket: { tag: { id: 'ABC123XYZ', nodeid: '123' } } } as any
await mps.onAPFKeepAliveRequest('123')
expect(lastSeenUpdateSpy).toHaveBeenCalledWith('123')
})
it('should allow device to connect if exists in db', async () => {
await mps.onAPFProtocolVersion(socket)
expect(deviceSpy).toHaveBeenCalledWith('123')
Expand Down Expand Up @@ -150,6 +156,16 @@ describe('MPS Server', function () {
expect(deviceConnectSpy).toHaveBeenCalledWith('123')
expect(sendUserAuthSpy).toHaveBeenCalledWith(socket)
})
it('should update last seen update', async () => {
const debugSpy = jest.spyOn(logger, 'debug')
testDevice = {} as any
Environment.Config = { instance_name: 'mpsInstance' } as any
devices['123'] = { ciraSocket: { tag: { SystemId: '123', id: 'MNO123XYZ', nodeid: '123' }, end: jest.fn() } } as any
await mps.handleLastSeenUpdate('123')
expect(deviceSpy).toHaveBeenCalledWith('123')
expect(deviceUpdateSpy).toHaveBeenCalledWith({ connectionStatus: true, mpsInstance: 'mpsInstance', lastSeen: testDevice.lastSeen })
expect(debugSpy).toHaveBeenCalledWith('Device last seen status updated in db : 123')
})
it('should NOT verify user auth when NOT valid', async () => {
const deviceConnectSpy = jest.spyOn(mps, 'handleDeviceConnect').mockResolvedValue(null)
await mps.onVerifyUserAuth(socket, 'admin', 'WrongP@ssw0rd')
Expand Down

0 comments on commit cc199e6

Please sign in to comment.