-
Notifications
You must be signed in to change notification settings - Fork 68
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
Trigger cache invalidation tests by queue #2215
base: main
Are you sure you want to change the base?
Conversation
txHash: faker.string.hexadecimal({ length: 32 }), | ||
}, | ||
{ | ||
type: 'MESSAGE_CREATED', | ||
address: faker.finance.ethereumAddress(), | ||
messageHash: faker.string.hexadecimal({ length: 32 }), | ||
}, | ||
{ | ||
type: 'MESSAGE_CONFIRMATION', | ||
address: faker.finance.ethereumAddress(), | ||
messageHash: faker.string.hexadecimal({ length: 32 }), | ||
}, | ||
{ | ||
type: 'CHAIN_UPDATE', | ||
}, | ||
{ | ||
type: 'REORG_DETECTED', | ||
chainId: faker.string.numeric(), | ||
blockNumber: faker.number.int(), | ||
}, | ||
{ | ||
type: 'SAFE_APPS_UPDATE', | ||
}, | ||
{ | ||
type: 'SAFE_CREATED', | ||
address: faker.finance.ethereumAddress(), | ||
blockNumber: faker.number.int(), | ||
}, | ||
])('accepts $type', async (payload) => { | ||
const chainId = faker.string.numeric(); | ||
const data = { | ||
chainId: chainId, | ||
...payload, | ||
}; | ||
networkService.get.mockImplementation(({ url }) => { | ||
switch (url) { | ||
case `${safeConfigUrl}/api/v1/chains/${chainId}`: | ||
return Promise.resolve({ | ||
data: rawify(chainBuilder().with('chainId', chainId).build()), | ||
status: 200, | ||
}); | ||
default: | ||
return Promise.reject(new Error(`Could not match ${url}`)); | ||
} | ||
}); | ||
|
||
await request(app.getHttpServer()) | ||
.post(`/hooks/events`) | ||
.set('Authorization', `Basic ${authToken}`) | ||
.send(data) | ||
.expect(202); | ||
}); | ||
|
||
it('returns 400 (Bad Request) on unknown payload', async () => { | ||
const data = { | ||
type: 'SOME_TEST_TYPE_THAT_WE_DO_NOT_SUPPORT', | ||
safeTxHash: 'some-safe-tx-hash', | ||
}; | ||
networkService.get.mockImplementation(({ url }) => { | ||
switch (url) { | ||
case `${safeConfigUrl}/api/v1/chains/1`: | ||
return Promise.resolve({ | ||
data: rawify(chainBuilder().with('chainId', '1').build()), | ||
status: 200, | ||
}); | ||
default: | ||
return Promise.reject(new Error(`Could not match ${url}`)); | ||
} | ||
}); | ||
|
||
await request(app.getHttpServer()) | ||
.post(`/hooks/events`) | ||
.set('Authorization', `Basic ${authToken}`) | ||
.send(data) | ||
.expect(422) | ||
.expect({ | ||
statusCode: 422, | ||
code: 'invalid_union_discriminator', | ||
options: [ | ||
'CHAIN_UPDATE', | ||
'DELETED_MULTISIG_TRANSACTION', | ||
'EXECUTED_MULTISIG_TRANSACTION', | ||
'INCOMING_ETHER', | ||
'INCOMING_TOKEN', | ||
'MESSAGE_CREATED', | ||
'MODULE_TRANSACTION', | ||
'NEW_CONFIRMATION', | ||
'MESSAGE_CONFIRMATION', | ||
'OUTGOING_ETHER', | ||
'OUTGOING_TOKEN', | ||
'PENDING_MULTISIG_TRANSACTION', | ||
'REORG_DETECTED', | ||
'SAFE_APPS_UPDATE', | ||
'SAFE_CREATED', | ||
], | ||
path: ['type'], | ||
message: | ||
"Invalid discriminator value. Expected 'CHAIN_UPDATE' | 'DELETED_MULTISIG_TRANSACTION' | 'EXECUTED_MULTISIG_TRANSACTION' | 'INCOMING_ETHER' | 'INCOMING_TOKEN' | 'MESSAGE_CREATED' | 'MODULE_TRANSACTION' | 'NEW_CONFIRMATION' | 'MESSAGE_CONFIRMATION' | 'OUTGOING_ETHER' | 'OUTGOING_TOKEN' | 'PENDING_MULTISIG_TRANSACTION' | 'REORG_DETECTED' | 'SAFE_APPS_UPDATE' | 'SAFE_CREATED'", | ||
}); | ||
}); |
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.
These were removed as we receive no response. If we want to check this, however, we could check whether an error is logged.
it.each( | ||
[ | ||
newDelegateEventBuilder().build(), | ||
updatedDelegateEventBuilder().build(), | ||
deletedDelegateEventBuilder().build(), | ||
].map((event) => [event.type, event]), | ||
)('%s clears delegates', async (_, event) => { |
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.
These were added as they were missing - initially marked with a TODO at the top.
Summary
Our cache is invalidated in accordance with queue events. Most of the test coverage was linked to our previous POST hooks, and therefore skipped.
This converts the tests to trigger via queue instead of POST calls, unskipping them.
Changes