From c8125eaaffd74e21e1ff1693d3373551b4c06231 Mon Sep 17 00:00:00 2001 From: Will Ruggiano Date: Tue, 3 Dec 2024 16:53:07 -0800 Subject: [PATCH] fix: copyFrom Reviewers: jmurphy4 Pull Request: https://github.com/tendrelhq/graphql/pull/84 --- .../__snapshots__/copyFrom.test.ts.snap | 26 ++++++++++++++++++- .../resolvers/Mutation/copyFrom.test.ts | 26 +++++++++++++++---- .../resolvers/Mutation/copyFrom.ts | 2 +- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/schema/application/resolvers/Mutation/__snapshots__/copyFrom.test.ts.snap b/schema/application/resolvers/Mutation/__snapshots__/copyFrom.test.ts.snap index e87db1f..87b7f6d 100644 --- a/schema/application/resolvers/Mutation/__snapshots__/copyFrom.test.ts.snap +++ b/schema/application/resolvers/Mutation/__snapshots__/copyFrom.test.ts.snap @@ -1,6 +1,30 @@ // Bun Snapshot v1, https://goo.gl/fbAQLP -exports[`copyFrom copyFrom(:template, :withStatus[Open]) 1`] = ` +exports[`copyFrom when entity is a template 1`] = ` +{ + "copyFrom": { + "__typename": "CopyFromPayload", + "edge": { + "__typename": "ChecklistEdge", + "node": { + "__typename": "Checklist", + "name": { + "__typename": "DisplayName", + "name": { + "__typename": "DynamicString", + "value": "Checklist", + }, + }, + "status": { + "__typename": "ChecklistOpen", + }, + }, + }, + }, +} +`; + +exports[`copyFrom when entity is an instance 1`] = ` { "copyFrom": { "__typename": "CopyFromPayload", diff --git a/schema/application/resolvers/Mutation/copyFrom.test.ts b/schema/application/resolvers/Mutation/copyFrom.test.ts index 2e47c5f..dc444a7 100644 --- a/schema/application/resolvers/Mutation/copyFrom.test.ts +++ b/schema/application/resolvers/Mutation/copyFrom.test.ts @@ -1,18 +1,34 @@ import { describe, expect, test } from "bun:test"; import { resolvers, typeDefs } from "@/schema"; +import { encodeGlobalId } from "@/schema/system"; import { execute } from "@/test/prelude"; import { makeExecutableSchema } from "@graphql-tools/schema"; import { TestCopyFromDocument } from "./copyFrom.test.generated"; const schema = makeExecutableSchema({ resolvers, typeDefs }); -const TEMPLATE = - "d29ya3RlbXBsYXRlOndvcmstdGVtcGxhdGVfNzdhNTU1NjctNmIyYi00NTA2LTlkMmItZjM3NWUwYzI5ZTNm"; - describe.skipIf(!!process.env.CI)("copyFrom", () => { - test("copyFrom(:template, :withStatus[Open])", async () => { + test("when entity is a template", async () => { + const result = await execute(schema, TestCopyFromDocument, { + entity: encodeGlobalId({ + type: "worktemplate", + id: "work-template_77a55567-6b2b-4506-9d2b-f375e0c29e3f", + }), + options: { + withStatus: "open", + }, + }); + + expect(result.errors).toBeFalsy(); + expect(result.data).toMatchSnapshot(); + }); + + test("when entity is an instance", async () => { const result = await execute(schema, TestCopyFromDocument, { - entity: TEMPLATE, + entity: encodeGlobalId({ + type: "workinstance", + id: "work-instance_14162314-3e50-41f9-9902-74a0c186b922", + }), options: { withStatus: "open", }, diff --git a/schema/application/resolvers/Mutation/copyFrom.ts b/schema/application/resolvers/Mutation/copyFrom.ts index 1fa1629..b50eb90 100644 --- a/schema/application/resolvers/Mutation/copyFrom.ts +++ b/schema/application/resolvers/Mutation/copyFrom.ts @@ -123,7 +123,7 @@ export async function copyFromWorkTemplate( worktemplatecustomerid, worktemplatesiteid, ${options.originator ?? null}::bigint, - ${"previous" in options ? options.previous : null}::bigint, + ${"previous" in options && options.previous ? options.previous : null}::bigint, worktemplatesoplink, ${match(options.withStatus) .with("open", () => null)