| Total Complexity | 10 |
| Complexity/F | 1 |
| Lines of Code | 79 |
| Function Count | 10 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | const router = require('./../../../src/routes/index'); |
||
| 2 | |||
| 3 | describe('Index routes.', () => { |
||
| 4 | test('GET homepage', (done) => { |
||
| 5 | const request = { |
||
| 6 | method: 'GET', |
||
| 7 | url: '/', |
||
| 8 | }; |
||
| 9 | const response = { |
||
| 10 | redirect: (targetUrl) => { |
||
| 11 | expect(targetUrl).toMatch(/.+/); |
||
| 12 | done(); |
||
| 13 | }, |
||
| 14 | }; |
||
| 15 | |||
| 16 | router.handle(request, response); |
||
| 17 | }); |
||
| 18 | |||
| 19 | test('GET page by streamId', (done) => { |
||
| 20 | const request = { |
||
| 21 | method: 'GET', |
||
| 22 | url: '/testId', |
||
| 23 | }; |
||
| 24 | const response = { |
||
| 25 | render: (tpl, data) => { |
||
| 26 | expect(tpl).toBe('index'); |
||
| 27 | expect(typeof data).toBe('object'); |
||
| 28 | done(); |
||
| 29 | }, |
||
| 30 | }; |
||
| 31 | |||
| 32 | router.handle(request, response); |
||
| 33 | }); |
||
| 34 | |||
| 35 | /** |
||
| 36 | * This block describes test cases related to POSTing data into page. |
||
| 37 | */ |
||
| 38 | describe('POST data into page with certain streamId.', () => { |
||
| 39 | const request = { |
||
| 40 | method: 'POST', |
||
| 41 | url: '/testId', |
||
| 42 | headers: { |
||
| 43 | 'content-type': 'application/json', |
||
| 44 | }, |
||
| 45 | connection: { |
||
| 46 | socket: { |
||
| 47 | remoteAddress: 'testIp', |
||
| 48 | }, |
||
| 49 | }, |
||
| 50 | socket: {}, |
||
| 51 | body: 'RAW Body.', |
||
| 52 | }; |
||
| 53 | /** global: jest */ |
||
| 54 | const response = { |
||
| 55 | status: jest.fn(), |
||
| 56 | send: jest.fn(), |
||
| 57 | }; |
||
| 58 | |||
| 59 | test('POST JSON', (done) => { |
||
| 60 | request.body = '{"decs": "JSON data"}'; |
||
| 61 | global.socket = { |
||
| 62 | emit: (type, data) => { |
||
| 63 | expect(type).toBe('log'); |
||
| 64 | expect(typeof data).toBe('object'); |
||
| 65 | done(); |
||
| 66 | }, |
||
| 67 | }; |
||
| 68 | |||
| 69 | router.handle(request, response); |
||
| 70 | }); |
||
| 71 | |||
| 72 | test('POST plain text', (done) => { |
||
| 73 | request.headers['content-type'] = 'text'; |
||
| 74 | response.send = () => done(); |
||
| 75 | |||
| 76 | router.handle(request, response); |
||
| 77 | }); |
||
| 78 | }); |
||
| 79 | }); |
||
| 80 |