msw: continue handler migration - #1186
Conversation
|
Deployment previews on netlify for branch
|
dati18
left a comment
There was a problem hiding this comment.
a singleton state is created at import time (including myWikis, lastWikiId, user and getEntityImportCalledTimes). For me it's a bit concerning because the state is glocal and not reset between tests or re-renderings, and a test that creates/deletes wikis can affect later tests.
I think a getter/setter pattern is more suitable than module-level constants. For example:
const getMyWikis = () => { //some code }const setMyWiki = (items) => { //some code }
And recomputelastWikiIdfrom the current array when needed, rather than keeping one stale global value.
Not a blocker for a trivial mock, but I would treat it as a test-flakiness issue. If this file is used across multiple UI tests, it might cause some order-dependent failures.
I agree for unit tests this logic is not suitable. Using a (shared) logic for unit tests I think should come after these initial fixes. As mentioned in the other PR, the scope for these was primarily the migration and touchup of the old broken mock service |
7dd0a19 to
5565314
Compare
| @@ -53,13 +167,127 @@ export const handlers = [ | |||
| return new Response('Success') | |||
| }), | |||
|
|
|||
| } | ||
|
|
||
| const user = makeUser() | ||
| user = makeUser() |
There was a problem hiding this comment.
I'm still a bit confused by this part. The mock’s GET /api/auth/login handler can reset the user with a fresh user by calling makeUser().
Then POST /api/auth/login uses the submitted email to create the session user in line 146, but the next auth check at line 134 throws that away and recreates the default user?
| return new Response('Success') | ||
| }), | ||
|
|
||
| http.post('/api/user/sendVerifyEmail', () => { |
There was a problem hiding this comment.
I already mentioned it in this comment
- The mock is a bit odd because it returns a string, api.js returns an object
- the frontend expects a different message text than the backend actually sends (a "!" difference)
onUnhandledRequest: 'error'so that not-implemented handlers error instead of bypass msw (docs)/api/wiki/entityImport/api/wiki/entityImport/api/wiki/create/api/wiki/delete/api/wiki/logo/update/\/api\/wiki\/setting\/.*?\/update$//api/wiki/details/api/wiki/api/v1/policies/missing/api/v1/policies/currentremoveWiki:splice()mutates, not copies (docs)test@localanymorehttps://phabricator.wikimedia.org/T436530