-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add unit tests for api-requests modules #44
Conversation
it('makes a single template request for multiple beacons', async () => { | ||
const state = stateModule.getInitialState(config); | ||
jest.spyOn(stateModule, 'getState').mockReturnValue(state); | ||
const logger = createMockedLogger(); |
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.
Tip: If you want to know what is actually logged, you can do:
(logger as any).debug.mockImplementation(console.log)
which will forward the logs to console log. I used that a bit.
|
||
export const callApi = async (payload: node.ApiCallPayload) => { | ||
getLogger().debug('Preprocessing API call payload', { aggregateApiCall: payload.aggregatedApiCall }); | ||
getLogger().debug('Preprocessing API call payload', pick(payload.aggregatedApiCall, ['endpointName', 'oisTitle'])); |
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.
The example file is uses pre/post processing to only make a single API call and if you log the full aggregateApiCall
you also log parameters
(of a single beacon) which is confusing, so I only log endpointName and oisTitle.
const processedPayload = await preProcessApiSpecifications(payload); | ||
getLogger().debug('Performing API call', { aggregateApiCall: payload.aggregatedApiCall }); | ||
getLogger().debug('Performing API call', { processedPayload: processedPayload }); |
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.
This was a bug before - we should have logged the processed payloed.
getLogger().info(`Pushed signed data updates to the pool.`, { ...logContext, count: goRes.data.count }); | ||
|
||
getLogger().debug('Parsing response from the data registry.', { ...logContext, axiosResponse: goAxiosRequest.data }); | ||
const parsedResponse = dataRegistryResponseSchema.safeParse(goAxiosRequest.data); |
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.
This was not handled correctly previously.
@@ -9,15 +9,13 @@ import { loadConfig } from './validation/config'; | |||
import { initiateFetchingBeaconData } from './fetch-beacon-data'; | |||
import { initiateUpdatingSignedApi } from './update-signed-api'; | |||
import { initializeState } from './state'; | |||
import { initializeWallet } from './wallets'; |
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.
This broke the tests, since the getInitialState
function essentially returned invalid state (wallet was missing).
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 moved all of the fixtures to this file. It makes the tests a bit cleaner and we might use these in case we want to make an e2e test later on.
@andreogle I anticipated we will do #45 and renamed some of the variables to data registry for clarity. I need to revert this back to the original naming (that's why I added the WIP). EDIT: The above was done. |
3fc60e6
to
3fecb9b
Compare
3fecb9b
to
6cca374
Compare
Closes #25