import { createMuniIssue } from "../muniIssues.setters"; import { generateMuniIssueId, getMuniIssueById, getMuniIssueByJiraKey, } from "../muniIssues.getters"; import { createMuniIssueInput } from "../../../test-utils/factories"; describe("muniIssues setters", () => { describe("createMuniIssue", () => { it("should insert a well-formed document with createdAt and nested content/jira", async () => { const input = createMuniIssueInput(); const id = generateMuniIssueId(); const insertedId = await createMuniIssue(input, id); const saved = await getMuniIssueById(insertedId.toString()); expect(saved).toMatchObject({ callSid: input.callSid, clientId: input.clientId, cityName: input.cityName, issueContent: input.issueContent, jira: input.jira, }); expect(saved?.createdAt).toBeInstanceOf(Date); }); it("should default jira.syncStatus to created when not provided", async () => { const id = generateMuniIssueId(); const insertedId = await createMuniIssue( createMuniIssueInput({ jira: { key: "CP-9" } }), id, ); const saved = await getMuniIssueById(insertedId.toString()); expect(saved?.jira.syncStatus).toBe("created"); }); it("should store long issueDescription and desiredBehavior in full", async () => { const issueDescription = "a".repeat(2000); const desiredBehavior = "b".repeat(2000); const id = generateMuniIssueId(); const insertedId = await createMuniIssue( createMuniIssueInput({ issueContent: { issuerName: "Dana", issuerRole: "Agent", issueDescription, desiredBehavior, }, }), id, ); const saved = await getMuniIssueById(insertedId.toString()); expect(saved?.issueContent.issueDescription).toHaveLength(2000); expect(saved?.issueContent.desiredBehavior).toBe(desiredBehavior); }); it("should persist the caller-supplied _id so the Jira ticket can link back", async () => { const id = generateMuniIssueId(); const insertedId = await createMuniIssue(createMuniIssueInput(), id); expect(insertedId.toString()).toBe(id.toString()); expect(await getMuniIssueById(id.toString())).not.toBeNull(); }); }); describe("getMuniIssueById", () => { it("should return null for an unknown or malformed id instead of throwing", async () => { expect( await getMuniIssueById(generateMuniIssueId().toString()), ).toBeNull(); expect(await getMuniIssueById("not-a-valid-id")).toBeNull(); }); }); describe("getMuniIssueByJiraKey", () => { it("should find the issue with the given Jira key", async () => { await createMuniIssue( createMuniIssueInput({ jira: { key: "CP-555" } }), generateMuniIssueId(), ); const found = await getMuniIssueByJiraKey("CP-555"); expect(found?.jira.key).toBe("CP-555"); expect(await getMuniIssueByJiraKey("CP-nope")).toBeNull(); }); }); });