Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/__mocks__/nanoid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
nanoid: () => {
return "nanoid";
}
};
105 changes: 68 additions & 37 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"locutus": "^2",
"morgan": "~1.10.1",
"mysql2": "^3.16",
"n3": "^1",
"nanoid": "^3.3.11",
"n3": "^2",
"nanoid": "^5.1.6",
"needle": "^3.1.0",
"node-tesseract-ocr": "^2",
"passport": "^0.7.0",
Expand Down
9 changes: 2 additions & 7 deletions api/src/services/Database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ jest.mock("knex", () => {
Knex: jest.fn(),
};
});
jest.mock("nanoid", () => {
return {
nanoid: jest.fn(() => "nanoid"),
};
});

describe("Database", () => {
beforeEach(() => {
Expand Down Expand Up @@ -53,7 +48,7 @@ describe("Database", () => {
throw new Error("no such table");
});
const token = await database.makeToken({ id: 1, username: "foo", password: "bar", hash: "xyzzy" });
expect(token).toEqual("nanoid");
expect(token).toEqual("nanoid"); // value comes from mock in __mocks__ directory
expect(userSpy).toHaveBeenCalledTimes(1);
expect(userSpy).toHaveBeenCalledWith("id", -1);
expect(schema.createTable).toHaveBeenCalledTimes(3);
Expand All @@ -65,7 +60,7 @@ describe("Database", () => {
const database = await Database.getInstance();
const userSpy = jest.spyOn(database, "getUserBy").mockResolvedValue(null);
const token = await database.makeToken({ id: 1, username: "foo", password: "bar", hash: "xyzzy" });
expect(token).toEqual("nanoid");
expect(token).toEqual("nanoid"); // value comes from mock in __mocks__ directory
expect(userSpy).toHaveBeenCalledTimes(1);
expect(userSpy).toHaveBeenCalledWith("id", -1);
expect(schema.createTable).toHaveBeenCalledTimes(0);
Expand Down