diff --git a/src/application/environment/environmentStateWriteAnswer.test.ts b/src/application/environment/environmentStateWriteAnswer.test.ts index c8bfb5f9cbf..5b5f340612d 100644 --- a/src/application/environment/environmentStateWriteAnswer.test.ts +++ b/src/application/environment/environmentStateWriteAnswer.test.ts @@ -1791,14 +1791,18 @@ describe("served catalog of calls that only read", () => { }); }); +const linkedCreateNotes = (project?: string) => { + const fields = project === undefined ? {} : { project }; + return [ + { id: 1001, title: "Alpha", ...fields }, + { id: 1002, title: "Beta", ...fields }, + { id: 1003, title: "Gamma", ...fields }, + ] as const; +}; + describe("creates read under another path", () => { it("creates into the collection a linked create's returned id was read under", () => { - const note = (id: number, title: string) => ({ id, title }); - const [alpha, beta, gamma] = [ - note(1001, "Alpha"), - note(1002, "Beta"), - note(1003, "Gamma"), - ]; + const [alpha, beta, gamma] = linkedCreateNotes(); const notes = servedFrom([ ["GET", "/api/notes", [alpha, beta]], ["GET", "/api/notes/1001", alpha], @@ -1811,18 +1815,13 @@ describe("creates read under another path", () => { notes.answer("post_drafts_publish", { body: { title: "Delta" } }), ).toMatchObject({ status: 201 }); // The capture's own create is not in the initial state, so the served one takes the next id. - const delta = note(1003, "Delta"); + const delta = { id: 1003, title: "Delta" }; expect(notes.answer("get_notes_by_id", { id: "1003" }).body).toEqual(delta); expect(notes.answer("get_notes").body).toEqual([alpha, beta, delta]); }); it("refuses a linked create called with other path arguments than its recording sent", () => { - const note = (id: number, title: string) => ({ id, title }); - const [alpha, beta, gamma] = [ - note(1001, "Alpha"), - note(1002, "Beta"), - note(1003, "Gamma"), - ]; + const [alpha, beta, gamma] = linkedCreateNotes(); const notes = servedFrom([ ["GET", "/api/projects/11/notes", [alpha, beta]], ["GET", "/api/projects/11/notes/1001", alpha], @@ -1862,12 +1861,7 @@ describe("creates read under another path", () => { describe("path values of creates read under another path", () => { it("refuses a linked create that changes one of two path values its template names alike", () => { - const note = (id: number, title: string) => ({ id, title }); - const [alpha, beta, gamma] = [ - note(1001, "Alpha"), - note(1002, "Beta"), - note(1003, "Gamma"), - ]; + const [alpha, beta, gamma] = linkedCreateNotes(); const group = "/api/projects/11/groups/5"; const notes = servedFrom([ ["GET", `${group}/notes`, [alpha, beta]], @@ -1900,16 +1894,7 @@ describe("path values of creates read under another path", () => { }); it("creates in the recorded linked collection for escaped and plain path values", () => { - const note = (id: number, title: string) => ({ - id, - title, - project: "my org1", - }); - const [alpha, beta, gamma] = [ - note(1001, "Alpha"), - note(1002, "Beta"), - note(1003, "Gamma"), - ]; + const [alpha, beta, gamma] = linkedCreateNotes("my org1"); const other = { id: 2001, title: "Other", project: "my org2" }; const project = "/api/projects/my%20org1"; // A second project makes the project segment a path parameter. @@ -1945,14 +1930,9 @@ describe("path values of creates read under another path", () => { }); it("counts a linked create's call from a source that names the exemplar's only after decoding twice as another source's", () => { - const note = (id: number, title: string) => ({ id, title }); - const [alpha, beta, gamma, delta] = [ - note(1001, "Alpha"), - note(1002, "Beta"), - note(1003, "Gamma"), - note(1004, "Delta"), - ]; - const other = note(2001, "Other"); + const [alpha, beta, gamma] = linkedCreateNotes(); + const delta = { id: 1004, title: "Delta" }; + const other = { id: 2001, title: "Other" }; const project = "/api/projects/team1"; // A second project makes the project segment a path parameter. const notes = servedFrom([ @@ -2156,16 +2136,7 @@ describe("served values an application stamps", () => { describe("path fields of creates read under another path", () => { it("fills a linked create's path field from its exemplar decoded once, whichever accepted spelling the call uses", () => { - const note = (id: number, title: string) => ({ - id, - title, - project: "team%31", - }); - const [alpha, beta, gamma] = [ - note(1001, "Alpha"), - note(1002, "Beta"), - note(1003, "Gamma"), - ]; + const [alpha, beta, gamma] = linkedCreateNotes("team%31"); const other = { id: 2001, title: "Other", project: "team2" }; // The recorded segment `team%2531` names the project `team%31`. const project = "/api/projects/team%2531";