-
Notifications
You must be signed in to change notification settings - Fork 220
fix(api): preserve zero project limit #535
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
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { INestApplication } from '@nestjs/common'; | |
| import * as request from 'supertest'; | ||
| import './util'; | ||
| import { createAndMigrateApp, signupTestUser, TestingUser } from './util'; | ||
| import { config } from '../src/config'; | ||
|
|
||
| describe('ProjectController (e2e)', () => { | ||
| let app: INestApplication; | ||
|
|
@@ -224,6 +225,31 @@ describe('ProjectController (e2e)', () => { | |
| .expect(429); | ||
| }); | ||
|
|
||
| it('/api/v1/projects (POST) should not create a project if the project limit is zero', async () => { | ||
| const maxProjectsPerUser = config.maxProjectsPerUser; | ||
| config.maxProjectsPerUser = 0; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Regression test mutates in-memory config after the app is already bootstrapped, so it does not cover the original zero-limit config-loading bug. Prompt for AI agents
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, good catch. I replaced that e2e singleton-mutation check with a config-loading unit test in |
||
|
|
||
| try { | ||
| await request(app.getHttpServer()) | ||
| .post('/api/v1/projects') | ||
| .set('Authorization', `Bearer ${testingUser.accessToken}`) | ||
| .send({ | ||
| name: 'My project', | ||
| }) | ||
| .expect(429); | ||
|
|
||
| await request(app.getHttpServer()) | ||
| .get('/api/v1/projects') | ||
| .set('Authorization', `Bearer ${testingUser.accessToken}`) | ||
| .expect(200) | ||
| .expect(res => { | ||
| expect(res.body.data).toHaveLength(0); | ||
| }); | ||
| } finally { | ||
| config.maxProjectsPerUser = maxProjectsPerUser; | ||
| } | ||
| }); | ||
|
|
||
| it('/api/v1/projects/:projectId (PATCH) should update a project', async () => { | ||
| let projectId; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configsingleton mid-test works because Jest runs test cases within the same file sequentially, and the controller readsconfig.maxProjectsPerUserat request time. However, a future move to parallel test workers could leave the value permanently set to0, causing every subsequent test in the file to reject all project creation requests. Thetry/finallypattern is the correct approach for plain object properties.