Skip to content

Commit f461180

Browse files
committed
e2e tests added
1 parent 44e6630 commit f461180

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

src/builds/builds.controller.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Controller, Get, UseGuards, Post, Body, Param, ParseUUIDPipe, Delete, Query, Patch } from '@nestjs/common';
22
import { BuildsService } from './builds.service';
33
import { JwtAuthGuard } from '../auth/guards/auth.guard';
4-
import { ApiBearerAuth, ApiTags, ApiParam, ApiSecurity, ApiQuery, ApiResponse } from '@nestjs/swagger';
4+
import { ApiBearerAuth, ApiTags, ApiSecurity, ApiResponse } from '@nestjs/swagger';
55
import { CreateBuildDto } from './dto/build-create.dto';
66
import { ApiGuard } from '../auth/guards/api.guard';
77
import { Build } from '@prisma/client';
@@ -13,7 +13,6 @@ export class BuildsController {
1313
constructor(private buildsService: BuildsService) {}
1414

1515
@Get()
16-
@ApiQuery({ name: 'projectId', required: true })
1716
@ApiResponse({ type: [BuildDto] })
1817
@ApiBearerAuth()
1918
@UseGuards(JwtAuthGuard)
@@ -22,7 +21,6 @@ export class BuildsController {
2221
}
2322

2423
@Delete(':id')
25-
@ApiParam({ name: 'id', required: true })
2624
@ApiBearerAuth()
2725
@UseGuards(JwtAuthGuard)
2826
remove(@Param('id', new ParseUUIDPipe()) id: string): Promise<Build> {
@@ -37,7 +35,7 @@ export class BuildsController {
3735
return this.buildsService.create(createBuildDto);
3836
}
3937

40-
@Patch()
38+
@Patch(':id')
4139
@ApiResponse({ type: BuildDto })
4240
@ApiSecurity('api_key')
4341
@UseGuards(ApiGuard)

test/builds.e2e-spec.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ describe('Builds (e2e)', () => {
5252
};
5353
return requestWithApiKey(app, 'post', '/builds', createBuildDto, user.apiKey)
5454
.expect(201)
55-
.expect(res => {
55+
.expect((res) => {
5656
expect(res.body.projectId).toBe(project.id);
5757
expect(res.body.branchName).toBe(createBuildDto.branchName);
5858
expect(res.body.failedCount).toBe(0);
5959
expect(res.body.passedCount).toBe(0);
6060
expect(res.body.unresolvedCount).toBe(0);
61+
expect(res.body.isRunning).toBe(true);
6162
});
6263
});
6364

@@ -68,15 +69,16 @@ describe('Builds (e2e)', () => {
6869
};
6970
return requestWithApiKey(app, 'post', '/builds', createBuildDto, user.apiKey)
7071
.expect(201)
71-
.expect(res => {
72+
.expect((res) => {
7273
expect(res.body.projectId).toBe(project.id);
7374
expect(res.body.branchName).toBe(createBuildDto.branchName);
7475
expect(res.body.failedCount).toBe(0);
7576
expect(res.body.passedCount).toBe(0);
7677
expect(res.body.unresolvedCount).toBe(0);
78+
expect(res.body.isRunning).toBe(true);
7779
});
7880
});
79-
81+
8082
it('404', () => {
8183
const createBuildDto: CreateBuildDto = {
8284
branchName: 'branchName',
@@ -100,7 +102,7 @@ describe('Builds (e2e)', () => {
100102

101103
return requestWithAuth(app, 'get', `/builds?projectId=${project.id}`, {}, user.token)
102104
.expect(200)
103-
.expect(res => {
105+
.expect((res) => {
104106
expect(JSON.stringify(res.body)).toEqual(JSON.stringify([build]));
105107
});
106108
});
@@ -123,4 +125,23 @@ describe('Builds (e2e)', () => {
123125
return requestWithAuth(app, 'delete', `/builds/${build.id}`, {}, '').expect(401);
124126
});
125127
});
128+
129+
describe('PATCH /', () => {
130+
it('200', async () => {
131+
const build = await buildsService.create({ project: project.id, branchName: 'develop' });
132+
133+
return requestWithApiKey(app, 'patch', `/builds/${build.id}`, {}, user.apiKey)
134+
.expect(200)
135+
.expect((res) => {
136+
expect(res.body.projectId).toBe(project.id);
137+
expect(res.body.isRunning).toBe(false);
138+
});
139+
});
140+
141+
it('401', async () => {
142+
const build = await buildsService.create({ project: project.id, branchName: 'develop' });
143+
144+
return requestWithAuth(app, 'patch', `/builds/${build.id}`, {}, '').expect(401);
145+
});
146+
});
126147
});

test/preconditions.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const generateUser = (
1414

1515
export const requestWithAuth = (
1616
app: INestApplication,
17-
method: 'post' | 'get' | 'put' | 'delete',
17+
method: 'post' | 'get' | 'put' | 'delete' | 'patch',
1818
url: string,
1919
body = {},
2020
token: string
@@ -26,15 +26,11 @@ export const requestWithAuth = (
2626

2727
export const requestWithApiKey = (
2828
app: INestApplication,
29-
method: 'post' | 'get' | 'put' | 'delete',
29+
method: 'post' | 'get' | 'put' | 'delete' | 'patch',
3030
url: string,
3131
body = {},
3232
apiKey: string
33-
): Test =>
34-
request(app.getHttpServer())
35-
[method](url)
36-
.set('apiKey', apiKey)
37-
.send(body);
33+
): Test => request(app.getHttpServer())[method](url).set('apiKey', apiKey).send(body);
3834

3935
export const haveUserLogged = async (usersService: UsersService) => {
4036
const password = '123456';

0 commit comments

Comments
 (0)