msw: add policy mock handlers - #1199
Conversation
|
Deployment previews on netlify for branch
|
| }), | ||
|
|
||
| http.post('/api/user/sendVerifyEmail', () => { | ||
| return new Response('Already verified') |
There was a problem hiding this comment.
looking at api.js:45. Under MSW, that makes alreadyVerified always returns false because there is a "!" difference between 2 strings
There was a problem hiding this comment.
That mismatch is outside this mock file, but it means fixing the mock alone would still leave a real API/UI contract bug.
| } | ||
|
|
||
| export const handlers = [ | ||
| http.get('/api/auth/login', ({ cookies }) => { |
There was a problem hiding this comment.
I'm a bit confused here. This block of code resets the authenticated user on successful GET login check by calling makeUser(). So that discards the email set during POST login at line 146-152?
| return Response.json(data) | ||
| }), | ||
|
|
||
| http.get('/api/wiki/entityImport', () => { |
There was a problem hiding this comment.
So you made entity-import polling depend on one global counter shared across the entire module? I think there is a chance that later polls for other wikis might drift and start in the wrong state after a test or something changes the value of the counter.
| } | ||
|
|
||
| export const handlers = [ | ||
| http.get('/api/auth/login', ({ cookies }) => { |
There was a problem hiding this comment.
I'm a bit confused here. This bloack of code resets the authenticated user on every successful GET login check by calling makeUser() with the default email. Does it mean that it discards the email set during POST login at default_handlers.js:146-152
| return Response.json(data) | ||
| }), | ||
|
|
||
| http.get('/api/wiki/entityImport', () => { |
There was a problem hiding this comment.
So the entire module shares 1 global counter? I think later polls might drift and start in the wrong state if a test or something messes up the counter.
There was a problem hiding this comment.
I think you also need to register a handler for the account-creation request. That route is called in api.js:19-27
It's not important right now because the task is focusing on policy functionalities. Ignore if you find it unnecessary
Note
needs merge & rebase of #1186
Adds basic versions of missing policy mock handlers for viewing the current policies.
/api/v1/policies/terms-of-use/api/v1/policies/terms-of-use/by_active_from/2022-01-01/api/v1/policies/terms-of-use/current/api/v1/policies/terms-of-use/upcoming/api/v1/policies/hosting-policy/api/v1/policies/hosting-policy/current/api/v1/policies/hosting-policy/upcomingnote: due to the current implementation these will need to be adjusted when we add new (current/upcoming) policies. I'm not sure if a more dynamic implementation is worth it.
Compared with the current api routes I noticed in general the coverage of the mocks is not including these endpoints (which is probably fine? as they need different means of testing)
/api/v1/policy_acceptances- requires ability of mocking different data scenarios/api/wiki/profile- could be implemented for a successful store response but re-implementing persistence is as i understand it currenlty not needednot ui relevant:
/api/wiki/deletedWikiMetrics/api/wikiConversionData/api/reusePrototypehttps://phabricator.wikimedia.org/T436954