-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathpaginateDeleted.test.js
More file actions
69 lines (61 loc) · 1.76 KB
/
paginateDeleted.test.js
File metadata and controls
69 lines (61 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const { paginateDeleted } = require("../../utils/paginateDeleted");
const softDelete = require("../../utils/softDelete");
const MsAdmin = require("../../models/msadmins");
describe("Paginete soft-deleted records", () => {
let msAdmin,
idsArray = [];
beforeAll(async () => {
//create dummy records and softDelete them
for (let index = 0; index < 20; index++) {
msAdmin = new MsAdmin({
fullname: "paginateDeleteTest",
email: `admin${Date.now()}@domain.com`,
password: "some password",
});
await msAdmin.save();
idsArray.push(msAdmin.id);
//soft delete
if ((index + 2) % 2 === 0) {
await softDelete.deleteById(MsAdmin, msAdmin.id, global.msAdmin.id);
}
}
});
afterAll(async () => {
for (let index = 0; index < idsArray.length; index++) {
const msAdminId = idsArray[index];
await softDelete.restoreById(MsAdmin, msAdminId);
await MsAdmin.findByIdAndDelete(msAdminId);
}
});
it("should get all deleted records", async () => {
const deletedAdmins = await paginateDeleted(
MsAdmin,
"disabled",
{ fullname: "paginateDeleteTest" },
5,
1
);
expect(deletedAdmins.totalRecords).toEqual(10);
});
it("should get all undeleted records", async () => {
const unDeleted = await paginateDeleted(
MsAdmin,
"enabled",
{ fullname: "paginateDeleteTest" },
5,
1
);
expect(unDeleted.totalRecords).toEqual(10);
});
it("should get all records", async () => {
const allAdmins = await paginateDeleted(
MsAdmin,
"all",
{ fullname: "paginateDeleteTest" },
5,
1
);
expect(allAdmins.totalRecords).toEqual(20);
});
//retrieve the deleted records by page
});