@justair/justair-library 3.1.4 → 3.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README +9 -9
- package/dist/index.d.ts +15 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/models/admin.d.ts.map +1 -1
- package/dist/models/announcements.d.ts +3 -0
- package/dist/models/announcements.d.ts.map +1 -0
- package/dist/models/configurations.d.ts.map +1 -1
- package/dist/models/contexts.d.ts +3 -0
- package/dist/models/contexts.d.ts.map +1 -0
- package/dist/models/events.d.ts.map +1 -1
- package/dist/models/lightmonitors.d.ts +3 -0
- package/dist/models/lightmonitors.d.ts.map +1 -0
- package/dist/models/measurements.d.ts.map +1 -1
- package/dist/models/monitorSuppliers.d.ts +3 -0
- package/dist/models/monitorSuppliers.d.ts.map +1 -0
- package/dist/models/monitors.d.ts.map +1 -1
- package/dist/models/organizations.d.ts.map +1 -1
- package/dist/models/parameters.d.ts +3 -0
- package/dist/models/parameters.d.ts.map +1 -0
- package/dist/models/qanotifications.d.ts +3 -0
- package/dist/models/qanotifications.d.ts.map +1 -0
- package/dist/models/users.d.ts.map +1 -1
- package/package.json +28 -28
- package/src/config/db.js +21 -21
- package/src/config/logger.js +44 -44
- package/src/index.js +42 -40
- package/src/models/admin.js +22 -22
- package/src/models/announcements.js +14 -0
- package/src/models/configurations.js +17 -17
- package/src/models/contexts.js +13 -13
- package/src/models/events.js +20 -20
- package/src/models/lightmonitors.js +24 -24
- package/src/models/measurements.js +17 -17
- package/src/models/monitorRequests.js +15 -15
- package/src/models/monitorSuppliers.js +11 -11
- package/src/models/monitors.js +101 -101
- package/src/models/organizations.js +23 -23
- package/src/models/parameters.js +11 -11
- package/src/models/qanotifications.js +17 -17
- package/src/models/referenceMonitorInfo.js +18 -18
- package/src/models/tests/admin.test.js +42 -42
- package/src/models/tests/configurations.test.js +44 -44
- package/src/models/tests/measurements.test.js +46 -46
- package/src/models/tests/monitorRequests.test.js +46 -46
- package/src/models/tests/monitors.test.js +62 -62
- package/src/models/tests/organizations.test.js +51 -51
- package/src/models/tests/users.test.js +54 -54
- package/src/models/users.js +30 -30
- package/tsconfig.json +10 -10
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import mongoose from 'mongoose';
|
|
2
|
-
|
|
3
|
-
const measurementsSchema = mongoose.Schema({
|
|
4
|
-
monitorId: { type: mongoose.Types.ObjectId, ref: 'Monitors' },
|
|
5
|
-
orgId: { type: mongoose.Types.ObjectId, ref: 'Organizations' },
|
|
6
|
-
timeUpdated: Date,
|
|
7
|
-
measurements: Object,
|
|
8
|
-
monitorState: String
|
|
9
|
-
}, {
|
|
10
|
-
timestamps: true
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
measurementsSchema.index({monitorId: 1});
|
|
14
|
-
measurementsSchema.index({timeUpdated: 1});
|
|
15
|
-
|
|
16
|
-
const Measurements = mongoose.model('Measurements', measurementsSchema);
|
|
17
|
-
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
|
|
3
|
+
const measurementsSchema = mongoose.Schema({
|
|
4
|
+
monitorId: { type: mongoose.Types.ObjectId, ref: 'Monitors' },
|
|
5
|
+
orgId: { type: mongoose.Types.ObjectId, ref: 'Organizations' },
|
|
6
|
+
timeUpdated: Date,
|
|
7
|
+
measurements: Object,
|
|
8
|
+
monitorState: String
|
|
9
|
+
}, {
|
|
10
|
+
timestamps: true
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
measurementsSchema.index({monitorId: 1});
|
|
14
|
+
measurementsSchema.index({timeUpdated: 1});
|
|
15
|
+
|
|
16
|
+
const Measurements = mongoose.model('Measurements', measurementsSchema);
|
|
17
|
+
|
|
18
18
|
export {measurementsSchema, Measurements};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import mongoose from 'mongoose';
|
|
2
|
-
|
|
3
|
-
const monitorRequestsSchema = mongoose.Schema({
|
|
4
|
-
monitorOwnerOrg: { type: mongoose.Types.ObjectId, ref: 'Organizations' },
|
|
5
|
-
monitorOwnerOrgName: String,
|
|
6
|
-
monitorSharerOrg: { type: mongoose.Types.ObjectId, ref: 'Organizations' },
|
|
7
|
-
monitorSharerOrgName: String,
|
|
8
|
-
monitorList: [{ type: mongoose.Types.ObjectId, ref: 'Monitors' }],
|
|
9
|
-
status: { type: String, enum: ['Requested', 'Approved', 'Denied', 'Cancel', 'Deleted'] }
|
|
10
|
-
}, {
|
|
11
|
-
timestamps: true
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const MonitorRequests = mongoose.model('MonitorRequests', monitorRequestsSchema);
|
|
15
|
-
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
|
|
3
|
+
const monitorRequestsSchema = mongoose.Schema({
|
|
4
|
+
monitorOwnerOrg: { type: mongoose.Types.ObjectId, ref: 'Organizations' },
|
|
5
|
+
monitorOwnerOrgName: String,
|
|
6
|
+
monitorSharerOrg: { type: mongoose.Types.ObjectId, ref: 'Organizations' },
|
|
7
|
+
monitorSharerOrgName: String,
|
|
8
|
+
monitorList: [{ type: mongoose.Types.ObjectId, ref: 'Monitors' }],
|
|
9
|
+
status: { type: String, enum: ['Requested', 'Approved', 'Denied', 'Cancel', 'Deleted'] }
|
|
10
|
+
}, {
|
|
11
|
+
timestamps: true
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const MonitorRequests = mongoose.model('MonitorRequests', monitorRequestsSchema);
|
|
15
|
+
|
|
16
16
|
export {monitorRequestsSchema, MonitorRequests};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import mongoose from "mongoose";
|
|
2
|
-
|
|
3
|
-
const monitorSuppliersSchema = mongoose.Schema({
|
|
4
|
-
name : String
|
|
5
|
-
},
|
|
6
|
-
{
|
|
7
|
-
timestamps: true
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const MonitorSuppliers = mongoose.model("MonitorSuppliers", monitorSuppliersSchema);
|
|
11
|
-
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
|
|
3
|
+
const monitorSuppliersSchema = mongoose.Schema({
|
|
4
|
+
name : String
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
timestamps: true
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const MonitorSuppliers = mongoose.model("MonitorSuppliers", monitorSuppliersSchema);
|
|
11
|
+
|
|
12
12
|
export {monitorSuppliersSchema, MonitorSuppliers};
|
package/src/models/monitors.js
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import mongoose from "mongoose";
|
|
2
|
-
|
|
3
|
-
const monitorsSchema = mongoose.Schema(
|
|
4
|
-
{
|
|
5
|
-
monitorCode: String,
|
|
6
|
-
//keep up to date with diff manufacturers
|
|
7
|
-
monitorSupplier: {
|
|
8
|
-
type: String,
|
|
9
|
-
enum: [
|
|
10
|
-
"clarity",
|
|
11
|
-
"aeroqual",
|
|
12
|
-
"purple air",
|
|
13
|
-
"reference monitor",
|
|
14
|
-
"earthview",
|
|
15
|
-
"sensit",
|
|
16
|
-
"blue sky",
|
|
17
|
-
"aq mesh",
|
|
18
|
-
"quant aq"
|
|
19
|
-
],
|
|
20
|
-
},
|
|
21
|
-
monitorType: String,
|
|
22
|
-
monitorIdFromSupplier: String,
|
|
23
|
-
measurementUpdate: Date,
|
|
24
|
-
monitorProperties: Object,
|
|
25
|
-
isPrivate: { type: Boolean, default: false },
|
|
26
|
-
monitorState: {
|
|
27
|
-
type: String,
|
|
28
|
-
enum: ["Collocation", "Deployed", "Maintenance", "Pending Deployment"],
|
|
29
|
-
},
|
|
30
|
-
monitorStateHistory: [Object],
|
|
31
|
-
monitorAlertStatus: {
|
|
32
|
-
type: String,
|
|
33
|
-
enum: ["Good","Moderate", "Unhealthy for SG", "Unhealthy", "Very Unhealthy", "Hazardous", "Bad"],
|
|
34
|
-
default: "Good",
|
|
35
|
-
},
|
|
36
|
-
sponsor: { type: mongoose.Types.ObjectId, ref: "Organizations" },
|
|
37
|
-
sponsorName: String,
|
|
38
|
-
monitorLatitude: Number,
|
|
39
|
-
monitorLongitude: Number,
|
|
40
|
-
gpsLocation: {
|
|
41
|
-
type: { type: String, enul: ['Point'], required: true},
|
|
42
|
-
coordinates: { type: [Number], required: true },
|
|
43
|
-
},
|
|
44
|
-
location: Object, //copied over from associated org
|
|
45
|
-
context: [
|
|
46
|
-
{
|
|
47
|
-
type: String,
|
|
48
|
-
enum: [
|
|
49
|
-
"School",
|
|
50
|
-
"Highway",
|
|
51
|
-
"Factory",
|
|
52
|
-
"Residential",
|
|
53
|
-
"Urban",
|
|
54
|
-
"Rural",
|
|
55
|
-
"Industrial",
|
|
56
|
-
"Street",
|
|
57
|
-
"Park",
|
|
58
|
-
],
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
colocationDate: Date,
|
|
62
|
-
deploymentDate: Date,
|
|
63
|
-
subscriptionDate: Date,
|
|
64
|
-
parameters: [
|
|
65
|
-
{
|
|
66
|
-
type: String,
|
|
67
|
-
enum: [
|
|
68
|
-
"NO2",
|
|
69
|
-
"SO2",
|
|
70
|
-
"PM2.5",
|
|
71
|
-
"PM10",
|
|
72
|
-
"Temperature",
|
|
73
|
-
"Humidity",
|
|
74
|
-
"OZONE",
|
|
75
|
-
"VOC",
|
|
76
|
-
"CO",
|
|
77
|
-
"NO",
|
|
78
|
-
"PM1",
|
|
79
|
-
"WS And Direction"
|
|
80
|
-
],
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
latestPM2_5: Number,
|
|
84
|
-
latestAQI_PM2_5: Number,
|
|
85
|
-
notes: [Object],
|
|
86
|
-
calculatedAverages: [Object],
|
|
87
|
-
images: [String],
|
|
88
|
-
isActive: { type: Boolean, default: true },
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
timestamps: true,
|
|
92
|
-
}
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
monitorsSchema.index({gpsLocation: '2dsphere'});
|
|
96
|
-
monitorsSchema.index({monitorSupplier: 1});
|
|
97
|
-
monitorsSchema.index({monitorIdFromSupplier: 1});
|
|
98
|
-
monitorsSchema.index({monitorState: 1});
|
|
99
|
-
|
|
100
|
-
const Monitors = mongoose.model("Monitors", monitorsSchema);
|
|
101
|
-
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
|
|
3
|
+
const monitorsSchema = mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
monitorCode: String,
|
|
6
|
+
//keep up to date with diff manufacturers
|
|
7
|
+
monitorSupplier: {
|
|
8
|
+
type: String,
|
|
9
|
+
enum: [
|
|
10
|
+
"clarity",
|
|
11
|
+
"aeroqual",
|
|
12
|
+
"purple air",
|
|
13
|
+
"reference monitor",
|
|
14
|
+
"earthview",
|
|
15
|
+
"sensit",
|
|
16
|
+
"blue sky",
|
|
17
|
+
"aq mesh",
|
|
18
|
+
"quant aq"
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
monitorType: String,
|
|
22
|
+
monitorIdFromSupplier: String,
|
|
23
|
+
measurementUpdate: Date,
|
|
24
|
+
monitorProperties: Object,
|
|
25
|
+
isPrivate: { type: Boolean, default: false },
|
|
26
|
+
monitorState: {
|
|
27
|
+
type: String,
|
|
28
|
+
enum: ["Collocation", "Deployed", "Maintenance", "Pending Deployment"],
|
|
29
|
+
},
|
|
30
|
+
monitorStateHistory: [Object],
|
|
31
|
+
monitorAlertStatus: {
|
|
32
|
+
type: String,
|
|
33
|
+
enum: ["Good","Moderate", "Unhealthy for SG", "Unhealthy", "Very Unhealthy", "Hazardous", "Bad"],
|
|
34
|
+
default: "Good",
|
|
35
|
+
},
|
|
36
|
+
sponsor: { type: mongoose.Types.ObjectId, ref: "Organizations" },
|
|
37
|
+
sponsorName: String,
|
|
38
|
+
monitorLatitude: Number,
|
|
39
|
+
monitorLongitude: Number,
|
|
40
|
+
gpsLocation: {
|
|
41
|
+
type: { type: String, enul: ['Point'], required: true},
|
|
42
|
+
coordinates: { type: [Number], required: true },
|
|
43
|
+
},
|
|
44
|
+
location: Object, //copied over from associated org
|
|
45
|
+
context: [
|
|
46
|
+
{
|
|
47
|
+
type: String,
|
|
48
|
+
enum: [
|
|
49
|
+
"School",
|
|
50
|
+
"Highway",
|
|
51
|
+
"Factory",
|
|
52
|
+
"Residential",
|
|
53
|
+
"Urban",
|
|
54
|
+
"Rural",
|
|
55
|
+
"Industrial",
|
|
56
|
+
"Street",
|
|
57
|
+
"Park",
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
colocationDate: Date,
|
|
62
|
+
deploymentDate: Date,
|
|
63
|
+
subscriptionDate: Date,
|
|
64
|
+
parameters: [
|
|
65
|
+
{
|
|
66
|
+
type: String,
|
|
67
|
+
enum: [
|
|
68
|
+
"NO2",
|
|
69
|
+
"SO2",
|
|
70
|
+
"PM2.5",
|
|
71
|
+
"PM10",
|
|
72
|
+
"Temperature",
|
|
73
|
+
"Humidity",
|
|
74
|
+
"OZONE",
|
|
75
|
+
"VOC",
|
|
76
|
+
"CO",
|
|
77
|
+
"NO",
|
|
78
|
+
"PM1",
|
|
79
|
+
"WS And Direction"
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
latestPM2_5: Number,
|
|
84
|
+
latestAQI_PM2_5: Number,
|
|
85
|
+
notes: [Object],
|
|
86
|
+
calculatedAverages: [Object],
|
|
87
|
+
images: [String],
|
|
88
|
+
isActive: { type: Boolean, default: true },
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
timestamps: true,
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
monitorsSchema.index({gpsLocation: '2dsphere'});
|
|
96
|
+
monitorsSchema.index({monitorSupplier: 1});
|
|
97
|
+
monitorsSchema.index({monitorIdFromSupplier: 1});
|
|
98
|
+
monitorsSchema.index({monitorState: 1});
|
|
99
|
+
|
|
100
|
+
const Monitors = mongoose.model("Monitors", monitorsSchema);
|
|
101
|
+
|
|
102
102
|
export {monitorsSchema, Monitors};
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import mongoose from "mongoose";
|
|
2
|
-
|
|
3
|
-
const organizationsSchema = mongoose.Schema({
|
|
4
|
-
name: String,
|
|
5
|
-
website: String,
|
|
6
|
-
location: Object,
|
|
7
|
-
authorized: { type: Boolean, default: false },
|
|
8
|
-
orgAPIKey: [Object],
|
|
9
|
-
orgCode: String,
|
|
10
|
-
orgDescription: String,
|
|
11
|
-
orgLogo: String,
|
|
12
|
-
customAlertLevels: [Object],
|
|
13
|
-
connectedMonitors: [{ type: mongoose.Types.ObjectId, ref: 'Monitors' }],
|
|
14
|
-
communityMessages: [Object],
|
|
15
|
-
weeklyReportData: [Object],
|
|
16
|
-
isActive: { type: Boolean, default: true }
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
timestamps: true
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const Organizations = mongoose.model('Organizations', organizationsSchema);
|
|
23
|
-
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
|
|
3
|
+
const organizationsSchema = mongoose.Schema({
|
|
4
|
+
name: String,
|
|
5
|
+
website: String,
|
|
6
|
+
location: Object,
|
|
7
|
+
authorized: { type: Boolean, default: false },
|
|
8
|
+
orgAPIKey: [Object],
|
|
9
|
+
orgCode: String,
|
|
10
|
+
orgDescription: String,
|
|
11
|
+
orgLogo: String,
|
|
12
|
+
customAlertLevels: [Object],
|
|
13
|
+
connectedMonitors: [{ type: mongoose.Types.ObjectId, ref: 'Monitors' }],
|
|
14
|
+
communityMessages: [Object],
|
|
15
|
+
weeklyReportData: [Object],
|
|
16
|
+
isActive: { type: Boolean, default: true }
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
timestamps: true
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const Organizations = mongoose.model('Organizations', organizationsSchema);
|
|
23
|
+
|
|
24
24
|
export {organizationsSchema, Organizations};
|
package/src/models/parameters.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import mongoose from "mongoose";
|
|
2
|
-
|
|
3
|
-
const parametersSchema = mongoose.Schema({
|
|
4
|
-
name: String
|
|
5
|
-
},
|
|
6
|
-
{
|
|
7
|
-
timestamps: true
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const Parameters = mongoose.model("Parameters", parametersSchema);
|
|
11
|
-
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
|
|
3
|
+
const parametersSchema = mongoose.Schema({
|
|
4
|
+
name: String
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
timestamps: true
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const Parameters = mongoose.model("Parameters", parametersSchema);
|
|
11
|
+
|
|
12
12
|
export {parametersSchema, Parameters};
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import mongoose from 'mongoose';
|
|
2
|
-
|
|
3
|
-
const qaNotificationsSchema = mongoose.Schema({
|
|
4
|
-
monitorId: {type: mongoose.Types.ObjectId, ref: 'Monitors'},
|
|
5
|
-
issue: String,
|
|
6
|
-
reportedAt: Date,
|
|
7
|
-
reportedBy: String,
|
|
8
|
-
resolvedAt: Date,
|
|
9
|
-
resolvedBy: String,
|
|
10
|
-
status: {type: String, enum: ["Open", "Resolved"]}
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
timestamps: true
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const QANotifications = mongoose.model('QANotifications', qaNotificationsSchema);
|
|
17
|
-
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
|
|
3
|
+
const qaNotificationsSchema = mongoose.Schema({
|
|
4
|
+
monitorId: {type: mongoose.Types.ObjectId, ref: 'Monitors'},
|
|
5
|
+
issue: String,
|
|
6
|
+
reportedAt: Date,
|
|
7
|
+
reportedBy: String,
|
|
8
|
+
resolvedAt: Date,
|
|
9
|
+
resolvedBy: String,
|
|
10
|
+
status: {type: String, enum: ["Open", "Resolved"]}
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
timestamps: true
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const QANotifications = mongoose.model('QANotifications', qaNotificationsSchema);
|
|
17
|
+
|
|
18
18
|
export {qaNotificationsSchema, QANotifications};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import mongoose from 'mongoose';
|
|
2
|
-
|
|
3
|
-
const referenceMonitorInfoSchema = mongoose.Schema({
|
|
4
|
-
bboxStartLat: String,
|
|
5
|
-
bboxStartLong: String,
|
|
6
|
-
bboxEndLat: String,
|
|
7
|
-
bboxEndLong: String,
|
|
8
|
-
parameters: String,
|
|
9
|
-
sponsor: { type: mongoose.Types.ObjectId, ref: 'Organizations' },
|
|
10
|
-
location: Object,
|
|
11
|
-
isActive: { type: Boolean, default: true },
|
|
12
|
-
context: [String]
|
|
13
|
-
}, {
|
|
14
|
-
timestamps: true
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const ReferenceMonitorInfo = mongoose.model('ReferenceMonitorInfo', referenceMonitorInfoSchema);
|
|
18
|
-
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
|
|
3
|
+
const referenceMonitorInfoSchema = mongoose.Schema({
|
|
4
|
+
bboxStartLat: String,
|
|
5
|
+
bboxStartLong: String,
|
|
6
|
+
bboxEndLat: String,
|
|
7
|
+
bboxEndLong: String,
|
|
8
|
+
parameters: String,
|
|
9
|
+
sponsor: { type: mongoose.Types.ObjectId, ref: 'Organizations' },
|
|
10
|
+
location: Object,
|
|
11
|
+
isActive: { type: Boolean, default: true },
|
|
12
|
+
context: [String]
|
|
13
|
+
}, {
|
|
14
|
+
timestamps: true
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const ReferenceMonitorInfo = mongoose.model('ReferenceMonitorInfo', referenceMonitorInfoSchema);
|
|
18
|
+
|
|
19
19
|
export {referenceMonitorInfoSchema, ReferenceMonitorInfo};
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import mongoose from 'mongoose';
|
|
2
|
-
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
3
|
-
import Admin from '../admins.js'; // Assuming this file is in the same directory
|
|
4
|
-
|
|
5
|
-
let mongoServer;
|
|
6
|
-
|
|
7
|
-
// Before running the tests, start the mock MongoDB server
|
|
8
|
-
beforeAll(async () => {
|
|
9
|
-
mongoServer = await MongoMemoryServer.create();
|
|
10
|
-
const mongoUri = mongoServer.getUri();
|
|
11
|
-
mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
// After running the tests, stop the mock MongoDB server and close the Mongoose connection
|
|
15
|
-
afterAll(async () => {
|
|
16
|
-
await mongoose.disconnect();
|
|
17
|
-
await mongoServer.stop();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// Clear the database and reset the state before each test
|
|
21
|
-
beforeEach(async () => {
|
|
22
|
-
await mongoose.connection.dropDatabase();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
// Sample test case
|
|
26
|
-
test('Create admin and fetch it from the database', async () => {
|
|
27
|
-
const adminData = {
|
|
28
|
-
name: 'John Doe',
|
|
29
|
-
phone: '1234567890',
|
|
30
|
-
email: 'john@example.com',
|
|
31
|
-
password: 'password123',
|
|
32
|
-
orgId: mongoose.Types.ObjectId(), // Generate a new ObjectId for orgId
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// Create a new admin document
|
|
36
|
-
const createdAdmin = await Admin.create(adminData);
|
|
37
|
-
|
|
38
|
-
// Fetch the admin from the database
|
|
39
|
-
const fetchedAdmin = await Admin.findById(createdAdmin._id);
|
|
40
|
-
|
|
41
|
-
expect(fetchedAdmin).toMatchObject(adminData);
|
|
42
|
-
});
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
3
|
+
import Admin from '../admins.js'; // Assuming this file is in the same directory
|
|
4
|
+
|
|
5
|
+
let mongoServer;
|
|
6
|
+
|
|
7
|
+
// Before running the tests, start the mock MongoDB server
|
|
8
|
+
beforeAll(async () => {
|
|
9
|
+
mongoServer = await MongoMemoryServer.create();
|
|
10
|
+
const mongoUri = mongoServer.getUri();
|
|
11
|
+
mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// After running the tests, stop the mock MongoDB server and close the Mongoose connection
|
|
15
|
+
afterAll(async () => {
|
|
16
|
+
await mongoose.disconnect();
|
|
17
|
+
await mongoServer.stop();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Clear the database and reset the state before each test
|
|
21
|
+
beforeEach(async () => {
|
|
22
|
+
await mongoose.connection.dropDatabase();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Sample test case
|
|
26
|
+
test('Create admin and fetch it from the database', async () => {
|
|
27
|
+
const adminData = {
|
|
28
|
+
name: 'John Doe',
|
|
29
|
+
phone: '1234567890',
|
|
30
|
+
email: 'john@example.com',
|
|
31
|
+
password: 'password123',
|
|
32
|
+
orgId: mongoose.Types.ObjectId(), // Generate a new ObjectId for orgId
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Create a new admin document
|
|
36
|
+
const createdAdmin = await Admin.create(adminData);
|
|
37
|
+
|
|
38
|
+
// Fetch the admin from the database
|
|
39
|
+
const fetchedAdmin = await Admin.findById(createdAdmin._id);
|
|
40
|
+
|
|
41
|
+
expect(fetchedAdmin).toMatchObject(adminData);
|
|
42
|
+
});
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import mongoose from 'mongoose';
|
|
2
|
-
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
3
|
-
import Configurations from '../configurations.js'; // Assuming this file is in the same directory
|
|
4
|
-
|
|
5
|
-
let mongoServer;
|
|
6
|
-
|
|
7
|
-
// Before running the tests, start the mock MongoDB server
|
|
8
|
-
beforeAll(async () => {
|
|
9
|
-
mongoServer = await MongoMemoryServer.create();
|
|
10
|
-
const mongoUri = mongoServer.getUri();
|
|
11
|
-
mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
// After running the tests, stop the mock MongoDB server and close the Mongoose connection
|
|
15
|
-
afterAll(async () => {
|
|
16
|
-
await mongoose.disconnect();
|
|
17
|
-
await mongoServer.stop();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// Clear the database and reset the state before each test
|
|
21
|
-
beforeEach(async () => {
|
|
22
|
-
await mongoose.connection.dropDatabase();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
// Sample test case
|
|
26
|
-
test('Create configuration and fetch it from the database', async () => {
|
|
27
|
-
const configurationData = {
|
|
28
|
-
type: 'flag',
|
|
29
|
-
name: 'FeatureA',
|
|
30
|
-
properties: {
|
|
31
|
-
enabled: true,
|
|
32
|
-
percentage: 50,
|
|
33
|
-
},
|
|
34
|
-
isActive: true,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// Create a new configuration document
|
|
38
|
-
const createdConfiguration = await Configurations.create(configurationData);
|
|
39
|
-
|
|
40
|
-
// Fetch the configuration from the database
|
|
41
|
-
const fetchedConfiguration = await Configurations.findById(createdConfiguration._id);
|
|
42
|
-
|
|
43
|
-
expect(fetchedConfiguration).toMatchObject(configurationData);
|
|
44
|
-
});
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
3
|
+
import Configurations from '../configurations.js'; // Assuming this file is in the same directory
|
|
4
|
+
|
|
5
|
+
let mongoServer;
|
|
6
|
+
|
|
7
|
+
// Before running the tests, start the mock MongoDB server
|
|
8
|
+
beforeAll(async () => {
|
|
9
|
+
mongoServer = await MongoMemoryServer.create();
|
|
10
|
+
const mongoUri = mongoServer.getUri();
|
|
11
|
+
mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// After running the tests, stop the mock MongoDB server and close the Mongoose connection
|
|
15
|
+
afterAll(async () => {
|
|
16
|
+
await mongoose.disconnect();
|
|
17
|
+
await mongoServer.stop();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Clear the database and reset the state before each test
|
|
21
|
+
beforeEach(async () => {
|
|
22
|
+
await mongoose.connection.dropDatabase();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Sample test case
|
|
26
|
+
test('Create configuration and fetch it from the database', async () => {
|
|
27
|
+
const configurationData = {
|
|
28
|
+
type: 'flag',
|
|
29
|
+
name: 'FeatureA',
|
|
30
|
+
properties: {
|
|
31
|
+
enabled: true,
|
|
32
|
+
percentage: 50,
|
|
33
|
+
},
|
|
34
|
+
isActive: true,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Create a new configuration document
|
|
38
|
+
const createdConfiguration = await Configurations.create(configurationData);
|
|
39
|
+
|
|
40
|
+
// Fetch the configuration from the database
|
|
41
|
+
const fetchedConfiguration = await Configurations.findById(createdConfiguration._id);
|
|
42
|
+
|
|
43
|
+
expect(fetchedConfiguration).toMatchObject(configurationData);
|
|
44
|
+
});
|