Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit 670db62

Browse files
committed
External e2e file
1 parent 54e2d97 commit 670db62

File tree

3 files changed

+146
-132
lines changed

3 files changed

+146
-132
lines changed

docker-compose.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
version: '3.8'
22
services:
3-
# nest-api:
4-
# build:
5-
# context: .
6-
# dockerfile: Dockerfile
7-
# container_name: nest-api
8-
# restart: always
9-
# ports:
10-
# - "4001:4001"
11-
# depends_on:
12-
# - postgres
13-
# env_file:
14-
# - .env
15-
163
postgres:
174
image: postgres:14
185
container_name: postgres

test/app.e2e-spec.ts

Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Test, TestingModule } from '@nestjs/testing';
22
import { INestApplication } from '@nestjs/common';
33
import * as request from 'supertest';
44
import { AppModule } from '@/app.module';
5-
import { CreateChannelDto } from '@/core/channel/dto/create-channel.dto';
65

76
describe('AppController (e2e)', () => {
87
let app: INestApplication;
@@ -41,122 +40,4 @@ describe('AppController (e2e)', () => {
4140
});
4241
});
4342
});
44-
45-
describe('/channel', () => {
46-
describe('Creating new Channel', () => {
47-
const newChannelDto: CreateChannelDto = {
48-
slug: 'test',
49-
name: 'test',
50-
currencyCode: 'USD',
51-
languageCode: 'EN',
52-
countryCode: 'US',
53-
};
54-
55-
it('Should return 401 Unauthorized', async () => {
56-
const response = await request(app.getHttpServer())
57-
.post('/channel')
58-
.send({})
59-
.set('Accept', 'application/json');
60-
61-
expect(response.status).toEqual(401);
62-
});
63-
64-
describe('Authorized', () => {
65-
const newEmployee = {
66-
firstName: 'Tester',
67-
};
68-
let employeeId = '';
69-
let bearerToken = '';
70-
71-
beforeAll(async () => {
72-
// Create Employee
73-
const employee = await request(app.getHttpServer())
74-
.post('/employee')
75-
.send(newEmployee);
76-
77-
expect(employee.body).toHaveProperty('ok', true);
78-
expect(employee.body).toHaveProperty('result.id');
79-
80-
employeeId = employee.body.result.id;
81-
82-
// Create Employee Contact
83-
const contact = await request(app.getHttpServer())
84-
.post('/employee/contact')
85-
.send({
86-
employeeId,
87-
type: 'EMAIL',
88-
value: 'tester@test.org',
89-
isUsedForAuthentication: true,
90-
});
91-
92-
expect(contact.body).toHaveProperty('ok', true);
93-
94-
// Create Employee Password
95-
const password = await request(app.getHttpServer())
96-
.post('/employee/password')
97-
.send({
98-
employeeId,
99-
password: '12345678',
100-
});
101-
102-
expect(password.body).toHaveProperty('ok', true);
103-
104-
// Create Employee Permission: EDIT_CHANNELS
105-
const permission = await request(app.getHttpServer())
106-
.post('/employee/permission')
107-
.send({
108-
employeeId,
109-
type: 'EDIT_CHANNELS',
110-
});
111-
112-
expect(permission.body).toHaveProperty('ok', true);
113-
114-
// Sign In to get Bearer Token
115-
const sign = await request(app.getHttpServer())
116-
.post('/auth/employee/email')
117-
.send({
118-
email: 'tester@test.org',
119-
password: '12345678',
120-
});
121-
122-
expect(sign.body).toHaveProperty('ok', true);
123-
expect(sign.body).toHaveProperty('result.access_token');
124-
const accessToken = sign.body.result.access_token;
125-
126-
bearerToken = `Bearer ${accessToken}`;
127-
});
128-
129-
it('Should return 400 on creating new Channel with bad data', async () => {
130-
const response = await request(app.getHttpServer())
131-
.post('/channel')
132-
.send({})
133-
.set('Accept', 'application/json')
134-
.set('Authorization', bearerToken);
135-
136-
expect(response.status).toEqual(400);
137-
});
138-
139-
it('Should return 201 on creating new Channel with good data', async () => {
140-
const response = await request(app.getHttpServer())
141-
.post('/channel')
142-
.send(newChannelDto)
143-
.set('Accept', 'application/json')
144-
.set('Authorization', bearerToken);
145-
146-
expect(response.body).toHaveProperty('ok', true);
147-
expect(response.body).toHaveProperty('result.id');
148-
expect(response.status).toEqual(201);
149-
});
150-
});
151-
});
152-
153-
it('Should return all Channels', async () => {
154-
return request(app.getHttpServer())
155-
.get('/channel/list')
156-
.expect(200)
157-
.expect(({ body }) => {
158-
expect(body).toBeDefined();
159-
});
160-
});
161-
});
16243
});

