Added fake DB for monitor route testing
This commit is contained in:
1 parent
def8ba4b9d
commit
2e2d91937e
5 files changed
+100
-7
No files matched your search
@@ -0,0 +1,46 @@
|
||||
const Monitor = require("../models/Monitor");
|
||||
|
||||
const FAKE_MONITOR_DATA = [];
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
FAKE_MONITOR_DATA.push(
|
||||
new Monitor({
|
||||
userId: i % 2 === 0 ? 1 : 2,
|
||||
name: `Monitor ${i}`,
|
||||
description: `Description for Monitor ${i}`,
|
||||
url: `https://monitor${i}.com`,
|
||||
isActive: true,
|
||||
interval: 60000,
|
||||
updated_at: new Date(),
|
||||
created_at: new Date(),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
const getAllMonitors = async () => {
|
||||
return FAKE_MONITOR_DATA;
|
||||
};
|
||||
|
||||
const getMonitorById = async (monitorId) => {
|
||||
const idx = FAKE_MONITOR_DATA.findIndex((monitor) => {
|
||||
return monitor.id === monitorId;
|
||||
});
|
||||
if (idx === -1) {
|
||||
throw new Error(`Monitor with id ${monitorId} not found`);
|
||||
}
|
||||
return FAKE_MONITOR_DATA[idx];
|
||||
};
|
||||
|
||||
const getMonitorsByUserId = async (userId) => {
|
||||
const userMonitors = FAKE_MONITOR_DATA.filter((monitor) => {
|
||||
return monitor.userId === userId;
|
||||
});
|
||||
|
||||
if (userMonitors.length === 0) {
|
||||
throw new Error(`Monitors for user ${userId} not found`);
|
||||
}
|
||||
|
||||
return userMonitors;
|
||||
};
|
||||
|
||||
module.exports = { getAllMonitors, getMonitorById, getMonitorsByUserId };
|
||||
Reference in new issue
Block a user