Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions modules/auth/tests/auth.abilities.integration.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
8 changes: 8 additions & 0 deletions modules/auth/tests/auth.authorization.integration.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
30 changes: 30 additions & 0 deletions modules/auth/tests/auth.integration.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
25 changes: 25 additions & 0 deletions modules/auth/tests/auth.signup.organization.integration.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>}
*/
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();
Expand All @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down
Loading