Skip to content

Commit

Permalink
api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
seydx committed Jan 9, 2022
1 parent 1268c05 commit 26025a3
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 35 deletions.
6 changes: 1 addition & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [1.0.0] - ??-??-??
## [1.0.0] - 2022-01-09
- Initial relase
9 changes: 6 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

Pull requests are welcome from everyone.

This project uses Express for the server and VUE for the client UI.
This project uses Express for the server and VUE for the client interface.

**Credits goes also to:**

- [@oznu](https://github.com/oznu): I could learn a lot from homebridge-config-ui-x
- [@Sunoo](https://github.com/Sunoo): For the HTTP/MQTT/SMTP implementation
- [@phoboslab](https://github.com/phoboslab/jsmpeg) for the decoder. Without it it would not be possible to display the cameras via an interface
- [@Sunoo](https://github.com/Sunoo): For the HTTP/MQTT/SMTP/FTP implementation
- [@phoboslab](https://github.com/phoboslab/jsmpeg): For the awesome decoder to show camera streams within browser
- [@koush](https://github.com/koush): For the prebuffering process
- [@adumesny](https://github.com/gridstack/gridstack.js): Without Gridstack the dashboard would not be so nice and functional

And also many thanks to the other developers who are not mentioned by name! You rock!

## Translations

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020-2021 Seydx <[email protected]>
Copyright (c) 2020-2022 seydx <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
7 changes: 7 additions & 0 deletions src/api/components/cameras/cameras.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ exports.insert = async (req, res) => {

const result = await CamerasModel.createCamera(req.body);

if (!result) {
return res.status(409).send({
statusCode: 409,
message: 'Camera already exists',
});
}

res.status(201).send({
name: result.name,
});
Expand Down
31 changes: 8 additions & 23 deletions src/api/components/cameras/cameras.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ exports.createCamera = async (cameraData) => {

ConfigService.ui.cameras.push(cameraData);
ConfigService.writeToConfig('cameras', ConfigService.ui.cameras);

CameraController.createController(cameraData);
CameraController.startController(cameraData.name);
await CameraController.startController(cameraData.name);

await Database.writeConfigCamerasToDB();

Database.controller.emit('addCamera', cameraData);
Database.controller?.emit('addCamera', cameraData);

return cameraData;
} else {
throw new Error('Camera already exists in config.json');
return false;
}
};

Expand Down Expand Up @@ -91,18 +91,11 @@ exports.removeByName = async (name) => {

ConfigService.ui.cameras = ConfigService.ui.cameras.filter((camera) => camera.name !== name);
ConfigService.writeToConfig('cameras', ConfigService.ui.cameras);
CameraController.removeController(name);

await Database.writeConfigCamerasToDB();
Database.controller.emit('removeCamera', name);
await CameraController.removeController(name);

/*return await Database.interfaceDB
.get('cameras')
.remove((cam) => cam.name === name)
.get('settings')
.get('cameras')
.remove((cam) => cam.name === name)
.write();*/
await Database.writeConfigCamerasToDB();
Database.controller?.emit('removeCamera', name);

return;
};
Expand All @@ -120,15 +113,7 @@ exports.removeAll = async () => {
}

await Database.writeConfigCamerasToDB();
Database.controller.emit('removeCameras');

/*return await Database.interfaceDB
.get('cameras')
.remove(() => true)
.get('settings')
.get('cameras')
.remove(() => true)
.write();*/
Database.controller?.emit('removeCameras');

return;
};
4 changes: 2 additions & 2 deletions src/controller/camera/camera.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ class CameraController {

await controller.media.probe();

if (controller.options.prebuffering) {
if (controller.options?.prebuffering) {
await controller.prebuffer.start();
}

if (controller.options.videoanalysis.active) {
if (controller.options.videoanalysis?.active) {
await controller.videoanalysis.start();
}

Expand Down
3 changes: 3 additions & 0 deletions test/__tests__/cameras.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ describe('DELETE /api/cameras/:name', () => {
const response = await request
.delete('/api/cameras/Test Camera 3')
.auth(auth.body.access_token, { type: 'bearer' });

console.log(response.error);

expect(response.statusCode).toBe(204);
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/__tests__/notifications.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('POST /api/notifications', () => {
.send(notification);
expect(response.statusCode).toBe(201);

notificationId = response.body.id;
notificationId = response.body.notification.id;
});
});

Expand Down

0 comments on commit 26025a3

Please sign in to comment.