Skip to content

Commit

Permalink
fix: copyFrom
Browse files Browse the repository at this point in the history
Reviewers: jmurphy4

Pull Request: #84
  • Loading branch information
willruggiano authored Dec 4, 2024
1 parent 0759420 commit c8125ea
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
26 changes: 21 additions & 5 deletions schema/application/resolvers/Mutation/copyFrom.test.ts
Original file line number Diff line number Diff line change
@@ -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",
},
Expand Down
2 changes: 1 addition & 1 deletion schema/application/resolvers/Mutation/copyFrom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c8125ea

Please sign in to comment.