Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AN-297-Adding unit tests for Device Registry. #1343

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7fa84e6
AN-297-Adding tests for create site util
BenjaminSsempala Feb 15, 2023
dd88f8e
Merge branch 'staging' into AN-297-Adding-unit-tests
BenjaminSsempala Feb 15, 2023
4a4db8c
AN-297-Some SETUP works
BenjaminSsempala Feb 23, 2023
4215420
AN-297-Finallising create-sites-util test
BenjaminSsempala Feb 23, 2023
86c85bb
AN-297-create-device-utils
BenjaminSsempala Feb 23, 2023
ee31a50
AN-297-Finalising create-site-util-test
BenjaminSsempala Feb 27, 2023
c0d7ce2
AN-297-Create device tests
BenjaminSsempala Mar 1, 2023
d2abaeb
Merge branch 'staging' into AN-297-Adding-unit-tests
BenjaminSsempala Mar 3, 2023
aa4b2b1
AN-297-create activity tests
BenjaminSsempala Mar 3, 2023
623659b
AN-297-removing brackets and small changes
BenjaminSsempala Mar 13, 2023
5490593
Merge branch 'staging' into AN-297-Adding-unit-tests
BenjaminSsempala Mar 28, 2023
c324ad8
Merge branch 'staging' into AN-297-Adding-unit-tests
BenjaminSsempala Apr 24, 2023
78e85ec
Create airQloud, and multitenancy
BenjaminSsempala Apr 27, 2023
cbad65b
Tests For Create-airQolud
BenjaminSsempala May 10, 2023
4a2579e
Tests for Multitenancy
BenjaminSsempala May 10, 2023
c08b3c5
Tests for Logging functionality
BenjaminSsempala May 10, 2023
d313f75
Tests for generate Filter
BenjaminSsempala May 10, 2023
248beef
Unit tests for date.js
BenjaminSsempala May 16, 2023
a5728dc
Unit tests for distance.js
BenjaminSsempala May 17, 2023
9bedb7e
Photo util and sensor util unit tests
BenjaminSsempala May 17, 2023
09edb4e
create Monitor tests
BenjaminSsempala May 17, 2023
640483b
Testing errors.js
BenjaminSsempala May 25, 2023
50d9974
Create-Location tests
BenjaminSsempala Jun 13, 2023
e383ff7
Tests for health-tips
BenjaminSsempala Jun 13, 2023
0a3c509
part of create EVents
BenjaminSsempala Jun 19, 2023
b3897c2
create event
BenjaminSsempala Jun 20, 2023
f24746c
updating scripts
BenjaminSsempala Jul 5, 2023
102dc88
Merge branch 'staging' into AN-297-Adding-unit-tests
BenjaminSsempala Jul 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/device-registry/models/Site.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require("module-alias/register");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the motivation for adding the "alias" module to this Models file? Does it help out in the testing process? @BenjaminSsempala

Copy link
Contributor Author

@BenjaminSsempala BenjaminSsempala Mar 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Baalmart yes, I discovered it was required but I guess because I shifted focus to first finish utils, I'll look more into this as I go into models

const { Schema } = require("mongoose");
const ObjectId = Schema.Types.ObjectId;
const uniqueValidator = require("mongoose-unique-validator");
Expand Down
44 changes: 0 additions & 44 deletions src/device-registry/models/test/device.js

This file was deleted.

96 changes: 96 additions & 0 deletions src/device-registry/models/test/ut_device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"use-strict";
const imageController = require("../Device");

let chai = require("chai"),
expect = chai.expect;
chai.should();
const chaiHttp = require("chai-http");
const should = chai.should();
const assert = chai.assert;
const faker = require("faker");
const sinon = require("sinon");
const request = require("request");
chai.use(chaiHttp);
const DeviceSchema = require("../Device");
const SiteModel = require("../../utils/multitenancy");

const stubValue = {
_name_id: faker.datatype.uuid(),
tenant: "airqo",
name: faker.name.findName(),
latitude: faker.address.latitude(),
longitude: faker.address.longitude(),
createdAt: faker.date.past(),
updatedAt: faker.date.past(),
approximate_distance_in_km: faker.datatype.float(),
writeKey: faker.name.writeKey(),
readKey: faker.name.readKey(),
network:faker.company.network(),
access_code:faker.datatype.int(),
visibility: faker.datatype.boolean(),
generation_version: faker.datatype.float(),
generation_count:faker.datatype.int(),
mobility: faker.datatype.boolean(),
height: faker.datatype.float(),
mountType:faker.datatype.mountType(),
device_codes:faker.datatype.array(),
status: faker.datatype.status(),
ISP:faker.datatype.ISP(),
phoneNumber: faker.phone.unique(),
powerType:faker.random.powerType(),
host_id: faker.random.unique(),
site_id:faker.datatype.uuid(),
device_number: faker.random.unique(),
category: faker.name.category(),
isActive:faker.datatype.isActive()
};

describe("create a device", function() {
beforeEach(function() {});
afterEach(function() {});
it("should have validation error for a duplicate compoment type name", function () {

});
});

