-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.spec.js
executable file
·166 lines (156 loc) · 3.95 KB
/
index.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
const should = require('should');
const request = require('supertest');
const app = require('./index');
describe('Get /Users는', () => {
describe('성공시 ', () => {
it('유저 객체를 담은 배열로 응답한다.', (done) => {
request(app)
.get('/users')
.end((err, res) => {
res.body.should.be.instanceOf(Array);
done();
});
});
it('최대 limit 갯수만큼 응답한다.', (done) => {
request(app)
.get('/users?limit=2')
.end((err, res) => {
res.body.should.have.lengthOf(2);
done();
});
});
});
describe('실패시', () => {
it('Limit이 숫자형이 아니면 400을 응답한다.', (done) => {
request(app)
.get('/users/?limit=two')
.expect(400)
.end(done);
});
});
});
describe('Get /users/:id는', () => {
describe('성공시', () => {
it('id가 1인 유저 객챌르 반환한다.', (done) => {
request(app)
.get('/users/1')
.end((err, res) => {
res.body.should.have.property('id', 1);
done();
});
});
});
describe('실패시', () => {
it('id가 숫자가 아닐 경우 400으로 응답한다.', (done) => {
request(app)
.get('/users/one')
.expect(400)
.end(done);
});
it('id로 유저를 찾을수 없는 걍우 404로 응답한다.', (done) => {
request(app)
.get('/users/9999')
.expect(404)
.end(done);
});
});
});
describe('DELETE /users/:id', () => {
describe('성공시', () => {
it('204를 응답한다', (done) => {
request(app)
.delete('/users/1')
.expect(204)
.end(done);
});
});
describe('실패시', () => {
it('id가 숫자가 아닐경우 400으로 응답한다.', (done) => {
request(app)
.delete('/users/one')
.expect(400)
.end(done);
});
});
});
describe('POST는 /users', () => {
describe('성공시', () => {
let name = 'test',
body;
before(done => {
request(app)
.post('/users')
.send({name})
.expect(201)
.end((err, res) => {
body = res.body;
done();
});
});
it('생성된 유저 객체를 반환한다.', () => {
body.should.have.property('id');
});
it('입력한 name을 반환한다', () => {
body.should.have.property('name', name);
});
});
describe('실패시', () => {
it('name 파라미테거 누락시 400을 반환한다.', (done) => {
request(app)
.post('/users')
.send({})
.expect(400)
.end(done);
});
it('name이 중복일 경우 4009를 반환한다.', (done) => {
request(app)
.post('/users')
.send({name: 'test'})
.expect(409)
.end(done);
});
});
});
describe('PUT는 /users', () => {
describe('성공시', () => {
it('변경된 name을 응답한다.', (done) => {
const name = 'yun';
request(app)
.put('/users/3')
.send({name: name})
.end((err, res) => {
res.body.should.have.property('name', name);
done();
});
});
});
describe('실패시', () => {
it('정수가아닌 id일 경우 400을 응답한다', (done) => {
request(app)
.put('/users/one')
.expect(400)
.end(done);
});
it('name이 없을경우 400을 응답한다', (done) => {
request(app)
.put('/users/one')
.send()
.expect(400)
.end(done);
});
it('없는 유저일 경우 404을 응답한다.', (done) => {
request(app)
.put('/users/999')
.send({name: 'foo'})
.expect(404)
.end(done);
});
it('이름이 중복일 경우 409를 응답한다.', (done) => {
request(app)
.put('/users/3')
.send({name: 'test2'})
.expect(409)
.end(done);
});
});
});