diff --git a/backend/__tests__/dal/new-quotes.spec.ts b/backend/__tests__/dal/new-quotes.spec.ts new file mode 100644 index 000000000000..2338a79093d7 --- /dev/null +++ b/backend/__tests__/dal/new-quotes.spec.ts @@ -0,0 +1,39 @@ +import { describe, it, expect, vi } from "vitest"; +import { ObjectId } from "mongodb"; +import * as NewQuotesDal from "../../src/dal/new-quotes"; + +vi.mock("simple-git", () => ({ + simpleGit: () => { + throw new Error("no repo"); + }, +})); + +describe("NewQuotesDal", () => { + describe("without git", () => { + it("add fails", async () => { + await expect( + NewQuotesDal.add("text", "source", "english", "uid"), + ).rejects.toThrow("Git not available."); + }); + it("get fails", async () => { + await expect(NewQuotesDal.get("all")).rejects.toThrow( + "Git not available.", + ); + }); + it("approve fails", async () => { + await expect( + NewQuotesDal.approve( + new ObjectId().toHexString(), + undefined, + undefined, + "name", + ), + ).rejects.toThrow("Git not available."); + }); + it("refuse fails", async () => { + await expect( + NewQuotesDal.refuse(new ObjectId().toHexString()), + ).rejects.toThrow("Git not available."); + }); + }); +}); diff --git a/backend/src/dal/new-quotes.ts b/backend/src/dal/new-quotes.ts index 60c423836aa3..25b2a6de7e18 100644 --- a/backend/src/dal/new-quotes.ts +++ b/backend/src/dal/new-quotes.ts @@ -56,7 +56,7 @@ export async function add( language: string, uid: string, ): Promise { - if (git === undefined) throw new MonkeyError(500, "Git not available."); + if (git === null) throw new MonkeyError(500, "Git not available."); const quote = { _id: new ObjectId(), text: text, @@ -114,7 +114,7 @@ export async function add( } export async function get(language: Language | "all"): Promise { - if (git === undefined) throw new MonkeyError(500, "Git not available."); + if (git === null) throw new MonkeyError(500, "Git not available."); const where: { approved: boolean; language?: Language; @@ -232,6 +232,6 @@ export async function approve( } export async function refuse(quoteId: string): Promise { - if (git === undefined) throw new MonkeyError(500, "Git not available."); + if (git === null) throw new MonkeyError(500, "Git not available."); await getNewQuoteCollection().deleteOne({ _id: new ObjectId(quoteId) }); }