-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get all tags in alarm handler rather than just App #2636
Conversation
@@ -94,6 +95,7 @@ describe('Handler', () => { | |||
}); | |||
|
|||
it('should throw error if the fetch HTTP call fails', async () => { | |||
(getTags as jest.Mock).mockResolvedValueOnce({ App: 'mock-app' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand why we didn't need this line before.
For some reason the tests were failing to initialise with the mock Fetch error
below, but no useful stack trace. I presume Promises can be a bit like scala Futures in that respect.
I guessed that getTags was the only other thing that could call fetch, and by mocking that it started working.
The strange thing was how did it work before? It definitely worked ok if I shelve the commit in this PR.
It was failing locally and also when I pushed.
This is one of the tests that does need to use a mocked fetch (as opposed to calling a pure function) as it's specifically testing what happens if it fails the http call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error was
/Users/john_duffell/code/support-service-lambdas/handlers/alarms-handler/test/index.test.ts:78
.mockResolvedValue(Promise.reject(new Error('Fetch error')));
^
Error: Fetch error
at Object.<anonymous> (/Users/john_duffell/code/support-service-lambdas/handlers/alarms-handler/test/index.test.ts:100:38)
at Promise.then.completed (/Users/john_duffell/code/support-service-lambdas/node_modules/.pnpm/[email protected]/node_modules/jest-circus/build/utils.js:298:28)
at new Promise (<anonymous>)
at callAsyncCircusFn (/Users/john_duffell/code/support-service-lambdas/node_modules/.pnpm/[email protected]/node_modules/jest-circus/build/utils.js:231:10)
at _callCircusTest (/Users/john_duffell/code/support-service-lambdas/node_modules/.pnpm/[email protected]/node_modules/jest-circus/build/run.js:316:40)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at _runTest (/Users/john_duffell/code/support-service-lambdas/node_modules/.pnpm/[email protected]/node_modules/jest-circus/build/run.js:252:3)
at _runTestsForDescribeBlock (/Users/john_duffell/code/support-service-lambdas/node_modules/.pnpm/[email protected]/node_modules/jest-circus/build/run.js:126:9)
at _runTestsForDescribeBlock (/Users/john_duffell/code/support-service-lambdas/node_modules/.pnpm/[email protected]/node_modules/jest-circus/build/run.js:121:9)
at run (/Users/john_duffell/code/support-service-lambdas/node_modules/.pnpm/[email protected]/node_modules/jest-circus/build/run.js:71:3)
at runAndTransformResultsToJestFormat (/Users/john_duffell/code/support-service-lambdas/node_modules/.pnpm/[email protected]/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)
at jestAdapter (/Users/john_duffell/code/support-service-lambdas/node_modules/.pnpm/[email protected]/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)
at runTestInternal (/Users/john_duffell/code/support-service-lambdas/node_modules/.pnpm/[email protected]/node_modules/jest-runner/build/runTest.js:367:16)
at runTest (/Users/john_duffell/code/support-service-lambdas/node_modules/.pnpm/[email protected]/node_modules/jest-runner/build/runTest.js:444:34)
at Object.worker (/Users/john_duffell/code/support-service-lambdas/node_modules/.pnpm/[email protected]/node_modules/jest-runner/build/testWorker.js:106:12)
Node.js v20.11.0
@@ -49,24 +49,24 @@ const buildCloudwatchClient = (awsAccountId: string): CloudWatchClient => { | |||
return new CloudWatchClient({ region: 'eu-west-1' }); | |||
}; | |||
|
|||
const getTags = async ( | |||
export type Tags = { | |||
App?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so far we only have App but the idea is to add a URL template for the logs link(s)
# Conflicts: # handlers/alarms-handler/test/index.test.ts
# Conflicts: # handlers/alarms-handler/src/index.ts
This PR follows on from #2635 and is the next part split out from the old PR #2487
In this PR I refactor the code that retrieves the tags on the alarm. Rather than just selecting the
App
tag, this returns an object containing all defined tags.This means that in the next PR we can look at a new tag to build a log URL.