-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/33961 Updated check expiry to use pupil status v2 message (#1256
) * Updated check expiry to use pupil status v2 message * Relocated new updated method within pupil status function * method reference fix * captured cases where check data is not an array type and included spec * updated test case * Removed unused properties before message queue submission
- Loading branch information
1 parent
ea5ace6
commit d8191cf
Showing
3 changed files
with
104 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict' | ||
|
||
/* global describe, expect, it, spyOn */ | ||
|
||
const azureStorageHelper = require('../lib/azure-storage-helper') | ||
const pupilStatusService = require('./pupil-status.service') | ||
|
||
describe('pupil-status.service', () => { | ||
const logger = { | ||
info: () => {}, | ||
verbose: () => {}, | ||
error: () => {} | ||
} | ||
let logPrefix = 'logPrefix' | ||
let checkData = [] | ||
for (let i = 0; i < 300; i++) { | ||
checkData.push({ id: i + 1, isLiveCheck: i < 200, pupilId: i + 1, checkCode: `checkCode${i + 1}` }) | ||
} | ||
describe('updatePupilStatusForLiveChecksV2', () => { | ||
it('calls addMessageToQueue repeadetly based on the number of batches', async () => { | ||
spyOn(azureStorageHelper, 'addMessageToQueue') | ||
try { | ||
await pupilStatusService.updatePupilStatusForLiveChecksV2(logger, logPrefix, checkData) | ||
} catch (err) { | ||
expect(err).not.toHaveBeenCalled() | ||
} | ||
expect(azureStorageHelper.addMessageToQueue).toHaveBeenCalledTimes(2) | ||
}) | ||
it('calls addMessageToQueue for pupil-status queue with version 2 and 100 checks', async () => { | ||
let processedCheckData = [] | ||
for (let i = 0; i < 300; i++) { | ||
processedCheckData.push({ pupilId: i + 1, checkCode: `checkCode${i + 1}` }) | ||
} | ||
|
||
const addMessageToQueueSpy = spyOn(azureStorageHelper, 'addMessageToQueue') | ||
try { | ||
await pupilStatusService.updatePupilStatusForLiveChecksV2(logger, logPrefix, checkData) | ||
} catch (err) { | ||
expect(err).not.toHaveBeenCalled() | ||
} | ||
expect(addMessageToQueueSpy.calls.mostRecent().args[0]).toBe('pupil-status') | ||
expect(addMessageToQueueSpy.calls.mostRecent().args[1].version).toBe(2) | ||
expect(addMessageToQueueSpy.calls.first().args[1].messages).toEqual(processedCheckData.filter(i => i.pupilId >= 1 && i.pupilId <= 100)) | ||
expect(addMessageToQueueSpy.calls.mostRecent().args[1].messages).toEqual(processedCheckData.filter(i => i.pupilId >= 101 && i.pupilId < 201)) | ||
}) | ||
it('calls logger error if addMessageToQueue method throws', async () => { | ||
spyOn(azureStorageHelper, 'addMessageToQueue').and.returnValue(Promise.reject(new Error('error'))) | ||
spyOn(logger, 'error') | ||
try { | ||
await pupilStatusService.updatePupilStatusForLiveChecksV2(logger, logPrefix, checkData) | ||
} catch (err) { | ||
expect(err).toHaveBeenCalled() | ||
} | ||
expect(logger.error).toHaveBeenCalled() | ||
}) | ||
it('should call logger error and return if check data parameter is undefined', async () => { | ||
spyOn(logger, 'error') | ||
spyOn(azureStorageHelper, 'addMessageToQueue') | ||
try { | ||
await pupilStatusService.updatePupilStatusForLiveChecksV2(logger, logPrefix, undefined) | ||
} catch (err) { | ||
expect(err).not.toHaveBeenCalled() | ||
} | ||
expect(azureStorageHelper.addMessageToQueue).not.toHaveBeenCalled() | ||
expect(logger.error).toHaveBeenCalledWith('logPrefix: updatePupilStatusV2(): ERROR: check data provided must be an array') | ||
}) | ||
}) | ||
}) |