describe("read device ", function() {
beforeEach(function() {});
afterEach(function() {});
it("should find the existing device ", function () {

});
});

describe("deleting device ", function() {
beforeEach(function() {});
afterEach(function() {});
it("should delete a device using ID", function () {

});

it("should delete a device using the name", function () {

});

it("should remove multiple device ", function () {

});

it("should remove device using its instance", function () {

});
});
BenjaminSsempala marked this conversation as resolved.
Show resolved Hide resolved

describe("updating a device", function() {
beforeEach(function() {});
afterEach(function() {});
it("should set and saves a device using an instance", function() {});

it("should update a device using its instance", function() {});

it("should update one device using the model", function() {});

it("should update one device with ID using model", function() {});

it("should return error is the update action fails", function() {});
});
227 changes: 116 additions & 111 deletions src/device-registry/package.json
Original file line number Diff line number Diff line change
@@ -1,112 +1,117 @@
{
"name": "device-registry",
"version": "0.0.0",
"private": true,
"main": "./bin/www",
"scripts": {
"start": "NODE_ENV=production node --max-old-space-size=1024 ./bin/www",
"stage": "NODE_ENV=staging node --max-old-space-size=1024 ./bin/www",
"dev-mac": "NODE_ENV=development nodemon --max-old-space-size=1024 ./bin/www",
"prod-mac": "NODE_ENV=production nodemon --max-old-space-size=1024 ./bin/www",
"stage-mac": "NODE_ENV=staging nodemon --max-old-space-size=1024 ./bin/www",
"dev-pc": "SET NODE_ENV=development&&nodemon --max-old-space-size=1024 ./bin/www",
"prod-pc": "SET NODE_ENV=production&&nodemon --max-old-space-size=1024 ./bin/www",
"stage-pc": "SET NODE_ENV=staging&&nodemon --max-old-space-size=1024 ./bin/www",
"prettier": "prettier --single-quote --print-width 80 --trailing-comma all --write 'src/**/*.js'",
"test": "mocha ./**/test/ut_*.js --exit"
},
"_moduleAliases": {
"@root": ".",
"@models": "models/",
"@utils": "utils",
"@controllers": "controllers",
"@config": "config",
"@middleware": "middleware",
"@scripts": "scripts",
"@routes": "routes"
},
"dependencies": {
"@google-cloud/bigquery": "^5.5.0",
"@google-cloud/iot": "^1.5.0",
"@googlemaps/google-maps-services-js": "^3.1.16",
"@kafkajs/confluent-schema-registry": "^3.0.1",
"@log4js-node/slack": "^1.0.0",
"adm-zip": "^0.5.10",
"app-module-path": "^2.2.0",
"avsc": "^5.4.16",
"axios": "^0.21.4",
"body-parser": "^1.18.3",
"clean-deep": "^3.4.0",
"cloudinary": "^1.23.0",
"compression": "^1.7.4",
"connect-mongo": "^3.2.0",
"cookie-parser": "~1.4.3",
"crypto-js": "^4.1.1",
"debug": "~2.6.9",
"decimal-places": "0.0.2",
"dot-object": "^2.1.4",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-cluster": "0.0.5",
"express-session": "^1.17.1",
"express-validation": "^1.0.3",
"express-validator": "^6.12.0",
"generate-password": "^1.7.0",
"geolib": "^3.3.3",
"google-libphonenumber": "^3.2.22",
"helmet": "^3.21.1",
"http-status": "^1.4.0",
"install": "^0.13.0",
"is-empty": "^1.2.0",
"jade": "~1.11.0",
"joi": "^14.3.1",
"json2csv": "^5.0.7",
"jsonrepair": "^3.0.2",
"jsonwebtoken": "^8.5.1",
"kafka-node": "^5.0.0",
"kafkajs": "^1.16.0",
"log4js": "^6.3.0",
"module-alias": "^2.2.2",
"moesif-nodejs": "^3.2.2",
"mongoose": "^5.13.5",
"mongoose-unique-validator": "^2.0.3",
"morgan": "^1.9.1",
"mqtt": "^3.0.0",
"multer": "^1.4.2",
"ngeohash": "^0.6.3",
"node-fetch": "^2.6.1",
"node-json-transform": "^1.1.2",
"nodemon": "^1.19.4",
"npm": "^7.20.5",
"numeral": "^2.0.6",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"point-in-polygon": "^1.1.0",
"qrcode": "^1.4.4",
"qs": "^6.9.4",
"redis": "^3.1.2",
"request": "^2.88.2",
"retry-request": "^4.1.1",
"serve-favicon": "~2.4.5",
"shapefile": "^0.6.6",
"underscore": "^1.13.1",
"unique-names-generator": "^4.3.0",
"uuid": "^3.3.3"
},
"devDependencies": {
"acorn": "^6.4.2",
"chai": "^4.3.3",
"chai-http": "^4.3.0",
"eslint": "^7.18.0",
"eslint-config-prettier": "^6.4.0",
"eslint-plugin-prettier": "^3.1.1",
"faker": "^5.5.3",
"gulp": "^4.0.2",
"gulp-mocha": "^8.0.0",
"gulp-util": "^3.0.8",
"mocha": "^8.1.3",
"prettier": "1.18.2",
"sinon": "^9.2.4",
"supertest": "^4.0.2"
}
}
"name": "device-registry",
"version": "0.0.0",
"private": true,
"main": "./bin/www",
"scripts": {
"start": "NODE_ENV=production node --max-old-space-size=1024 ./bin/www",
"stage": "NODE_ENV=staging node --max-old-space-size=1024 ./bin/www",
"dev-mac": "NODE_ENV=development nodemon --max-old-space-size=1024 ./bin/www",
"prod-mac": "NODE_ENV=production nodemon --max-old-space-size=1024 ./bin/www",
"stage-mac": "NODE_ENV=staging nodemon --max-old-space-size=1024 ./bin/www",
"dev-pc": "SET NODE_ENV=development&&nodemon --max-old-space-size=1024 ./bin/www",
"prod-pc": "SET NODE_ENV=production&&nodemon --max-old-space-size=1024 ./bin/www",
"stage-pc": "SET NODE_ENV=staging&&nodemon --max-old-space-size=1024 ./bin/www",
"prettier": "prettier --single-quote --print-width 80 --trailing-comma all --write 'src/**/*.js'",
"test": "mocha ./**/test/ut_*.js --exit",
"test-models": "mocha ./models/test/ut_site.js --exit",
"test-controllers": "mocha ./controllers/test/ut_create-site.js --exit",
"test-utils": "mocha ./utils/test/ut_$FILE --exit",
"test-utils-all": "mocha ./utils/test/ut_*.js --exit",
"test-utils-sep": "node ./utils/test/generate-tests.js | xargs -0 -I {} sh -c {}"
},
"_moduleAliases": {
"@root": ".",
"@models": "models/",
"@utils": "utils",
"@controllers": "controllers",
"@config": "config",
"@middleware": "middleware",
"@scripts": "scripts",
"@routes": "routes"
},
"dependencies": {
"@google-cloud/bigquery": "^5.5.0",
"@google-cloud/iot": "^1.5.0",
"@googlemaps/google-maps-services-js": "^3.1.16",
"@kafkajs/confluent-schema-registry": "^3.0.1",
"@log4js-node/slack": "^1.0.0",
"adm-zip": "^0.5.10",
"app-module-path": "^2.2.0",
"avsc": "^5.4.16",
"axios": "^0.21.4",
"body-parser": "^1.18.3",
"clean-deep": "^3.4.0",
"cloudinary": "^1.23.0",
"compression": "^1.7.4",
"connect-mongo": "^3.2.0",
"cookie-parser": "~1.4.3",
"crypto-js": "^4.1.1",
"debug": "~2.6.9",
"decimal-places": "0.0.2",
"dot-object": "^2.1.4",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-cluster": "0.0.5",
"express-session": "^1.17.1",
"express-validation": "^1.0.3",
"express-validator": "^6.12.0",
"generate-password": "^1.7.0",
"geolib": "^3.3.3",
"google-libphonenumber": "^3.2.22",
"helmet": "^3.21.1",
"http-status": "^1.4.0",
"install": "^0.13.0",
"is-empty": "^1.2.0",
"jade": "~1.11.0",
"joi": "^14.3.1",
"json2csv": "^5.0.7",
"jsonrepair": "^3.0.2",
"jsonwebtoken": "^8.5.1",
"kafka-node": "^5.0.0",
"kafkajs": "^1.16.0",
"log4js": "^6.3.0",
"module-alias": "^2.2.2",
"moesif-nodejs": "^3.2.2",
"mongoose": "^5.13.5",
"mongoose-unique-validator": "^2.0.3",
"morgan": "^1.9.1",
"mqtt": "^3.0.0",
"multer": "^1.4.2",
"ngeohash": "^0.6.3",
"node-fetch": "^2.6.1",
"node-json-transform": "^1.1.2",
"nodemon": "^1.19.4",
"npm": "^7.20.5",
"numeral": "^2.0.6",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"point-in-polygon": "^1.1.0",
"qrcode": "^1.4.4",
"qs": "^6.9.4",
"redis": "^3.1.2",
"request": "^2.88.2",
"retry-request": "^4.1.1",
"serve-favicon": "~2.4.5",
"shapefile": "^0.6.6",
"underscore": "^1.13.1",
"unique-names-generator": "^4.3.0",
"uuid": "^3.3.3"
},
"devDependencies": {
"acorn": "^6.4.2",
"chai": "^4.3.3",
"chai-http": "^4.3.0",
"eslint": "^7.18.0",
"eslint-config-prettier": "^6.4.0",
"eslint-plugin-prettier": "^3.1.1",
"faker": "^5.5.3",
"gulp": "^4.0.2",
"gulp-mocha": "^8.0.0",
"gulp-util": "^3.0.8",
"mocha": "^8.1.3",
"prettier": "1.18.2",
"sinon": "^9.2.4",
"supertest": "^4.0.2"
}
}
Loading