@justair/justair-library 1.0.1 → 1.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justair/justair-library",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "JustAir Internal Library",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -0,0 +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
+ });
@@ -0,0 +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
+ });
@@ -0,0 +1,46 @@
1
+ import mongoose from 'mongoose';
2
+ import { MongoMemoryServer } from 'mongodb-memory-server';
3
+ import Measurements from '../measurements.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 measurement and fetch it from the database', async () => {
27
+ const measurementData = {
28
+ monitorId: mongoose.Types.ObjectId(), // Generate a new ObjectId for monitorId
29
+ orgId: mongoose.Types.ObjectId(), // Generate a new ObjectId for orgId
30
+ timeUpdated: new Date(),
31
+ measurements: {
32
+ temperature: 25,
33
+ humidity: 60,
34
+ },
35
+ alert: 'Good',
36
+ alertMessage: 'High temperature detected',
37
+ };
38
+
39
+ // Create a new measurement document
40
+ const createdMeasurement = await Measurements.create(measurementData);
41
+
42
+ // Fetch the measurement from the database
43
+ const fetchedMeasurement = await Measurements.findById(createdMeasurement._id);
44
+
45
+ expect(fetchedMeasurement).toMatchObject(measurementData);
46
+ });
@@ -0,0 +1,46 @@
1
+ import mongoose from 'mongoose';
2
+ import { MongoMemoryServer } from 'mongodb-memory-server';
3
+ import MonitorRequests from '../monitorRequests.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 monitor request and fetch it from the database', async () => {
27
+ const monitorRequestData = {
28
+ monitorOwnerOrg: mongoose.Types.ObjectId(), // Generate a new ObjectId for monitorOwnerOrg
29
+ monitorOwnerOrgName: 'Organization A',
30
+ monitorSharerOrg: mongoose.Types.ObjectId(), // Generate a new ObjectId for monitorSharerOrg
31
+ monitorSharerOrgName: 'Organization B',
32
+ monitorList: [
33
+ mongoose.Types.ObjectId(), // Generate a new ObjectId for each monitor in the list
34
+ mongoose.Types.ObjectId(),
35
+ ],
36
+ status: 'Requested',
37
+ };
38
+
39
+ // Create a new monitor request document
40
+ const createdMonitorRequest = await MonitorRequests.create(monitorRequestData);
41
+
42
+ // Fetch the monitor request from the database
43
+ const fetchedMonitorRequest = await MonitorRequests.findById(createdMonitorRequest._id);
44
+
45
+ expect(fetchedMonitorRequest).toMatchObject(monitorRequestData);
46
+ });
@@ -0,0 +1,62 @@
1
+ import { Decimal128 } from 'bson';
2
+ import mongoose from 'mongoose';
3
+ import { MongoMemoryServer } from 'mongodb-memory-server';
4
+ import Monitors from '../monitors.js'; // Assuming this file is in the same directory
5
+
6
+ let mongoServer;
7
+
8
+ // Before running the tests, start the mock MongoDB server
9
+ beforeAll(async () => {
10
+ mongoServer = await MongoMemoryServer.create();
11
+ const mongoUri = mongoServer.getUri();
12
+ mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
13
+ });
14
+
15
+ // After running the tests, stop the mock MongoDB server and close the Mongoose connection
16
+ afterAll(async () => {
17
+ await mongoose.disconnect();
18
+ await mongoServer.stop();
19
+ });
20
+
21
+ // Clear the database and reset the state before each test
22
+ beforeEach(async () => {
23
+ await mongoose.connection.dropDatabase();
24
+ });
25
+
26
+ // Sample test case
27
+ test('Create monitor and fetch it from the database', async () => {
28
+ const monitorData = {
29
+ monitorCode: 'ABC123',
30
+ monitorSupplier: 'clarity',
31
+ monitorIdFromSupplier: '123456',
32
+ measurementUpdate: new Date(),
33
+ monitorProperties: {
34
+ property1: 'value1',
35
+ property2: 'value2',
36
+ },
37
+ isPrivate: false,
38
+ monitorState: 'Collocation',
39
+ sponsor: mongoose.Types.ObjectId(), // Generate a new ObjectId for sponsor
40
+ sponsorName: 'Organization A',
41
+ monitorLatitude: 37.7749,
42
+ monitorLongitude: -122.4194,
43
+ location: {
44
+ city: 'San Francisco',
45
+ country: 'United States',
46
+ },
47
+ context: ['School'],
48
+ colocationDate: new Date(),
49
+ parameters: ['NO2', 'PM2.5', 'Temperature'],
50
+ latestPM2_5: Decimal128.fromString('10.5'), // Use Decimal128 for decimal values
51
+ latestAQI_PM2_5: 75,
52
+ isActive: true,
53
+ };
54
+
55
+ // Create a new monitor document
56
+ const createdMonitor = await Monitors.create(monitorData);
57
+
58
+ // Fetch the monitor from the database
59
+ const fetchedMonitor = await Monitors.findById(createdMonitor._id);
60
+
61
+ expect(fetchedMonitor).toMatchObject(monitorData);
62
+ });
@@ -0,0 +1,51 @@
1
+ import mongoose from 'mongoose';
2
+ import { MongoMemoryServer } from 'mongodb-memory-server';
3
+ import Organizations from '../organizations.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 organization and fetch it from the database', async () => {
27
+ const organizationData = {
28
+ name: 'Acme Corp',
29
+ website: 'https://www.example.com',
30
+ location: {
31
+ city: 'San Francisco',
32
+ country: 'United States',
33
+ },
34
+ authorized: false,
35
+ orgAPIKey: [{ key: 'ABC123' }],
36
+ orgCode: 'ACME123',
37
+ orgDescription: 'A sample organization',
38
+ orgLogo: 'https://www.example.com/logo.png',
39
+ connectedMonitors: [mongoose.Types.ObjectId()], // Generate a new ObjectId for each connected monitor
40
+ communityMessages: [{ message: 'Welcome to our community!' }],
41
+ isActive: true,
42
+ };
43
+
44
+ // Create a new organization document
45
+ const createdOrganization = await Organizations.create(organizationData);
46
+
47
+ // Fetch the organization from the database
48
+ const fetchedOrganization = await Organizations.findById(createdOrganization._id);
49
+
50
+ expect(fetchedOrganization).toMatchObject(organizationData);
51
+ });
@@ -0,0 +1,54 @@
1
+ import mongoose from 'mongoose';
2
+ import { MongoMemoryServer } from 'mongodb-memory-server';
3
+ import Users from '../users.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 user and fetch it from the database', async () => {
27
+ const userData = {
28
+ name: 'John Doe',
29
+ phone: '1234567890',
30
+ email: 'john.doe@example.com',
31
+ zipCode: '12345',
32
+ location: {
33
+ city: 'San Francisco',
34
+ country: 'United States',
35
+ },
36
+ organizations: [mongoose.Types.ObjectId()], // Generate a new ObjectId for each organization
37
+ alertPhone: '9876543210',
38
+ alertCount: 0,
39
+ subscribedMonitors: [mongoose.Types.ObjectId()], // Generate a new ObjectId for each subscribed monitor
40
+ currentAlertMode: 'Good',
41
+ latestAlerts: [{ message: 'Alert 1' }],
42
+ optInPhone: true,
43
+ optInEmail: true,
44
+ isActive: true,
45
+ };
46
+
47
+ // Create a new user document
48
+ const createdUser = await Users.create(userData);
49
+
50
+ // Fetch the user from the database
51
+ const fetchedUser = await Users.findById(createdUser._id);
52
+
53
+ expect(fetchedUser).toMatchObject(userData);
54
+ });