|
1 | 1 | import { app } from 'egg-mock/bootstrap'; |
2 | 2 | import assert = require('assert'); |
| 3 | +// import { expect } from 'chai'; |
3 | 4 |
|
4 | 5 | describe('test/app/service/post.test.js', () => { |
5 | | - describe('GET /posts', () => { |
| 6 | + describe('GET /api/posts', () => { |
6 | 7 | it('should work', async () => { |
7 | 8 | await app.factory.createMany('post', 3); |
8 | | - const res = await app.httpRequest().get('/posts?limit=2'); |
| 9 | + const res = await app.httpRequest().get('/api/posts?limit=2'); |
9 | 10 | assert(res.status === 200); |
10 | | - assert(res.body.count === 3); |
11 | | - assert(res.body.rows.length === 2); |
12 | | - assert(res.body.rows[0].title); |
13 | | - assert(!res.body.rows[0].content); |
| 11 | + assert(res.body.data.count === 3); |
| 12 | + assert(res.body.data.rows.length === 2); |
| 13 | + assert(res.body.data.rows[0].title); |
| 14 | + assert(!res.body.data.rows[0].content); |
14 | 15 | }); |
15 | 16 | }); |
16 | 17 |
|
17 | | - describe('GET /posts/:id', () => { |
| 18 | + describe('GET /api/posts/:id', () => { |
18 | 19 | it('should work', async () => { |
19 | 20 | const post = await app.factory.create('post'); |
20 | | - const res = await app.httpRequest().get(`/posts/${post.id}`); |
| 21 | + const res = await app.httpRequest().get(`/api/posts/${post.id}`); |
21 | 22 | assert(res.status === 200); |
22 | | - assert(res.body.title === post.title); |
23 | | - assert(res.body.content === post.content); |
| 23 | + assert(res.body.data.title === post.title); |
| 24 | + assert(res.body.data.content === post.content); |
24 | 25 | }); |
25 | 26 | }); |
26 | 27 |
|
27 | | - describe('POST /posts', () => { |
| 28 | + describe('POST /api/posts', () => { |
28 | 29 | it('should work', async () => { |
29 | 30 | app.mockCsrf(); |
30 | | - let res = await app.httpRequest().post('/posts') |
| 31 | + let res = await app.httpRequest().post('/api/posts') |
31 | 32 | .send({ |
32 | 33 | title: 'title', |
33 | 34 | content: 'content', |
34 | 35 | user_id: 1, |
35 | 36 | }); |
36 | 37 | assert(res.status === 201); |
37 | | - assert(res.body.id); |
| 38 | + assert(res.body.data.id); |
38 | 39 |
|
39 | | - res = await app.httpRequest().get(`/posts/${res.body.id}`); |
| 40 | + res = await app.httpRequest().get(`/api/posts/${res.body.data.id}`); |
40 | 41 | assert(res.status === 200); |
41 | | - assert(res.body.title === 'title'); |
| 42 | + assert(res.body.data.title === 'title'); |
42 | 43 | }); |
43 | 44 | }); |
44 | 45 |
|
45 | | - describe('DELETE /posts/:id', () => { |
| 46 | + describe('DELETE /api/posts/:id', () => { |
46 | 47 | it('should work', async () => { |
47 | 48 | const post = await app.factory.create('post'); |
48 | 49 |
|
49 | 50 | app.mockCsrf(); |
50 | | - const res = await app.httpRequest().delete(`/posts/${post.id}`) |
| 51 | + const res = await app.httpRequest().delete(`/api/posts/${post.id}`) |
51 | 52 | .send({ user_id: post.user_id }); |
52 | 53 | assert(res.status === 200); |
53 | 54 | }); |
|
0 commit comments