Skip to content

Commit 27d9d06

Browse files
committed
test: refactor error
1 parent c41c164 commit 27d9d06

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
roots: ['<rootDir>/tests'],
2+
roots: ['<rootDir>/src'],
33
collectCoverageFrom: [
44
'<rootDir>/src/**/*.ts',
55
'!<rootDir>/src/main/**'

src/controlllers/signup.spec.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,27 @@ describe('SignUp controller', () => {
55
const sut = new SignUpController()
66
const httpRequest = {
77
body: {
8-
name: 'any_name',
98
109
password: 'any_password',
1110
passwordConformation: 'any_password'
1211
}
1312
}
1413
const httpResponse = sut.handle(httpRequest)
1514
expect(httpResponse.statusCode).toBe(400)
15+
expect(httpResponse.body).toEqual(new Error('Missing param: name'))
16+
})
17+
18+
test('Should return 400 if no email is prvided', () => {
19+
const sut = new SignUpController()
20+
const httpRequest = {
21+
body: {
22+
name: 'any_name',
23+
password: 'any_password',
24+
passwordConformation: 'any_password'
25+
}
26+
}
27+
const httpResponse = sut.handle(httpRequest)
28+
expect(httpResponse.statusCode).toBe(400)
29+
expect(httpResponse.body).toEqual(new Error('Missing param: email'))
1630
})
1731
})

src/controlllers/signup.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
export class SignUpController {
22
handle (httpRequest: any): any {
3-
return {
4-
statusCode: 400
3+
if (!httpRequest.body.name) {
4+
return {
5+
statusCode: 400,
6+
body: new Error('Missing param: name')
7+
}
8+
}
9+
10+
if (!httpRequest.body.email) {
11+
return {
12+
statusCode: 400,
13+
body: new Error('Missing param: email')
14+
}
515
}
616
}
717
}

0 commit comments

Comments
 (0)