import { createWebsiteUrl, getWebsiteUrlsByClient, getWebsiteUrlById, getWebsiteUrlsCollection, updateWebsiteUrl, deleteWebsiteUrl, } from "../websiteUrls.getters"; import { createWebsiteUrlFixture } from "../../../test-utils/factories/websitalk/websiteUrls"; describe("db.websitalk.websiteUrls", () => { const clientId = "test-client"; describe("createWebsiteUrl", () => { it("should create a website URL configuration", async () => { const id = await createWebsiteUrl({ clientId, name: "Primary", baseUrl: "https://example.com", }); const saved = await getWebsiteUrlById(id.toString()); expect(saved).toMatchObject({ clientId, name: "Primary", baseUrl: "https://example.com", }); expect(saved?.createdAt).toBeInstanceOf(Date); expect(saved?.updatedAt).toBeInstanceOf(Date); }); }); describe("getWebsiteUrlsByClient", () => { it("should return all configurations for a client", async () => { await getWebsiteUrlsCollection().insertMany([ createWebsiteUrlFixture({ clientId, name: "A" }), createWebsiteUrlFixture({ clientId, name: "B" }), createWebsiteUrlFixture({ clientId: "other-client", name: "Other" }), ]); const results = await getWebsiteUrlsByClient(clientId); expect(results).toHaveLength(2); expect(results.map((doc) => doc.name)).toEqual(["A", "B"]); }); }); describe("updateWebsiteUrl", () => { it("should update name and baseUrl", async () => { const id = await createWebsiteUrl({ clientId, name: "Old", baseUrl: "https://old.example", }); const updated = await updateWebsiteUrl(id.toString(), { name: "New", baseUrl: "https://new.example", }); expect(updated?.name).toBe("New"); expect(updated?.baseUrl).toBe("https://new.example"); }); }); describe("deleteWebsiteUrl", () => { it("should delete the website and return true", async () => { const id = await createWebsiteUrl({ clientId: "delete-client", name: "Gone", baseUrl: "https://gone.example", }); expect(await deleteWebsiteUrl(id.toString())).toBe(true); expect(await getWebsiteUrlById(id.toString())).toBeNull(); }); }); });