Skip to content

test(server-nestjs): migrate Registry client spec to MSW + @msw/data - #2671

Draft
shikanime wants to merge 1 commit into
test/msw-vault-migratefrom
test/msw-registry-migrate
Draft

test(server-nestjs): migrate Registry client spec to MSW + @msw/data#2671
shikanime wants to merge 1 commit into
test/msw-vault-migratefrom
test/msw-registry-migrate

Conversation

@shikanime

Copy link
Copy Markdown
Member

Migrate Registry client spec from inline MSW handlers to @msw/data-based factories.

Stacking on: PR #2670

Refs #2655

Registry testing utils use @msw/data Collection for faker-seeded Harbor
projects, robots, quotas, members, repositories. Handlers split into per-
resource subfunctions. makeRobotPermissions() extracted as factory.

Refs #2655

Co-authored-by: Automata <[email protected]>
Signed-off-by: Shikanime Deva <[email protected]>
Signed-off-by: William Phetsinorath <[email protected]>
Change-Id: I3040943080a743eb0d3e5a55f782a9766a6a6964

@shikanime shikanime left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Verdict : Commentaire

Bonne continuation de la série MSW — la structure par sous-handlers est claire. Deux points non bloquants : la vérification du corps du PUT retentions a disparu, et quelques toMatchObject affaiblissent les assertions.

const base = `${HARBOR_INTERNAL_URL}/api/v2.0`

return [
http.put(`${base}/retentions/:id`, () => new HttpResponse(null, { status: 200 })),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

[⚪ Suggestion] Le PUT /retentions/:id répond 200 sans persister ni vérifier le corps : l'ancien mock affirmait request.json() === policy. La garde est perdue — capturer le corps dans la collection retentions restaurerait la vérification.

const result = await service.ensureProject('myproj', -1)

expect(result).toEqual({ project_id: 123, metadata: {} })
expect(result).toMatchObject({ project_id: 123, metadata: {} })

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

[🟡 Nit] toMatchObject en remplacement de toEqual : si le handler renvoie des champs supplémentaires, l'assertion passe silencieusement. Acceptable le temps de la migration, à surveiller.

]
}

export function makeRegistryHandlers(db: Db): HttpHandler[] {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

[✨ Éloge] Découpage par sous-ressources + validation zod des corps : l'émulation Harbor gagne en fidélité et les écarts de contrat deviennent explicites.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant