Skip to content

msw: add policy mock handlers - #1199

Open
deer-wmde wants to merge 26 commits into
mainfrom
de/msw-policies
Open

msw: add policy mock handlers#1199
deer-wmde wants to merge 26 commits into
mainfrom
de/msw-policies

Conversation

@deer-wmde

@deer-wmde deer-wmde commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Note

needs merge & rebase of #1186

Adds basic versions of missing policy mock handlers for viewing the current policies.

  • GET /api/v1/policies/terms-of-use
  • GET /api/v1/policies/terms-of-use/by_active_from/2022-01-01
  • GET /api/v1/policies/terms-of-use/current
  • GET /api/v1/policies/terms-of-use/upcoming
  • GET /api/v1/policies/hosting-policy
  • GET /api/v1/policies/hosting-policy/current
  • GET /api/v1/policies/hosting-policy/upcoming

note: 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 needed

not ui relevant:

  • /api/wiki/deletedWikiMetrics
  • /api/wikiConversionData
  • /api/reusePrototype

https://phabricator.wikimedia.org/T436954

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

Deployment previews on netlify for branch refs/pull/1199/merge will be at the following locations (when build is done):

@deer-wmde
deer-wmde marked this pull request as ready for review September 4, 2026 14:36
@deer-wmde
deer-wmde changed the base branch from main to ui_msw_login September 4, 2026 15:24
@deer-wmde
deer-wmde changed the base branch from ui_msw_login to main September 4, 2026 15:26
}),

http.post('/api/user/sendVerifyEmail', () => {
return new Response('Already verified')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at api.js:45. Under MSW, that makes alreadyVerified always returns false because there is a "!" difference between 2 strings

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 }) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 }) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@dati18 dati18 Sep 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants