| Total Complexity | 6 |
| Complexity/F | 1.5 |
| Lines of Code | 49 |
| Function Count | 4 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { assert } from 'chai'; |
||
| 2 | import axios from 'axios'; |
||
| 3 | import { users } from '../mock/fixtures'; |
||
| 4 | import Test from '../Test'; |
||
| 5 | import { mockAppUrl } from '../constants'; |
||
| 6 | import chronicle, { middlewares } from '../entry'; |
||
| 7 | |||
| 8 | suite('Express'); |
||
| 9 | |||
| 10 | const factory = new Test(chronicle); |
||
| 11 | const expressMiddleWare = middlewares.express(chronicle); |
||
| 12 | |||
| 13 | before(async function () { |
||
| 14 | await factory.setTmpFolder(); |
||
| 15 | factory.mockApp.use(expressMiddleWare(req => { |
||
| 16 | if (req.url.includes('format')) { |
||
| 17 | return { |
||
| 18 | group : 'Format', |
||
| 19 | title : req.url |
||
| 20 | }; |
||
| 21 | } |
||
| 22 | |||
| 23 | return { |
||
| 24 | group : 'Users', |
||
| 25 | title : req.url.includes('limit=10') ? 'With limit' : 'general' |
||
| 26 | }; |
||
| 27 | })); |
||
| 28 | await factory.startMockApp(); |
||
| 29 | }); |
||
| 30 | |||
| 31 | test('Express middleware for get json array', async function () { |
||
| 32 | const response = await axios(`${mockAppUrl}/api/users?limit=10`); |
||
| 33 | const body = response.data; |
||
| 34 | |||
| 35 | assert.isArray(body); |
||
| 36 | assert.isNotEmpty(body); |
||
| 37 | assert.deepEqual(body, users); |
||
| 38 | const context = { title: 'With limit', group: 'Users' }; |
||
| 39 | |||
| 40 | factory.ensureAction(context, { |
||
| 41 | method : 'GET', |
||
| 42 | path : '/api/users', |
||
| 43 | body |
||
| 44 | }); |
||
| 45 | }); |
||
| 46 | |||
| 47 | after(async function () { |
||
| 48 | await factory.cleanup(); |
||
| 49 | }); |
||
| 50 |