-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const mongoose = require('mongoose'); | ||
const DailyUsage = require('../DailyUsage'); | ||
|
||
describe('DailyUsage Model Test', () => { | ||
|
||
it('create & save daily usage successfully', async () => { | ||
const dailyUsageData = { | ||
userID: new mongoose.Types.ObjectId(), | ||
usedBandwidth: 0, | ||
totalBandwidth: 25000000 | ||
}; | ||
const validDailyUsage = new DailyUsage(dailyUsageData); | ||
const savedDailyUsage = await validDailyUsage.save(); | ||
|
||
|
||
expect(savedDailyUsage._id).toBeDefined(); | ||
expect(savedDailyUsage.userID).toBe(dailyUsageData.userID); | ||
expect(savedDailyUsage.usedBandwidth).toBe(dailyUsageData.usedBandwidth); | ||
expect(savedDailyUsage.totalBandwidth).toBe(dailyUsageData.totalBandwidth); | ||
}); | ||
|
||
|
||
}); | ||
|
||
|
||
const mongoose = require('mongoose'); | ||
const UsageRequest = require('../UsageRequest'); | ||
|
||
describe('UsageRequest Model Test', () => { | ||
|
||
it('create & save usage request successfully', async () => { | ||
const usageRequestData = { | ||
userID: new mongoose.Types.ObjectId(), | ||
usedBandwidth: 0, | ||
requestType: 'testType' | ||
}; | ||
const validUsageRequest = new UsageRequest(usageRequestData); | ||
const savedUsageRequest = await validUsageRequest.save(); | ||
|
||
// Object Id should be defined when successfully saved to MongoDB. | ||
expect(savedUsageRequest._id).toBeDefined(); | ||
expect(savedUsageRequest.userID).toBe(usageRequestData.userID); | ||
expect(savedUsageRequest.usedBandwidth).toBe(usageRequestData.usedBandwidth); | ||
expect(savedUsageRequest.requestType).toBe(usageRequestData.requestType); | ||
}); | ||
|
||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const mongoose = require('mongoose'); | ||
const User = require('../user'); // Import your User model | ||
|
||
describe('User Model Test', () => { | ||
|
||
|
||
it('create & save user successfully', async () => { | ||
const userData = { username: 'test', password: 'test', email: '[email protected]' }; | ||
const validUser = new User(userData); | ||
const savedUser = await validUser.save(); | ||
|
||
// Object Id should be defined when successfully saved to MongoDB. | ||
expect(savedUser._id).toBeDefined(); | ||
expect(savedUser.username).toBe(userData.username); | ||
expect(savedUser.password).toBe(userData.password); | ||
expect(savedUser.email).toBe(userData.email); | ||
}); | ||
|
||
// You should add more tests to validate your schema. | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const MongoMemoryServer = require('mongodb-memory-server').MongoMemoryServer; | ||
const mongoose = require('mongoose'); | ||
const app = require("../app").app; | ||
|
||
|
||
let mongoServer; | ||
beforeAll(async () => { | ||
mongoServer = new MongoMemoryServer(); | ||
await mongoServer.start(); | ||
const mongoUri = await mongoServer.getUri(); | ||
await mongoose.connect(mongoUri, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true | ||
}); | ||
}); | ||
|
||
|
||
beforeEach(async () => { | ||
const collections = await mongoose.connection.db.collections(); | ||
for (let collection of collections) { | ||
await collection.deleteMany({}); | ||
} | ||
}); | ||
|
||
afterAll(async () => { | ||
await mongoServer.stop(); | ||
await mongoose.connection.close(); | ||
}); |