Skip to content

Commit 7535179

Browse files
committed
Update unit tests
1 parent e575edd commit 7535179

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

build/src/src/calls/removeDevice.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { getUserList, removeClient } from "../openvpn";
22
import { MAIN_ADMIN_NAME } from "../params";
33

4+
export const REMOVE_MAIN_ADMIN_ERROR = "Cannot remove the main admin user";
5+
46
/**
57
* Removes the device with the provided id, if exists.
68
* @param id "new-device"
@@ -9,7 +11,7 @@ export async function removeDevice({ id }: { id: string }): Promise<void> {
911
const deviceArray = await getUserList();
1012

1113
if (id === MAIN_ADMIN_NAME) {
12-
throw Error("Cannot remove the main admin user");
14+
throw Error(REMOVE_MAIN_ADMIN_ERROR);
1315
}
1416

1517
if (!deviceArray.includes(id)) {

build/src/test/calls/listDevices.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ describe("Call function: listDevices", () => {
1212
{ cn: "tom", ip: "172.33.0.2" }
1313
];
1414
const userResult = [
15-
{ id: "dappnode_admin", admin: true, ip: "172.33.0.1" },
16-
{ id: "mobile", admin: false, ip: "" },
17-
{ id: "guest", admin: false, ip: "" },
18-
{ id: "tom", admin: true, ip: "172.33.0.2" }
15+
{ id: "dappnode_admin" },
16+
{ id: "mobile" },
17+
{ id: "guest" },
18+
{ id: "tom" }
1919
];
2020
// sinon.replace(,)); <--- to replace an inside function
2121
const getUserList = sinon.stub();

build/src/test/calls/removeDevice.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import "mocha";
22
import { expect } from "chai";
33
import sinon from "sinon";
44
import proxyquire from "proxyquire";
5+
import { REMOVE_MAIN_ADMIN_ERROR } from "../../src/calls/removeDevice";
56

67
describe("Call function: removeDevice", () => {
78
// This function calls getUserList and getCCD to build
@@ -46,6 +47,6 @@ describe("Call function: removeDevice", () => {
4647
} catch (e) {
4748
error = e.message;
4849
}
49-
expect(error).to.equal("You cannot remove an admin user");
50+
expect(error).to.equal(REMOVE_MAIN_ADMIN_ERROR);
5051
});
5152
});

0 commit comments

Comments
 (0)