UNPKG

@arisan/data-api

Version:

The Universal Database API Gateway for CLIO's Modules

196 lines (173 loc) 7.67 kB
'use strict'; var _powMongodbFixtures = require('pow-mongodb-fixtures'); var _mongodbUri = require('mongodb-uri'); var _mongodbUri2 = _interopRequireDefault(_mongodbUri); var _DataAPI = require('../DataAPI'); var _DataAPI2 = _interopRequireDefault(_DataAPI); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /* eslint-disable import/newline-after-import, import/first */ //region 1. Platform Libraries const request = require('supertest'); //endregion //region 2. Project Libraries //endregion describe('Route .../events', () => { const mongo = _mongodbUri2.default.parse(process.env.CLIO_MONGO_URL); const fixtures = (0, _powMongodbFixtures.connect)(mongo.database, { host: mongo.hosts[0].host, port: mongo.hosts[0].port, user: mongo.username, pass: mongo.password }); const dataAPI = new _DataAPI2.default(); const projectId = '123456789a123456789b1235'; const cameraId1 = '123456789a123456789b1234'; const streamIndex1 = 1; const cameraId2 = '123456789a123456789b1236'; const streamIndex2 = 0; const invalidCameraId = '123456789a123456789b1231'; const fileSizeAsBytes = 5242880; before(function before(done) { this.timeout(5000); fixtures.clearAllAndLoad({ cameras: [{ _id: (0, _powMongodbFixtures.createObjectId)(cameraId1), project_id: (0, _powMongodbFixtures.createObjectId)(projectId), public_address: '123.123.123.123', web_port: 80, username: 'onvif', password: 'onvif', triggering_camera_id: (0, _powMongodbFixtures.createObjectId)(cameraId1), streams: [{}, { rtsp_url: 'rtsp://url', frame_rate_limit: 30, gov_length: 15 }], active_stream_index: streamIndex1 }, { _id: (0, _powMongodbFixtures.createObjectId)(cameraId2), project_id: (0, _powMongodbFixtures.createObjectId)(projectId), public_address: '123.123.123.124', web_port: 80, username: 'onvif', password: 'onvif', triggering_camera_id: (0, _powMongodbFixtures.createObjectId)(cameraId1), streams: [{ rtsp_url: 'rtsp://url', frame_rate_limit: 30, gov_length: 15 }], active_stream_index: streamIndex2 }] }, err => { if (err) { throw new Error(err.message); } dataAPI.initialize({ environment: 'unit-test', heartbeatInterval: 10, logLevel: 'DEBUG', mongoUrl: process.env.CLIO_MONGO_URL, port: 15925 }); dataAPI.start(done); }); }); it('POST existing stream should succeed', done => { request(dataAPI.expressApp).post(`/cameras/${cameraId1}/streams/${streamIndex1}/events`).send({ type: 'DIO', time: 1470296111425 }).expect(200).end( /** @type function */done); }); it('POST invalid stream should fail', done => { request(dataAPI.expressApp).post(`/cameras/${invalidCameraId}/streams/${streamIndex1}/events`).send({ type: 'DIO', time: 1470296111425 }).expect(500).end( /** @type function */done); }); it('POST invalid body should fail', done => { request(dataAPI.expressApp).post(`/cameras/${cameraId1}/streams/${streamIndex1}/events`).send({ type: 'DIO' }).expect(400).end( /** @type function */done); }); it('PUT event video status should succeed', done => { request(dataAPI.expressApp).put(`/cameras/${cameraId1}/streams/${streamIndex1}/events?time=1470296111425`).send({ videoInfo: { status: 'recording', streamId: `${cameraId1}_${streamIndex1}` } }).expect(200).end( /** @type function */done); }); it('PUT event video info should fail with incorrect time', done => { request(dataAPI.expressApp).put(`/cameras/${cameraId1}/streams/${streamIndex1}/events?time=1470296111426`).send({ videoInfo: { status: 'uploaded', startTime: 1474250357286, endTime: 1474250367286, bucketName: 'io-arisan-clio-sandbox-test', objectName: 'path/to/obj.mp4', streamId: `${cameraId2}_${streamIndex2}`, size: fileSizeAsBytes } }).expect(500).end( /** @type function */done); }); it('PUT event video info should succeed', done => { request(dataAPI.expressApp).put(`/cameras/${cameraId1}/streams/${streamIndex1}/events?time=1470296111425`).send({ videoInfo: { status: 'uploaded', startTime: 1474250357286, endTime: 1474250367286, bucketName: 'io-arisan-clio-sandbox-test', objectName: 'path/to/obj.mp4', streamId: `${cameraId2}_${streamIndex2}`, size: fileSizeAsBytes } }).expect(200).end( /** @type function */done); }); it('PUT event info without size field should fail', done => { request(dataAPI.expressApp).put(`/cameras/${cameraId1}/streams/${streamIndex1}/events?time=1470296111425`).send({ videoInfo: { status: 'uploaded', startTime: 1474250357286, endTime: 1474250367286, bucketName: 'io-arisan-clio-sandbox-test', objectName: 'path/to/obj.mp4', streamId: `${cameraId2}_${streamIndex2}` } }).expect(400).end( /** @type function */done); }); it('PUT should fail when size is not a integer', done => { request(dataAPI.expressApp).put(`/cameras/${cameraId1}/streams/${streamIndex1}/events?time=1470296111425`).send({ videoInfo: { status: 'uploaded', startTime: 1474250357286, endTime: 1474250367286, bucketName: 'io-arisan-clio-sandbox-test', objectName: 'path/to/obj.mp4', streamId: `${cameraId2}_${streamIndex2}`, size: `${fileSizeAsBytes}` } }).expect(400).end( /** @type function */done); }); it('PUT should fail without videoInfo', done => { request(dataAPI.expressApp).put(`/cameras/${cameraId1}/streams/${streamIndex1}/events?time=1470296111425`).send({ status: 'uploaded', startTime: 1474250357286, endTime: 1474250367286, bucketName: 'io-arisan-clio-sandbox-test', objectName: 'path/to/obj.mp4', streamId: `${cameraId2}_${streamIndex2}` }).expect(400).end( /** @type function */done); }); it('PUT should fail without streamId', done => { request(dataAPI.expressApp).put(`/cameras/${cameraId1}/streams/${streamIndex1}/events?time=1470296111425`).send({ videoInfo: { status: 'uploaded', startTime: 1474250357286, endTime: 1474250367286, bucketName: 'io-arisan-clio-sandbox-test', objectName: 'path/to/obj.mp4' } }).expect(400).end( /** @type function */done); }); after(done => dataAPI.stop(done)); }); //# sourceMappingURL=mountEvents.spec.js.map