test/channel.e2e-spec.ts

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { INestApplication } from '@nestjs/common';
3+
import * as request from 'supertest';
4+
import { AppModule } from '@/app.module';
5+
import { CreateChannelDto } from '@/core/channel/dto/create-channel.dto';
6+
7+
describe('ChannelController (e2e)', () => {
8+
let app: INestApplication;
9+
10+
beforeAll(async () => {
11+
const moduleRef: TestingModule = await Test.createTestingModule({
12+
imports: [AppModule],
13+
}).compile();
14+
15+
app = moduleRef.createNestApplication();
16+
await app.init();
17+
}, 20000);
18+
19+
afterAll(async () => {
20+
await app.close();
21+
});
22+
23+
describe('#createChannel', () => {
24+
const newChannelDto: CreateChannelDto = {
25+
slug: 'test',
26+
name: 'test',
27+
currencyCode: 'USD',
28+
languageCode: 'EN',
29+
countryCode: 'US',
30+
};
31+
32+
it('Should return 401 Unauthorized', async () => {
33+
const response = await request(app.getHttpServer())
34+
.post('/channel')
35+
.send({})
36+
.set('Accept', 'application/json');
37+
38+
expect(response.status).toEqual(401);
39+
});
40+
41+
describe('Authorized', () => {
42+
const newEmployee = {
43+
firstName: 'Tester',
44+
};
45+
let employeeId = '';
46+
let bearerToken = '';
47+
48+
beforeAll(async () => {
49+
// Create Employee
50+
const employee = await request(app.getHttpServer())
51+
.post('/employee')
52+
.send(newEmployee);
53+
54+
expect(employee.body).toHaveProperty('ok', true);
55+
expect(employee.body).toHaveProperty('result.id');
56+
57+
employeeId = employee.body.result.id;
58+
59+
// Create Employee Contact
60+
const contact = await request(app.getHttpServer())
61+
.post('/employee/contact')
62+
.send({
63+
employeeId,
64+
type: 'EMAIL',
65+
value: 'tester@test.org',
66+
isUsedForAuthentication: true,
67+
});
68+
69+
expect(contact.body).toHaveProperty('ok', true);
70+
71+
// Create Employee Password
72+
const password = await request(app.getHttpServer())
73+
.post('/employee/password')
74+
.send({
75+
employeeId,
76+
password: '12345678',
77+
});
78+
79+
expect(password.body).toHaveProperty('ok', true);
80+
81+
// Create Employee Permission: EDIT_CHANNELS
82+
const permission = await request(app.getHttpServer())
83+
.post('/employee/permission')
84+
.send({
85+
employeeId,
86+
type: 'EDIT_CHANNELS',
87+
});
88+
89+
expect(permission.body).toHaveProperty('ok', true);
90+
91+
// Sign In to get Bearer Token
92+
const sign = await request(app.getHttpServer())
93+
.post('/auth/employee/email')
94+
.send({
95+
email: 'tester@test.org',
96+
password: '12345678',
97+
});
98+
99+
expect(sign.body).toHaveProperty('ok', true);
100+
expect(sign.body).toHaveProperty('result.access_token');
101+
const accessToken = sign.body.result.access_token;
102+
103+
bearerToken = `Bearer ${accessToken}`;
104+
});
105+
106+
it('Should return 400 on creating new Channel with bad data', async () => {
107+
const response = await request(app.getHttpServer())
108+
.post('/channel')
109+
.send({})
110+
.set('Accept', 'application/json')
111+
.set('Authorization', bearerToken);
112+
113+
expect(response.status).toEqual(400);
114+
});
115+
116+
it('Should return 201 on creating new Channel with good data', async () => {
117+
const response = await request(app.getHttpServer())
118+
.post('/channel')
119+
.send(newChannelDto)
120+
.set('Accept', 'application/json')
121+
.set('Authorization', bearerToken);
122+
123+
expect(response.body).toHaveProperty('ok', true);
124+
expect(response.body).toHaveProperty('result.id');
125+
expect(response.status).toEqual(201);
126+
});
127+
});
128+
});
129+
130+
describe('#findAllChannels', () => {
131+
it('Should return all Channels', async () => {
132+
return request(app.getHttpServer())
133+
.get('/channel/list')
134+
.expect(200)
135+
.expect(({ body }) => {
136+
expect(body).toBeDefined();
137+
});
138+
});
139+
});
140+
141+
describe('#findChannelById', () => {
142+
it('Should return 404', async () => {
143+
return request(app.getHttpServer()).get('/channel/123').expect(404);
144+
});
145+
});
146+
});

0 commit comments

Comments
 (0)