@justair/justair-library 3.4.1 → 3.4.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.
@@ -1,54 +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
- });
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
+ });
@@ -1,28 +1,28 @@
1
- import mongoose, { Schema } from "mongoose";
2
-
3
- const requestSchema = new Schema(
4
- {
5
- endpoint: String,
6
- count: Number,
7
- },
8
- { timestamps: true }
9
- );
10
-
11
- const usageMetricsSchema = mongoose.Schema(
12
- {
13
- apiKeyId: { type: mongoose.Schema.Types.ObjectId, ref: "ApiKey" },
14
- endpoint: String,
15
- response: {
16
- sizeInMB: Number,
17
- sizeInKB: Number,
18
- }
19
-
20
- },
21
- { timestamps: true }
22
- );
23
-
24
- const UsageMetrics = mongoose.model("UsageMetrics", usageMetricsSchema);
25
-
26
- export { usageMetricsSchema, UsageMetrics };
27
-
28
-
1
+ import mongoose, { Schema } from "mongoose";
2
+
3
+ const requestSchema = new Schema(
4
+ {
5
+ endpoint: String,
6
+ count: Number,
7
+ },
8
+ { timestamps: true }
9
+ );
10
+
11
+ const usageMetricsSchema = mongoose.Schema(
12
+ {
13
+ apiKeyId: { type: mongoose.Schema.Types.ObjectId, ref: "ApiKey" },
14
+ endpoint: String,
15
+ response: {
16
+ sizeInMB: Number,
17
+ sizeInKB: Number,
18
+ }
19
+
20
+ },
21
+ { timestamps: true }
22
+ );
23
+
24
+ const UsageMetrics = mongoose.model("UsageMetrics", usageMetricsSchema);
25
+
26
+ export { usageMetricsSchema, UsageMetrics };
27
+
28
+
@@ -1,31 +1,31 @@
1
- import mongoose from 'mongoose';
2
-
3
- const usersSchema = mongoose.Schema({
4
- name: String,
5
- phone: String,
6
- email: String,
7
- zipCode: String,
8
- location: [Object],
9
- organizations: [{ type: mongoose.Types.ObjectId, ref: 'Organizations' }],
10
- alertPhone: String,
11
- alertCount: { type: Number, default: 0 },
12
- subscribedMonitors: [{ type: mongoose.Types.ObjectId, ref: 'Monitors' }],
13
- currentAlertMode: { type: String, enum: ['Good', 'Unhealthy','Moderate', 'Unhealthy for SG', 'Very Unhealthy', 'Hazardous'], default: 'Good' },
14
- latestAlerts: [Object],
15
- optInPhone: { type: Boolean, default: true },
16
- optInEmail: { type: Boolean, default: true },
17
- isActive: { type: Boolean, default: true },
18
- hasOnboarded: {type: Boolean, default: false},
19
- isSharingLocation: {type: Boolean, default: false},
20
- toolTips: Object,
21
- alertPreferenceLevel: { type: String, enum: ['Good', 'Moderate', 'Unhealthy for SG', 'Unhealthy', 'Very Unhealthy', 'Hazardous'], default: 'Good' }
22
- },
23
- {
24
- timestamps: true
25
- });
26
-
27
- usersSchema.index({phone: 1});
28
-
29
- const Users = mongoose.model('Users', usersSchema);
30
-
1
+ import mongoose from 'mongoose';
2
+
3
+ const usersSchema = mongoose.Schema({
4
+ name: String,
5
+ phone: String,
6
+ email: String,
7
+ zipCode: String,
8
+ location: [Object],
9
+ organizations: [{ type: mongoose.Types.ObjectId, ref: 'Organizations' }],
10
+ alertPhone: String,
11
+ alertCount: { type: Number, default: 0 },
12
+ subscribedMonitors: [{ type: mongoose.Types.ObjectId, ref: 'Monitors' }],
13
+ currentAlertMode: { type: String, enum: ['Good', 'Unhealthy','Moderate', 'Unhealthy for SG', 'Very Unhealthy', 'Hazardous'], default: 'Good' },
14
+ latestAlerts: [Object],
15
+ optInPhone: { type: Boolean, default: true },
16
+ optInEmail: { type: Boolean, default: true },
17
+ isActive: { type: Boolean, default: true },
18
+ hasOnboarded: {type: Boolean, default: false},
19
+ isSharingLocation: {type: Boolean, default: false},
20
+ toolTips: Object,
21
+ alertPreferenceLevel: { type: String, enum: ['Good', 'Moderate', 'Unhealthy for SG', 'Unhealthy', 'Very Unhealthy', 'Hazardous'], default: 'Good' }
22
+ },
23
+ {
24
+ timestamps: true
25
+ });
26
+
27
+ usersSchema.index({phone: 1});
28
+
29
+ const Users = mongoose.model('Users', usersSchema);
30
+
31
31
  export {usersSchema, Users};
package/tsconfig.json CHANGED
@@ -1,11 +1,11 @@
1
- {
2
- "include": ["src/**/*"],
3
- "compilerOptions": {
4
- "allowJs": true,
5
- // Generate d.ts files
6
- "declaration": true,
7
- "emitDeclarationOnly": true,
8
- "outDir": "dist",
9
- "declarationMap": true
10
- }
1
+ {
2
+ "include": ["src/**/*"],
3
+ "compilerOptions": {
4
+ "allowJs": true,
5
+ // Generate d.ts files
6
+ "declaration": true,
7
+ "emitDeclarationOnly": true,
8
+ "outDir": "dist",
9
+ "declarationMap": true
10
+ }
11
11
  }