1 | 'use strict';
|
2 |
|
3 |
|
4 | const request = require('supertest');
|
5 |
|
6 |
|
7 | const app = require('../src/app');
|
8 |
|
9 | describe('Update Camera Document', () => {
|
10 | before((done) => {
|
11 | app.init({
|
12 | logLevel: app.LOG_LEVEL.DEBUG,
|
13 | mongoUrl: process.env.CLIO_MONGO_URL,
|
14 | serverPort: process.env.CLIO_DATA_API_PORT,
|
15 | });
|
16 | app.launch(done);
|
17 | });
|
18 |
|
19 | let cameraId;
|
20 | it('should create new camera', (done) => {
|
21 | request(app)
|
22 | .post('/cameras')
|
23 | .send({
|
24 | projectId: 'test',
|
25 | publicAddress: '1.1.1.1',
|
26 | webPort: 11111,
|
27 | })
|
28 | .expect(201)
|
29 | .expect((res) => {
|
30 | if (res.text.length !== 24) throw new Error('Invalid Recorder ID');
|
31 | cameraId = res.text;
|
32 | })
|
33 | .end(done);
|
34 | });
|
35 |
|
36 | it('should read created camera', (done) => {
|
37 | request(app)
|
38 | .get(`/cameras/${cameraId}`)
|
39 | .expect(200)
|
40 | .expect((res) => console.log(JSON.stringify(res.body, null, 2)))
|
41 | .end(done);
|
42 | });
|
43 |
|
44 | it('should only update defined fields', (done) => {
|
45 | request(app)
|
46 | .put(`/cameras/${cameraId}`)
|
47 | .send({
|
48 | webPort: 22222,
|
49 | audio: { encoding: 'hifi' },
|
50 | streams: {
|
51 | 2: { rtspUrl: 'url2' },
|
52 | },
|
53 | })
|
54 | .expect(200)
|
55 | .end(done);
|
56 | });
|
57 |
|
58 | it('confirm updated camera reading', (done) => {
|
59 | request(app)
|
60 | .get(`/cameras/${cameraId}`)
|
61 | .expect(200)
|
62 | .expect((res) => console.log(JSON.stringify(res.body, null, 2)))
|
63 | .end(done);
|
64 | });
|
65 |
|
66 | it('should only update defined fields', (done) => {
|
67 | request(app)
|
68 | .put(`/cameras/${cameraId}`)
|
69 | .send({
|
70 | publicAddress: '123.123.123.123',
|
71 | audio: { bitRate: 123 },
|
72 | streams: { 0: { rtspUrl: 'url0' } },
|
73 | })
|
74 | .expect(200)
|
75 | .end(done);
|
76 | });
|
77 |
|
78 | it('confirm updated camera reading', (done) => {
|
79 | request(app)
|
80 | .get(`/cameras/${cameraId}`)
|
81 | .expect(200)
|
82 | .expect((res) => console.log(JSON.stringify(res.body, null, 2)))
|
83 | .end(done);
|
84 | });
|
85 |
|
86 | it('should update stream status', (done) => {
|
87 | request(app)
|
88 | .put(`/cameras/${cameraId}/streams/0/status`)
|
89 | .send({
|
90 | recorderId: 'recorder0',
|
91 | status: 'activated',
|
92 | module: 'broker',
|
93 | })
|
94 | .expect(200)
|
95 | .end(done);
|
96 | });
|
97 | });
|