You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test: FORMS-1444 add public and utils routes tests (bcgov#1477)
* test: FORMS-1444 add public and utils routes
* for consistency check userAccess.currentUser
* docs: add some thoughts around the route testing
* docs: added brief notes on middleware testing
* refactor: updated the proxy routes tests for consistency
Copy file name to clipboardExpand all lines: app/tests/unit/README.md
+33Lines changed: 33 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -53,3 +53,36 @@ describe('my tests', () => {
53
53
```
54
54
55
55
Similar to `.only` is the `.skip` modifier to skip a test or group of tests.
56
+
57
+
## Testing Strategy
58
+
59
+
The testing strategy for the backend unit tests can be broken down into the different layers of the backend. For all tests we should:
60
+
61
+
- ensure that the tests are consistent
62
+
- ensure that we have 100% test coverage
63
+
- ensure that we have complete test coverage: we should be testing additional corner cases even once we reach 100% test coverage
64
+
- test the interface, not the implementation
65
+
- test the unit under test, not its dependencies
66
+
67
+
### Middleware Testing
68
+
69
+
The tests for the middleware files should:
70
+
71
+
- mock all services calls used by the middleware, including both exception and minimal valid results
72
+
- test all response codes produced by the middleware
73
+
74
+
### Route Testing
75
+
76
+
The tests for the `route.js` files should:
77
+
78
+
- mock all middleware used by the file
79
+
- each route test should check that every middleware is called the proper number of times
80
+
- each route test should mock the controller function that it calls
81
+
- mock controller functions with `res.sendStatus(200)`, as doing something like `next()` will call multiple controller functions when route paths are overloaded
82
+
- check that the mocked controller function is called - this will catch when a new route path accidentally overloads an old one
83
+
- for consistency and ease of comparison, alphabetize the expect clauses ("alphabetize when possible")
84
+
85
+
Note:
86
+
87
+
- Some middleware is called when the `routes.js` is loaded, not when the route is called. For example, the parameters to `userAccess.hasFormPermissions` cannot be tested by calling the route using it. Even if we reload the `routes.js` for each route test, it would be hard to tell which call to `hasFormPermissions` was the call for the route under test
88
+
- Maybe we should refactor and create a set of standard middleware mocks that live outside the `routes.spec.js` files
0 commit comments