diff --git a/modules/auth/tests/auth.abilities.integration.tests.js b/modules/auth/tests/auth.abilities.integration.tests.js index b11e62c33..62bc880fb 100644 --- a/modules/auth/tests/auth.abilities.integration.tests.js +++ b/modules/auth/tests/auth.abilities.integration.tests.js @@ -42,6 +42,14 @@ describe('Auth abilities integration tests:', () => { agent = request.agent(init.app); adminAgent = request.agent(init.app); + // clean up stale users from previous runs on shared databases + for (const email of [userCredentials.email, adminCredentials.email]) { + try { + const existing = await UserService.getBrut({ email }); + if (existing) await UserService.remove(existing); + } catch (_) { /* cleanup – ignore errors */ } + } + // Create a regular user const userRes = await agent .post('/api/auth/signup') diff --git a/modules/auth/tests/auth.authorization.integration.tests.js b/modules/auth/tests/auth.authorization.integration.tests.js index 7e7161b94..c9758666b 100644 --- a/modules/auth/tests/auth.authorization.integration.tests.js +++ b/modules/auth/tests/auth.authorization.integration.tests.js @@ -40,6 +40,14 @@ describe('Authorization integration tests:', () => { adminAgent = request.agent(init.app); otherAgent = request.agent(init.app); + // clean up stale users from previous runs on shared databases + for (const email of ['auth-test-user@test.com', 'auth-test-admin@test.com', 'auth-test-other@test.com']) { + try { + const existing = await UserService.getBrut({ email }); + if (existing) await UserService.remove(existing); + } catch (_) { /* cleanup – ignore errors */ } + } + // Create a normal user via agent const userRes = await agent .post('/api/auth/signup') diff --git a/modules/auth/tests/auth.integration.tests.js b/modules/auth/tests/auth.integration.tests.js index bbbec71a1..fdbffafcb 100644 --- a/modules/auth/tests/auth.integration.tests.js +++ b/modules/auth/tests/auth.integration.tests.js @@ -66,6 +66,14 @@ describe('Auth integration tests:', () => { _userEdited.email = credentials[1].email; _userEdited.password = credentials[1].password; + // clean up stale users from previous runs on shared databases + for (const email of [credentials[0].email, credentials[1].email, 'register_new_user_@test.com']) { + try { + const existing = await UserService.getBrut({ email }); + if (existing) await UserService.remove(existing); + } catch (_) { /* cleanup – ignore errors */ } + } + // add user try { const result = await agent.post('/api/auth/signup').send(_user).expect(200); @@ -645,6 +653,11 @@ describe('Auth integration tests:', () => { password: credentials[0].password, provider: 'local', }; + // clean up stale users from previous runs on shared databases + try { + const existing = await UserService.getBrut({ email: credentials[0].email }); + if (existing) await UserService.remove(existing); + } catch (_) { /* cleanup – ignore errors */ } try { const result = await agent.post('/api/auth/signup').send(_user).expect(200); user = result.body.user; @@ -722,6 +735,13 @@ describe('Auth integration tests:', () => { let secUser; beforeEach(async () => { + // clean up stale users from previous runs on shared databases + for (const email of [secEmail, 'cookieflag@test.com']) { + try { + const existing = await UserService.getBrut({ email }); + if (existing) await UserService.remove(existing); + } catch (_) { /* cleanup – ignore errors */ } + } try { const result = await agent.post('/api/auth/signup').send({ firstName: 'Sec', @@ -873,6 +893,11 @@ describe('Auth integration tests:', () => { let verifyUser; beforeEach(async () => { + // clean up stale users from previous runs on shared databases + try { + const existing = await UserService.getBrut({ email: verifyEmail }); + if (existing) await UserService.remove(existing); + } catch (_) { /* cleanup – ignore errors */ } try { const result = await agent.post('/api/auth/signup').send({ firstName: 'Verify', @@ -998,6 +1023,11 @@ describe('Auth integration tests:', () => { let lockUser; beforeEach(async () => { + // clean up stale users from previous runs on shared databases + try { + const existing = await UserService.getBrut({ email: lockEmail }); + if (existing) await UserService.remove(existing); + } catch (_) { /* cleanup – ignore errors */ } try { const result = await agent.post('/api/auth/signup').send({ firstName: 'Lock', diff --git a/modules/auth/tests/auth.signup.organization.integration.tests.js b/modules/auth/tests/auth.signup.organization.integration.tests.js index e83f9fa85..5070be60b 100644 --- a/modules/auth/tests/auth.signup.organization.integration.tests.js +++ b/modules/auth/tests/auth.signup.organization.integration.tests.js @@ -44,6 +44,18 @@ describe('Auth signup organization integration tests:', () => { } catch (_) { /* cleanup — ignore errors */ } }; + /** + * Remove a user by email if they exist (cleanup stale data from previous runs). + * @param {string} email - email address of the user to purge + * @returns {Promise} + */ + const purgeUser = async (email) => { + try { + const existing = await UserService.getBrut({ email }); + if (existing) await cleanupUser(existing); + } catch (_) { /* cleanup – ignore errors */ } + }; + beforeAll(async () => { try { const init = await bootstrap(); @@ -66,6 +78,8 @@ describe('Auth signup organization integration tests:', () => { config.organizations = { enabled: false, autoCreate: true, domainMatching: true }; let user; + // clean up stale users from previous runs on shared databases + await purgeUser('silent-org@test.com'); try { const result = await agent .post('/api/auth/signup') @@ -108,6 +122,9 @@ describe('Auth signup organization integration tests:', () => { // First, create an existing organization with a specific domain let firstUser; let secondUser; + // clean up stale users from previous runs on shared databases + await purgeUser('first@matchdomain.com'); + await purgeUser('second@matchdomain.com'); try { // Sign up first user to create the org with domain const result1 = await agent @@ -162,6 +179,8 @@ describe('Auth signup organization integration tests:', () => { config.organizations = { enabled: true, autoCreate: true, domainMatching: true }; let user; + // clean up stale users from previous runs on shared databases + await purgeUser('solo@uniquedomain123.com'); try { const result = await agent .post('/api/auth/signup') @@ -200,6 +219,8 @@ describe('Auth signup organization integration tests:', () => { config.organizations = { enabled: true, autoCreate: true, domainMatching: false }; let user; + // clean up stale users from previous runs on shared databases + await purgeUser('personal@somecompany.com'); try { const result = await agent .post('/api/auth/signup') @@ -238,6 +259,8 @@ describe('Auth signup organization integration tests:', () => { config.organizations = { enabled: true, autoCreate: false, domainMatching: true }; let user; + // clean up stale users from previous runs on shared databases + await purgeUser('manual@setup.com'); try { const result = await agent .post('/api/auth/signup') @@ -273,6 +296,8 @@ describe('Auth signup organization integration tests:', () => { config.organizations = { enabled: false, autoCreate: true, domainMatching: true }; let user; + // clean up stale users from previous runs on shared databases + await purgeUser('response-check@test.com'); try { const result = await agent .post('/api/auth/signup')