mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
test(core): Relax assertions for testing the maxTeamProjects quota (#15798)
This commit is contained in:
@@ -440,7 +440,8 @@ describe('POST /projects/', () => {
|
|||||||
if (!globalConfig.database.isLegacySqlite) {
|
if (!globalConfig.database.isLegacySqlite) {
|
||||||
test('should respect the quota when trying to create multiple projects in parallel (no race conditions)', async () => {
|
test('should respect the quota when trying to create multiple projects in parallel (no race conditions)', async () => {
|
||||||
expect(await Container.get(ProjectRepository).count({ where: { type: 'team' } })).toBe(0);
|
expect(await Container.get(ProjectRepository).count({ where: { type: 'team' } })).toBe(0);
|
||||||
testServer.license.setQuota('quota:maxTeamProjects', 3);
|
const maxTeamProjects = 3;
|
||||||
|
testServer.license.setQuota('quota:maxTeamProjects', maxTeamProjects);
|
||||||
const ownerUser = await createOwner();
|
const ownerUser = await createOwner();
|
||||||
const ownerAgent = testServer.authAgentFor(ownerUser);
|
const ownerAgent = testServer.authAgentFor(ownerUser);
|
||||||
await expect(
|
await expect(
|
||||||
@@ -456,9 +457,17 @@ describe('POST /projects/', () => {
|
|||||||
ownerAgent.post('/projects/').send({ name: 'Test Team Project 6' }),
|
ownerAgent.post('/projects/').send({ name: 'Test Team Project 6' }),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Some of the calls above will interleave and may fail with a deadlock
|
||||||
|
// error on MySQL (this is not an issue on PG or MariaDB).
|
||||||
|
// That can lead to less projects being created than the quota allows.
|
||||||
|
// So we're only checking here that we didn't create more projects than
|
||||||
|
// are allowed instead of checking for a specific number.
|
||||||
|
// We only want to prevent that this endpoint is exploited. A normal user
|
||||||
|
// using the FE would almost never hit this and if they do they can retry
|
||||||
|
// the action. No need to implement rety logic in the controller.
|
||||||
await expect(
|
await expect(
|
||||||
Container.get(ProjectRepository).count({ where: { type: 'team' } }),
|
Container.get(ProjectRepository).count({ where: { type: 'team' } }),
|
||||||
).resolves.toBe(3);
|
).resolves.toBeLessThanOrEqual(maxTeamProjects);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user