-
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.
- Loading branch information
1 parent
918651b
commit 4c1e7ab
Showing
1 changed file
with
84 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { NestExpressApplication } from '@nestjs/platform-express'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { OrganizationDto } from 'shared-types'; | ||
import * as request from 'supertest'; | ||
import { AppModule } from '../src/app.module'; | ||
import { CreateOrganizationDto } from '../src/models/organizations/dto/create-organization.dto'; | ||
import { PatchOrganizationSettingsDto } from '../src/models/organizations/dto/path-organization-settings.dto'; | ||
import { UpdateOrganizationDto } from '../src/models/organizations/dto/update-organization.dto'; | ||
import NestSetup from '../src/setup'; | ||
import { setupTestUser } from './setup-user'; | ||
|
||
describe('OrganizationsController (e2e)', () => { | ||
let app: NestExpressApplication; | ||
let agent: request.SuperAgentTest; | ||
|
||
let createdOrganizationId: string; | ||
|
||
beforeAll(async () => { | ||
const moduleFixture: TestingModule = await Test.createTestingModule({ | ||
imports: [AppModule], | ||
}).compile(); | ||
|
||
app = moduleFixture.createNestApplication<NestExpressApplication>(); | ||
NestSetup.configureNestApp(app); | ||
await app.init(); | ||
|
||
agent = request.agent(app.getHttpServer()); | ||
await setupTestUser(agent); | ||
}); | ||
|
||
it('/organizations (POST)', async () => { | ||
const dto: CreateOrganizationDto = { | ||
name: 'test-org', | ||
warehouse: { | ||
name: 'test-warehouse', | ||
address: 'test-adress', | ||
}, | ||
}; | ||
const res = await agent.post('/api/organizations').send(dto).expect(201); | ||
expect(res.body.name).toBe('test-org'); | ||
createdOrganizationId = res.body.id; | ||
}); | ||
|
||
it('/organizations (GET)', async () => { | ||
const res = await agent.get('/api/organizations').expect(200); | ||
const lastOrg: OrganizationDto = res.body.items[0]; | ||
expect(lastOrg.name).toBe('test-org'); | ||
expect(lastOrg.id).toBe(createdOrganizationId); | ||
}); | ||
|
||
it('/organizations/:id (GET)', async () => { | ||
const res = await agent.get(`/api/organizations/${createdOrganizationId}`).expect(200); | ||
expect(res.body.name).toBe('test-org'); | ||
expect(res.body.id).toBe(createdOrganizationId); | ||
}); | ||
|
||
it('/organizations/:id (PUT)', async () => { | ||
const dto: UpdateOrganizationDto = { name: 'updated-org' }; | ||
|
||
await agent.put(`/api/organizations/${createdOrganizationId}`).send(dto).expect(200); | ||
const res = await agent.get(`/api/organizations/${createdOrganizationId}`).expect(200); | ||
|
||
expect(res.body.name).toBe('updated-org'); | ||
}); | ||
|
||
it('/organizations/:id/settings (PATCH)', async () => { | ||
const dto: PatchOrganizationSettingsDto = { currency: 'PLN' }; | ||
|
||
const res = await agent | ||
.patch(`/api/organizations/${createdOrganizationId}/settings`) | ||
.send(dto) | ||
.expect(200); | ||
|
||
expect(res.body.currency).toBe('PLN'); | ||
}); | ||
|
||
it('/organizations/:id (DELETE)', async () => { | ||
await agent.delete(`/api/organizations/${createdOrganizationId}`).expect(200); | ||
|
||
// We actually test for code 403 here since when organization is not found it | ||
// throws 403 instead of 404 | ||
await agent.get(`/api/organizations/${createdOrganizationId}`).expect(403); | ||
}); | ||
}); |