Skip to content

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

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

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

Conversation

@shikanime

Copy link
Copy Markdown
Member

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

Stacking on: PR #2669

Refs #2655

Vault testing utils use @msw/data Collection for faker-seeded secret engines
and secrets. Server initialized empty, handlers added in beforeEach.

Refs #2655

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

@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 : Changements demandés

La migration vers MSW stateful + @msw/data est la bonne direction et le durcissement onUnhandledRequest est appréciable. Mais makeVaultSecret change de contrat alors que quatre specs existantes l'appellent toujours à l'ancienne signature — la branche casse la compile du reste du paquet. Réaligner la signature (ou migrer les consommateurs dans la même PR) suffit à débloquer.

}

export function makeVaultSecret(overrides: Partial<VaultSecret> = {}): VaultSecret {
export function makeVaultSecret<T>(data: T): { data: { data: T, metadata: { created_time: string, destroyed: boolean, version: number } } } {

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.

[🔴 Bloquant] makeVaultSecret change de contrat : avant makeVaultSecret(overrides) avec data/metadata optionnels, maintenant makeVaultSecret<T>(data: T). Les specs tronc nexus.service.spec.ts, registry.service.spec.ts, sonarqube.service.spec.ts et vault.service.spec.ts appellent makeVaultSecret({ data: {...} }) — avec la nouvelle signature, { data: ... } serait interprété comme la donnée elle-même. Suggestion : conserver la signature par overrides, ou faire évoluer les quatre specs consommatrices dans cette même PR.

data: {
data,
metadata: {
created_time: new Date().toISOString(),

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] new Date().toISOString() dans une fixture : préférez faker.date.recent().toISOString() (cohérence faker, pas d'horloge réelle dans les données de test). Idem ligne 68.

let db: ReturnType<typeof makeVaultDb>

beforeAll(() => server.listen())
beforeAll(() => server.listen({ onUnhandledRequest: 'error' }))

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] onUnhandledRequest: 'error' + handlers réinstallés par test : bon durcissement, chaque test porte son propre état réseau.

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