-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add options to
setupTestUser
test utility
- Loading branch information
1 parent
8af7778
commit 244cb12
Showing
1 changed file
with
16 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |