Skip to content

Commit

Permalink
Add options to setupTestUser test utility
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBartusek committed Jun 10, 2024
1 parent 8af7778 commit 244cb12
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion apps/api/test/setup-user.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import * as request from 'supertest';
import { CreateOrganizationDto } from '../src/models/organizations/dto/create-organization.dto';

export async function setupTestUser(agent: request.SuperAgentTest) {
export interface TestUserOptions {
createOrganization?: boolean;
}

export async function setupTestUser(agent: request.SuperAgentTest, options: TestUserOptions = {}) {
const payload = { username: 'test-user', email: '[email protected]', password: 'Test123!' };

await agent.post('/api/auth/register').send(payload);
await agent.post('/api/auth/login').send(payload);

if (options.createOrganization == true) {
const dto: CreateOrganizationDto = {
name: 'auto-mock-test-org',
warehouse: {
name: 'auto-mock-test-warehouse',
},
};
await agent.post('/api/organizations').send(dto);
}
}

0 comments on commit 244cb12

Please sign in to comment.