Unit test controller and service of each core Module#75
Conversation
rflechtner
left a comment
There was a problem hiding this comment.
Be sure to await any expect(async() => {}).resolves and expect(async() => {}).rejects like this:
await expect(async() => true).resolves.toBeTruthy()
Other than that I have no functional complaints, the remaining comments are all style-related. To summarise, there's two things that could help readability of the tests:
- Choose one way to mock async functions and to return promises. My personal favourite is
async(): Promise<any> => value, i.e.async(): Promise<void> => {}.(): Promise<any> => Promise.resolve(value)also works, butasync (): Promise<any> => Promise.resolve(value)seems a bit redundant - Separate negative and positive tests. In general its nicer not to lump too many different cases in one
it(), but checking happy path & correct error handling should definitely be two tests imo
Co-authored-by: Raphael Flechtner <39338561+rflechtner@users.noreply.github.com>
Co-authored-by: Raphael Flechtner <39338561+rflechtner@users.noreply.github.com>
Co-authored-by: Raphael Flechtner <39338561+rflechtner@users.noreply.github.com>
cf8f463 to
9cba8bb
Compare
rflechtner
left a comment
There was a problem hiding this comment.
the failing integration tests indicate that this broke the API by requiring that a KILT address be sent to the faucet endpoint. You basically have two options to fix this:
- translate a public key to an address before running it through the address validator. In this case it would be cool to amend integration tests so that we call the faucet endpoint with both an address and a public key. Just add an extra test for address.
- change the api. This would of course require changing the integration tests, but most importantly we'd have to change the
pubkeykey in the payload toaddress; imho we can't ask for a public key but secretly require an address, even in a non-public api. This would mean changing the faucet implementation as well.
|
Good points, and yes you are requesting with a pubkey in the Integration tests. I'll talk to TImo, what the services should be capable of. But I think the best solution atm for this would be to convert to address before checking validity and eligibility. |
|
Wir wollen nur die address erwarten und akzeptieren. |
rflechtner
left a comment
There was a problem hiding this comment.
Nice! There's an error message to fix (see my comment) but then you're good to go!
fixes KILTProtocol/ticket#616
##fixes KILTProtocol/ticket#721
##fixes KILTProtocol/ticket#720
##fixes KILTProtocol/ticket#718
##fixes KILTProtocol/ticket#686
##fixes KILTProtocol/ticket#724
##fixes KILTProtocol/ticket#730
This introduces unit testing of controller and service for each core module, via faking the modules service and mocking of the mongoose Models.
Removes naive approach of in-memory unit testing.
Also aims to refactor some minor issues within our classes.
Contact Module changes:
Removed _findByAddress, and replaced calling it with directly querying the DB.
converToContact is now a private function inside MongoDbMContactsService.
CType Module changes:
Renamed verifyCType to verifyCTypeAndReturnChainOwner, to more accurately represent the updated behaviour. Please suggest a better name!
Removed _findByHash, replaced calls with directly querying DB.
Changed convertToCType from exported to private.
Faucet Module Changes:
Removed email from POST payload parameter.
Removed try catch to check address in favor of checkAddress call.
Now only accepts actual addresses and NOT public keys, or anthing else, prefix of address has to match KILT prefix of 42.
Messaging Module Changes:
Changed uuidv4() from unexported function to exported constant.
Checklist: