-
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.
Jira ticket: CAMS-461 Co-authored-by: Fritz Madden <[email protected]> Co-authored-by: Arthur Morrow <[email protected]> Co-authored-by: Brian Posey <[email protected]>
- Loading branch information
1 parent
c5ad025
commit 94d2f1d
Showing
12 changed files
with
95 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,56 @@ | ||
import { InvocationContext } from '@azure/functions'; | ||
import { AdminController } from '../../../lib/controllers/admin/admin.controller'; | ||
import { | ||
buildTestResponseError, | ||
createMockAzureFunctionRequest, | ||
} from '../../azure/testing-helpers'; | ||
import handler from './admin.function'; | ||
import { UnauthorizedError } from '../../../lib/common-errors/unauthorized-error'; | ||
|
||
const ADMIN_KEY = 'good-key'; | ||
|
||
describe('Admin function tests', () => { | ||
const originalEnv = { ...process.env }; | ||
const context = new InvocationContext(); | ||
|
||
beforeEach(() => { | ||
process.env = { | ||
...originalEnv, | ||
ADMIN_KEY, | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
process.env = originalEnv; | ||
}); | ||
|
||
// TODO: test the function | ||
test('testing Migration Delete function', () => {}); | ||
test('admin handler will return a 401 response code if api key is missing from body', async () => { | ||
const badRequest = createMockAzureFunctionRequest({ | ||
method: 'DELETE', | ||
body: { apiKey: 'bad-key' }, //pragma: allowlist secret | ||
}); | ||
const error = new UnauthorizedError('ADMIN-FUNCTION', { | ||
message: 'API key was missing or did not match.', | ||
}); | ||
const { azureHttpResponse } = buildTestResponseError(error); | ||
const response = await handler(badRequest, context); | ||
expect(response).toEqual(azureHttpResponse); | ||
}); | ||
|
||
test('admin handler should call controller when invoked', async () => { | ||
const request = createMockAzureFunctionRequest({ | ||
method: 'DELETE', | ||
body: { apiKey: ADMIN_KEY }, | ||
}); | ||
|
||
const adminControllerSpy = jest | ||
.spyOn(AdminController.prototype, 'handleRequest') | ||
.mockResolvedValue({ statusCode: 204 }); | ||
|
||
const result = await handler(request, context); | ||
|
||
expect(adminControllerSpy).toHaveBeenCalled(); | ||
expect(result.status).toEqual(204); | ||
}); | ||
}); |
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
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
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