test(sample-01): added service unit tests
PR Checklist
Please check if your PR fulfills the following requirements:
- [x] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
- [x] Tests for the changes have been added (for bug fixes / features)
- [ ] Docs have been added / updated (for bug fixes / features)
PR Type
What kind of change does this PR introduce?
- [ ] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, local variables)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] CI related changes
- [ x] Other... Please describe: Adding unitary tests to sample 01 service
What is the current behavior?
The sample 01 already have e2e tests and unitary tests on the controller, but it's missing tests on the service. It's also missing tests on the create cat function
Issue Number: #1539
What is the new behavior?
I've added a new test file providing an example on how to test only the service, and modified the controller test to add the create cat test.
Does this PR introduce a breaking change?
- [ ] Yes
- [x] No
Other information
I've tried to create an e2e test to the POST method, however the Role guard is blocking the request, I've noticed that in the src/common/guards/roles.guard.ts the guard is expecting an property from the request called user but I did not found a way to pass this property in my request, without using the header or body.
Pull Request Test Coverage Report for Build 961a2e7c-ad7e-401a-bff2-7cecf5aa4419
- 0 of 0 changed or added relevant lines in 0 files are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage remained the same at 93.404%
| Totals | |
|---|---|
| Change from base Build a5022226-a52a-4785-87b3-bf2bbe181377: | 0.0% |
| Covered Lines: | 6202 |
| Relevant Lines: | 6640 |
💛 - Coveralls
Hey @micalevisk I've implemented the code review suggestions, but could you help me with the Role guard so i can write the e2e test to the create endpoint?
is this line correct? if so, how do i pass the user metadata in the supertest library?
@Yansb we would have to mock the request.user object but I didn't find any non-hacky way to do that :thinking: Also, looks like the app itself didn't have any way to populate the request.user field
@micalevisk should i change this implementation to search for the role on the body or header?
you could propose that change in another PR after merging this one.