-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #923 from US-Trustee-Program/CAMS-283-sync-timer-f…
…unction CAMS-283 - Add office staff sync timer
- Loading branch information
Showing
9 changed files
with
145 additions
and
51 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
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
39 changes: 39 additions & 0 deletions
39
backend/functions/office-staff-sync/office-staff-sync.function.test.ts
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,39 @@ | ||
import { LoggerImpl } from '../lib/adapters/services/logger.service'; | ||
import { CamsError } from '../lib/common-errors/cams-error'; | ||
import timerTrigger from './office-staff-sync.function'; | ||
import { Timer } from '@azure/functions'; | ||
import { createMockAzureFunctionContext } from '../azure/testing-helpers'; | ||
import { OfficesController } from '../lib/controllers/offices/offices.controller'; | ||
|
||
describe('Office Staff Sync Function tests', () => { | ||
const context = createMockAzureFunctionContext(); | ||
const timer: Timer = { | ||
isPastDue: false, | ||
schedule: { | ||
adjustForDST: false, | ||
}, | ||
scheduleStatus: { | ||
last: '', | ||
next: '', | ||
lastUpdated: '', | ||
}, | ||
}; | ||
|
||
test('Should call offices controller method handleTimer', async () => { | ||
const handleTimer = jest | ||
.spyOn(OfficesController.prototype, 'handleTimer') | ||
.mockImplementation(() => Promise.resolve()); | ||
await timerTrigger(timer, context); | ||
expect(handleTimer).toHaveBeenCalled(); | ||
}); | ||
|
||
test('Should log a camsError if handleTimer throws a CamsError', async () => { | ||
const handleTimer = jest | ||
.spyOn(OfficesController.prototype, 'handleTimer') | ||
.mockRejectedValue(new CamsError('TEST_MODULE', { message: 'error' })); | ||
const camsError = jest.spyOn(LoggerImpl.prototype, 'camsError').mockImplementation(() => {}); | ||
await timerTrigger(timer, context); | ||
expect(handleTimer).toHaveBeenCalled(); | ||
expect(camsError).toHaveBeenCalled(); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
backend/functions/office-staff-sync/office-staff-sync.function.ts
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,31 @@ | ||
import * as dotenv from 'dotenv'; | ||
import { app, InvocationContext, Timer } from '@azure/functions'; | ||
import ContextCreator from '../azure/application-context-creator'; | ||
import { initializeApplicationInsights } from '../azure/app-insights'; | ||
import { toAzureError } from '../azure/functions'; | ||
import { OfficesController } from '../lib/controllers/offices/offices.controller'; | ||
|
||
dotenv.config(); | ||
|
||
initializeApplicationInsights(); | ||
|
||
const MODULE_NAME = 'OFFICE-STAFF-SYNC-FUNCTION'; | ||
|
||
export default async function timerTrigger( | ||
_myTimer: Timer, | ||
invocationContext: InvocationContext, | ||
): Promise<void> { | ||
const logger = ContextCreator.getLogger(invocationContext); | ||
try { | ||
const appContext = await ContextCreator.getApplicationContext({ invocationContext, logger }); | ||
const controller = new OfficesController(); | ||
await controller.handleTimer(appContext); | ||
} catch (error) { | ||
toAzureError(logger, MODULE_NAME, error); | ||
} | ||
} | ||
|
||
app.timer('office-staff-sync', { | ||
schedule: '0 0 * * * *', | ||
handler: timerTrigger, | ||
}); |
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