-
Notifications
You must be signed in to change notification settings - Fork 6
test(server-nestjs): cas limites des utilitaires partagés (edges, BigInt, cron) #2588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
shikanime
wants to merge
4
commits into
main
Choose a base branch
from
test/adv-utils
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f518eab
test(server-nestjs): adversarial edge coverage shared utils
shikanime 1cff6cd
test(server-nestjs): neutral wording in http utils spec
shikanime f22910a
test(server-nestjs): fix lint violations in utils specs
shikanime ec9c18a
fix(server-nestjs): apply review feedback on utils specs
shikanime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
apps/server-nestjs/src/modules/project-members/project-members.utils.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { faker } from '@faker-js/faker' | ||
| import { describe, expect, it } from 'vitest' | ||
| import { makeProjectMemberWithUser, makeUser } from '../project/project-testing.utils' | ||
| import { makeProjectMember } from './project-members.utils' | ||
|
|
||
| describe('makeProjectMember', () => { | ||
| it('projects exactly the Member shape (id, roleIds, identity)', () => { | ||
| const user = makeUser() | ||
| const roles = [faker.string.uuid(), faker.string.uuid()] | ||
| expect(makeProjectMember(makeProjectMemberWithUser(user, { roleIds: roles }))).toEqual({ | ||
| userId: user.id, | ||
| roleIds: roles, | ||
| email: user.email, | ||
| firstName: user.firstName, | ||
| lastName: user.lastName, | ||
| }) | ||
| }) | ||
|
|
||
| it('drops internal user fields (adminRoleIds, type, timestamps)', () => { | ||
| const user = makeUser({ adminRoleIds: [faker.string.uuid()] }) | ||
| const member = makeProjectMember(makeProjectMemberWithUser(user)) | ||
| expect(member).not.toHaveProperty('adminRoleIds') | ||
| expect(member).not.toHaveProperty('type') | ||
| expect(member).not.toHaveProperty('createdAt') | ||
| expect(member).not.toHaveProperty('lastLogin') | ||
| }) | ||
|
|
||
| it('preserves empty and multi-role arrays verbatim (order matters to callers)', () => { | ||
| const user = makeUser() | ||
| expect(makeProjectMember(makeProjectMemberWithUser(user, { roleIds: [] })).roleIds).toEqual([]) | ||
| const orderedRoles = ['zzz', 'aaa'] | ||
| expect(makeProjectMember(makeProjectMemberWithUser(user, { roleIds: orderedRoles })).roleIds).toEqual(orderedRoles) | ||
| }) | ||
|
|
||
| it('passes unicode identities through untouched (no sanitization here)', () => { | ||
| const user = makeUser({ email: 'ünïcodé@dso.fr', firstName: 'Élodie', lastName: 'Nüñez' }) | ||
| const member = makeProjectMember(makeProjectMemberWithUser(user)) | ||
| expect(member.email).toBe('ünïcodé@dso.fr') | ||
| expect(member.firstName).toBe('Élodie') | ||
| expect(member.lastName).toBe('Nüñez') | ||
| }) | ||
| }) |
2 changes: 1 addition & 1 deletion
2
apps/server-nestjs/src/modules/project-members/project-members.utils.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
apps/server-nestjs/src/modules/project/project-queries.utils.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import type { Prisma } from '@prisma/client' | ||
| import type { DeepMockProxy } from 'vitest-mock-extended' | ||
| import { faker } from '@faker-js/faker' | ||
| import { describe, expect, it } from 'vitest' | ||
| import { mockDeep } from 'vitest-mock-extended' | ||
| import { | ||
| createProject, | ||
| deleteProjectDependencies, | ||
| getNotArchivedProjectForUpdate, | ||
| getProject, | ||
| getProjectContext, | ||
| getProjectForUpsert, | ||
| getProjectNotArchived, | ||
| getProjectSlug, | ||
| listProjects, | ||
| listProjectsForDataExport, | ||
| listProjectSlugsForPrefix, | ||
| projectContextSelect, | ||
| projectForDataSelect, | ||
| projectForUpdateSelect, | ||
| projectForUpsertSelect, | ||
| projectIdSelect, | ||
| projectSelect, | ||
| projectSlugSelect, | ||
| updateProject, | ||
| } from './project-queries.utils' | ||
|
|
||
| function mockTx(): DeepMockProxy<Prisma.TransactionClient> { | ||
| return mockDeep<Prisma.TransactionClient>() | ||
| } | ||
|
|
||
| describe('project query helpers', () => { | ||
| it('getProject selects the full aggregate by id', async () => { | ||
| const tx = mockTx() | ||
| const projectId = faker.string.uuid() | ||
| await getProject(tx, projectId) | ||
| expect(tx.project.findUnique).toHaveBeenCalledWith({ where: { id: projectId }, select: projectSelect }) | ||
| }) | ||
|
|
||
| it('getProjectNotArchived excludes archived status', async () => { | ||
| const tx = mockTx() | ||
| const projectId = faker.string.uuid() | ||
| tx.project.findFirst.mockResolvedValueOnce({ id: projectId } as never) | ||
| await expect(getProjectNotArchived(tx, projectId)).resolves.toEqual({ id: projectId }) | ||
| expect(tx.project.findFirst).toHaveBeenCalledWith({ | ||
| where: { id: projectId, status: { not: 'archived' } }, | ||
| select: projectSelect, | ||
| }) | ||
| }) | ||
|
|
||
| it('listProjects ANDs the caller-supplied clauses', async () => { | ||
| const tx = mockTx() | ||
| const ownerId = faker.string.uuid() | ||
| const where = [{ ownerId }, { slug: { startsWith: 'a' } }] | ||
| await listProjects(tx, where) | ||
| expect(tx.project.findMany).toHaveBeenCalledWith({ where: { AND: where }, select: projectSelect }) | ||
| }) | ||
|
|
||
| it('listProjects accepts an empty clause list (matches everything)', async () => { | ||
| const tx = mockTx() | ||
| await listProjects(tx, []) | ||
| expect(tx.project.findMany).toHaveBeenCalledWith({ where: { AND: [] }, select: projectSelect }) | ||
| }) | ||
|
|
||
| it('listProjectSlugsForPrefix prefixes on slug only', async () => { | ||
| const tx = mockTx() | ||
| const prefix = faker.helpers.slugify('proj') | ||
| await listProjectSlugsForPrefix(tx, prefix) | ||
| expect(tx.project.findMany).toHaveBeenCalledWith({ | ||
| where: { slug: { startsWith: prefix } }, | ||
| select: { slug: true }, | ||
| }) | ||
| }) | ||
|
|
||
| it('slug/context selects stay minimal', async () => { | ||
| const tx = mockTx() | ||
| const projectId = faker.string.uuid() | ||
| await getProjectSlug(tx, projectId) | ||
| await getProjectContext(tx, projectId) | ||
| expect(tx.project.findUnique).toHaveBeenNthCalledWith(1, { where: { id: projectId }, select: projectSlugSelect }) | ||
| expect(tx.project.findUnique).toHaveBeenNthCalledWith(2, { where: { id: projectId }, select: projectContextSelect }) | ||
| }) | ||
|
|
||
| it('listProjectsForDataExport scans every project without where', async () => { | ||
| const tx = mockTx() | ||
| await listProjectsForDataExport(tx) | ||
| expect(tx.project.findMany).toHaveBeenCalledWith({ select: projectForDataSelect }) | ||
| }) | ||
|
|
||
| it('createProject returns only the id', async () => { | ||
| const tx = mockTx() | ||
| const data = { name: faker.company.name(), slug: faker.helpers.slugify('project') } as never | ||
| await createProject(tx, data) | ||
| expect(tx.project.create).toHaveBeenCalledWith({ data, select: projectIdSelect }) | ||
| }) | ||
|
|
||
| it('update-context and upsert selects match their shapes', async () => { | ||
| const tx = mockTx() | ||
| const projectId = faker.string.uuid() | ||
| await getNotArchivedProjectForUpdate(tx, projectId) | ||
| await getProjectForUpsert(tx, projectId) | ||
| expect(tx.project.findFirst).toHaveBeenCalledWith({ | ||
| where: { id: projectId, status: { not: 'archived' } }, | ||
| select: projectForUpdateSelect, | ||
| }) | ||
| expect(tx.project.findUnique).toHaveBeenCalledWith({ where: { id: projectId }, select: projectForUpsertSelect }) | ||
| }) | ||
|
|
||
| it('updateProject writes without narrowing the result', async () => { | ||
| const tx = mockTx() | ||
| const projectId = faker.string.uuid() | ||
| const data = { name: faker.company.name() } as never | ||
| await updateProject(tx, projectId, data) | ||
| expect(tx.project.update).toHaveBeenCalledWith({ where: { id: projectId }, data }) | ||
| }) | ||
|
|
||
| it('deleteProjectDependencies clears repo/env/deployment rows in parallel', async () => { | ||
| const tx = mockTx() | ||
| const projectId = faker.string.uuid() | ||
| tx.repository.deleteMany.mockResolvedValueOnce({ count: 2 }) | ||
| tx.environment.deleteMany.mockResolvedValueOnce({ count: 3 }) | ||
| tx.deployment.deleteMany.mockResolvedValueOnce({ count: 5 }) | ||
| await expect(deleteProjectDependencies(tx, projectId)).resolves.toEqual([ | ||
| { count: 2 }, | ||
| { count: 3 }, | ||
| { count: 5 }, | ||
| ]) | ||
| expect(tx.repository.deleteMany).toHaveBeenCalledWith({ where: { projectId } }) | ||
| expect(tx.environment.deleteMany).toHaveBeenCalledWith({ where: { projectId } }) | ||
| expect(tx.deployment.deleteMany).toHaveBeenCalledWith({ where: { projectId } }) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.