Skip to content

Commit 2248cf2

Browse files
committed
email field
1 parent 852f7f8 commit 2248cf2

File tree

3 files changed

+163
-2
lines changed

3 files changed

+163
-2
lines changed

examples/rubico-http-server/runserver-complex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ function runserver(options = {}) {
134134
error.code = 400
135135
throw error
136136
}
137+
if (typeof requestBodyJSON.email != 'string') {
138+
const error = new Error('Bad Request')
139+
error.code = 400
140+
throw error
141+
}
137142

138143
const user = {
139144
id: requestBodyJSON.id,

examples/rubico-http-server/runserver-simple

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,18 @@ function runserver(options = {}) {
130130
error.code = 400
131131
throw error
132132
}
133+
if (typeof requestBodyJSON.email != 'string') {
134+
const error = new Error('Bad Request')
135+
error.code = 400
136+
throw error
137+
}
133138

134139
const user = {
135140
id: requestBodyJSON.id,
136141
name: requestBodyJSON.name,
137142
birthdate: requestBodyJSON.birthdate,
138143
profilePictureUrl: requestBodyJSON.profilePictureUrl,
144+
email: requestBodyJSON.email,
139145
createTime: Date.now(),
140146
}
141147

examples/rubico-http-server/runserver.test.js

Lines changed: 152 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,82 @@ describe('runserver-simple', () => {
2727

2828
const userId = '100'
2929

30-
{ // put user
30+
{ // put user bad request (id missing)
31+
const response = await http.put(`/user/${userId}`, {
32+
body: JSON.stringify({
33+
// id: userId,
34+
name: `User ${userId}`,
35+
birthdate: '2020-01-01',
36+
profilePictureUrl: 'https://rubico.land/assets/rubico-logo.png',
37+
38+
}),
39+
})
40+
41+
assert.equal(response.status, 400)
42+
assert.deepEqual(await response.text(), 'Bad Request')
43+
}
44+
45+
{ // put user bad request (name missing)
46+
const response = await http.put(`/user/${userId}`, {
47+
body: JSON.stringify({
48+
id: userId,
49+
// name: `User ${userId}`,
50+
birthdate: '2020-01-01',
51+
profilePictureUrl: 'https://rubico.land/assets/rubico-logo.png',
52+
53+
}),
54+
})
55+
56+
assert.equal(response.status, 400)
57+
assert.deepEqual(await response.text(), 'Bad Request')
58+
}
59+
60+
{ // put user bad request (birthdate missing)
61+
const response = await http.put(`/user/${userId}`, {
62+
body: JSON.stringify({
63+
id: userId,
64+
name: `User ${userId}`,
65+
// birthdate: '2020-01-01',
66+
profilePictureUrl: 'https://rubico.land/assets/rubico-logo.png',
67+
68+
}),
69+
})
70+
71+
assert.equal(response.status, 400)
72+
assert.deepEqual(await response.text(), 'Bad Request')
73+
}
74+
75+
{ // put user bad request (profilePictureUrl missing)
76+
const response = await http.put(`/user/${userId}`, {
77+
body: JSON.stringify({
78+
id: userId,
79+
name: `User ${userId}`,
80+
birthdate: '2020-01-01',
81+
// profilePictureUrl: 'https://rubico.land/assets/rubico-logo.png',
82+
83+
}),
84+
})
85+
86+
assert.equal(response.status, 400)
87+
assert.deepEqual(await response.text(), 'Bad Request')
88+
}
89+
90+
{ // put user bad request (email missing)
91+
const response = await http.put(`/user/${userId}`, {
92+
body: JSON.stringify({
93+
id: userId,
94+
name: `User ${userId}`,
95+
birthdate: '2020-01-01',
96+
profilePictureUrl: 'https://rubico.land/assets/rubico-logo.png',
97+
// email: '[email protected]',
98+
}),
99+
})
100+
101+
assert.equal(response.status, 400)
102+
assert.deepEqual(await response.text(), 'Bad Request')
103+
}
104+
105+
{ // put user success
31106
const response = await http.put(`/user/${userId}`, {
32107
body: JSON.stringify({
33108
id: userId,
@@ -87,7 +162,82 @@ describe('runserver-complex', () => {
87162

88163
const userId = '100'
89164

90-
{ // put user
165+
{ // put user bad request (id missing)
166+
const response = await http.put(`/user/${userId}`, {
167+
body: JSON.stringify({
168+
// id: userId,
169+
name: `User ${userId}`,
170+
birthdate: '2020-01-01',
171+
profilePictureUrl: 'https://rubico.land/assets/rubico-logo.png',
172+
173+
}),
174+
})
175+
176+
assert.equal(response.status, 400)
177+
assert.deepEqual(await response.text(), 'Bad Request')
178+
}
179+
180+
{ // put user bad request (name missing)
181+
const response = await http.put(`/user/${userId}`, {
182+
body: JSON.stringify({
183+
id: userId,
184+
// name: `User ${userId}`,
185+
birthdate: '2020-01-01',
186+
profilePictureUrl: 'https://rubico.land/assets/rubico-logo.png',
187+
188+
}),
189+
})
190+
191+
assert.equal(response.status, 400)
192+
assert.deepEqual(await response.text(), 'Bad Request')
193+
}
194+
195+
{ // put user bad request (birthdate missing)
196+
const response = await http.put(`/user/${userId}`, {
197+
body: JSON.stringify({
198+
id: userId,
199+
name: `User ${userId}`,
200+
// birthdate: '2020-01-01',
201+
profilePictureUrl: 'https://rubico.land/assets/rubico-logo.png',
202+
203+
}),
204+
})
205+
206+
assert.equal(response.status, 400)
207+
assert.deepEqual(await response.text(), 'Bad Request')
208+
}
209+
210+
{ // put user bad request (profilePictureUrl missing)
211+
const response = await http.put(`/user/${userId}`, {
212+
body: JSON.stringify({
213+
id: userId,
214+
name: `User ${userId}`,
215+
birthdate: '2020-01-01',
216+
// profilePictureUrl: 'https://rubico.land/assets/rubico-logo.png',
217+
218+
}),
219+
})
220+
221+
assert.equal(response.status, 400)
222+
assert.deepEqual(await response.text(), 'Bad Request')
223+
}
224+
225+
{ // put user bad request (email missing)
226+
const response = await http.put(`/user/${userId}`, {
227+
body: JSON.stringify({
228+
id: userId,
229+
name: `User ${userId}`,
230+
birthdate: '2020-01-01',
231+
profilePictureUrl: 'https://rubico.land/assets/rubico-logo.png',
232+
// email: '[email protected]',
233+
}),
234+
})
235+
236+
assert.equal(response.status, 400)
237+
assert.deepEqual(await response.text(), 'Bad Request')
238+
}
239+
240+
{ // put user success
91241
const response = await http.put(`/user/${userId}`, {
92242
body: JSON.stringify({
93243
id: userId,

0 commit comments

Comments
 (0)