From 366f402b0fa7c15f36fe256d3697e04f0012d63a Mon Sep 17 00:00:00 2001 From: Sagarika Dasgupta Date: Mon, 22 Sep 2025 14:32:45 -0500 Subject: [PATCH 1/2] Adding wasm level test fixture and default test --- .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 30 ++++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 24 +++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 30 ++++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 24 +++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 24 +++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 24 +++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 24 +++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 24 +++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 24 +++++++ functions-discount-js/tests/default.test.js | 40 +++++++++++ functions-discount-js/tests/fixtures/log.json | 49 +++++++++++++ functions-discount-rs/tests/default.test.js | 40 +++++++++++ functions-discount-rs/tests/fixtures/log.json | 45 ++++++++++++ functions-discount-wasm/tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 45 ++++++++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 17 +++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 17 +++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 17 +++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 27 +++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 27 +++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 27 +++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 57 +++++++++++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 58 +++++++++++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 58 +++++++++++++++ .../tests/default.test.js | 40 +++++++++++ .../fixtures/default_success.json.liquid | 56 +++++++++++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 56 +++++++++++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 56 +++++++++++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 16 +++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 19 +++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 19 +++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 70 ++++++++++++++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 72 +++++++++++++++++++ .../tests/default.test.js | 40 +++++++++++ .../tests/fixtures/log.json | 72 +++++++++++++++++++ 60 files changed, 2308 insertions(+) create mode 100644 functions-cart-checkout-validation-js/tests/default.test.js create mode 100644 functions-cart-checkout-validation-js/tests/fixtures/log.json create mode 100644 functions-cart-checkout-validation-rs/tests/default.test.js create mode 100644 functions-cart-checkout-validation-rs/tests/fixtures/log.json create mode 100644 functions-cart-checkout-validation-wasm/tests/default.test.js create mode 100644 functions-cart-checkout-validation-wasm/tests/fixtures/log.json create mode 100644 functions-cart-transform-js/tests/default.test.js create mode 100644 functions-cart-transform-js/tests/fixtures/log.json create mode 100644 functions-cart-transform-rs/tests/default.test.js create mode 100644 functions-cart-transform-rs/tests/fixtures/log.json create mode 100644 functions-cart-transform-wasm/tests/default.test.js create mode 100644 functions-cart-transform-wasm/tests/fixtures/log.json create mode 100644 functions-delivery-customization-js/tests/default.test.js create mode 100644 functions-delivery-customization-js/tests/fixtures/log.json create mode 100644 functions-delivery-customization-rs/tests/default.test.js create mode 100644 functions-delivery-customization-rs/tests/fixtures/log.json create mode 100644 functions-delivery-customization-wasm/tests/default.test.js create mode 100644 functions-delivery-customization-wasm/tests/fixtures/log.json create mode 100644 functions-discount-js/tests/default.test.js create mode 100644 functions-discount-js/tests/fixtures/log.json create mode 100644 functions-discount-rs/tests/default.test.js create mode 100644 functions-discount-rs/tests/fixtures/log.json create mode 100644 functions-discount-wasm/tests/default.test.js create mode 100644 functions-discount-wasm/tests/fixtures/log.json create mode 100644 functions-discounts-allocator-js/tests/default.test.js create mode 100644 functions-discounts-allocator-js/tests/fixtures/log.json create mode 100644 functions-discounts-allocator-rs/tests/default.test.js create mode 100644 functions-discounts-allocator-rs/tests/fixtures/log.json create mode 100644 functions-discounts-allocator-wasm/tests/default.test.js create mode 100644 functions-discounts-allocator-wasm/tests/fixtures/log.json create mode 100644 functions-fulfillment-constraints-js/tests/default.test.js create mode 100644 functions-fulfillment-constraints-js/tests/fixtures/log.json create mode 100644 functions-fulfillment-constraints-rs/tests/default.test.js create mode 100644 functions-fulfillment-constraints-rs/tests/fixtures/log.json create mode 100644 functions-fulfillment-constraints-wasm/tests/default.test.js create mode 100644 functions-fulfillment-constraints-wasm/tests/fixtures/log.json create mode 100644 functions-local-pickup-delivery-option-generators-js/tests/default.test.js create mode 100644 functions-local-pickup-delivery-option-generators-js/tests/fixtures/log.json create mode 100644 functions-local-pickup-delivery-option-generators-rs/tests/default.test.js create mode 100644 functions-local-pickup-delivery-option-generators-rs/tests/fixtures/log.json create mode 100644 functions-local-pickup-delivery-option-generators-wasm/tests/default.test.js create mode 100644 functions-local-pickup-delivery-option-generators-wasm/tests/fixtures/log.json create mode 100644 functions-location-rules-js/tests/default.test.js create mode 100644 functions-location-rules-js/tests/fixtures/default_success.json.liquid create mode 100644 functions-location-rules-rs/tests/default.test.js create mode 100644 functions-location-rules-rs/tests/fixtures/log.json create mode 100644 functions-location-rules-wasm/tests/default.test.js create mode 100644 functions-location-rules-wasm/tests/fixtures/log.json create mode 100644 functions-payment-customization-js/tests/default.test.js create mode 100644 functions-payment-customization-js/tests/fixtures/log.json create mode 100644 functions-payment-customization-rs/tests/default.test.js create mode 100644 functions-payment-customization-rs/tests/fixtures/log.json create mode 100644 functions-payment-customization-wasm/tests/default.test.js create mode 100644 functions-payment-customization-wasm/tests/fixtures/log.json create mode 100644 functions-pickup-point-delivery-option-generators-js/tests/default.test.js create mode 100644 functions-pickup-point-delivery-option-generators-js/tests/fixtures/log.json create mode 100644 functions-pickup-point-delivery-option-generators-rs/tests/default.test.js create mode 100644 functions-pickup-point-delivery-option-generators-rs/tests/fixtures/log.json create mode 100644 functions-pickup-point-delivery-option-generators-wasm/tests/default.test.js create mode 100644 functions-pickup-point-delivery-option-generators-wasm/tests/fixtures/log.json diff --git a/functions-cart-checkout-validation-js/tests/default.test.js b/functions-cart-checkout-validation-js/tests/default.test.js new file mode 100644 index 00000000..fafb13be --- /dev/null +++ b/functions-cart-checkout-validation-js/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-cart-checkout-validation-js/tests/fixtures/log.json b/functions-cart-checkout-validation-js/tests/fixtures/log.json new file mode 100644 index 00000000..a1be280e --- /dev/null +++ b/functions-cart-checkout-validation-js/tests/fixtures/log.json @@ -0,0 +1,30 @@ +{ + "payload": { + "export": "cart-validations-generate-run", + "target": "cart.validations.generate.run", + "input": { + "cart": { + "lines": [ + { + "quantity": 1 + }, + { + "quantity": 1 + }, + { + "quantity": 1 + } + ] + } + }, + "output": { + "operations": [ + { + "validationAdd": { + "errors": [] + } + } + ] + } + } +} \ No newline at end of file diff --git a/functions-cart-checkout-validation-rs/tests/default.test.js b/functions-cart-checkout-validation-rs/tests/default.test.js new file mode 100644 index 00000000..fafb13be --- /dev/null +++ b/functions-cart-checkout-validation-rs/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-cart-checkout-validation-rs/tests/fixtures/log.json b/functions-cart-checkout-validation-rs/tests/fixtures/log.json new file mode 100644 index 00000000..3579c1a8 --- /dev/null +++ b/functions-cart-checkout-validation-rs/tests/fixtures/log.json @@ -0,0 +1,24 @@ +{ + "payload": { + "export": "run", + "target": "purchase.validation.run", + "input": { + "cart": { + "lines": [ + { + "quantity": 1 + }, + { + "quantity": 1 + }, + { + "quantity": 1 + } + ] + } + }, + "output": { + "errors": [] + } + } +} \ No newline at end of file diff --git a/functions-cart-checkout-validation-wasm/tests/default.test.js b/functions-cart-checkout-validation-wasm/tests/default.test.js new file mode 100644 index 00000000..fafb13be --- /dev/null +++ b/functions-cart-checkout-validation-wasm/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-cart-checkout-validation-wasm/tests/fixtures/log.json b/functions-cart-checkout-validation-wasm/tests/fixtures/log.json new file mode 100644 index 00000000..a1be280e --- /dev/null +++ b/functions-cart-checkout-validation-wasm/tests/fixtures/log.json @@ -0,0 +1,30 @@ +{ + "payload": { + "export": "cart-validations-generate-run", + "target": "cart.validations.generate.run", + "input": { + "cart": { + "lines": [ + { + "quantity": 1 + }, + { + "quantity": 1 + }, + { + "quantity": 1 + } + ] + } + }, + "output": { + "operations": [ + { + "validationAdd": { + "errors": [] + } + } + ] + } + } +} \ No newline at end of file diff --git a/functions-cart-transform-js/tests/default.test.js b/functions-cart-transform-js/tests/default.test.js new file mode 100644 index 00000000..73d465f1 --- /dev/null +++ b/functions-cart-transform-js/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/cart_transform_run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-cart-transform-js/tests/fixtures/log.json b/functions-cart-transform-js/tests/fixtures/log.json new file mode 100644 index 00000000..ff4a5e83 --- /dev/null +++ b/functions-cart-transform-js/tests/fixtures/log.json @@ -0,0 +1,24 @@ +{ + "payload": { + "export": "cart-transform-run", + "target": "cart.transform.run", + "input": { + "cart": { + "buyerIdentity": null, + "cost": { + "subtotalAmount": { + "amount": "100.0" + } + }, + "lines": [ + { + "quantity": 1 + } + ] + } + }, + "output": { + "operations": [] + } + } +} \ No newline at end of file diff --git a/functions-cart-transform-rs/tests/default.test.js b/functions-cart-transform-rs/tests/default.test.js new file mode 100644 index 00000000..73d465f1 --- /dev/null +++ b/functions-cart-transform-rs/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/cart_transform_run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-cart-transform-rs/tests/fixtures/log.json b/functions-cart-transform-rs/tests/fixtures/log.json new file mode 100644 index 00000000..d6094218 --- /dev/null +++ b/functions-cart-transform-rs/tests/fixtures/log.json @@ -0,0 +1,24 @@ +{ + "payload": { + "export": "cart_transform_run", + "target": "cart.transform.run", + "input": { + "cart": { + "buyerIdentity": null, + "cost": { + "subtotalAmount": { + "amount": "100.0" + } + }, + "lines": [ + { + "quantity": 1 + } + ] + } + }, + "output": { + "operations": [] + } + } +} \ No newline at end of file diff --git a/functions-cart-transform-wasm/tests/default.test.js b/functions-cart-transform-wasm/tests/default.test.js new file mode 100644 index 00000000..73d465f1 --- /dev/null +++ b/functions-cart-transform-wasm/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/cart_transform_run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-cart-transform-wasm/tests/fixtures/log.json b/functions-cart-transform-wasm/tests/fixtures/log.json new file mode 100644 index 00000000..d6094218 --- /dev/null +++ b/functions-cart-transform-wasm/tests/fixtures/log.json @@ -0,0 +1,24 @@ +{ + "payload": { + "export": "cart_transform_run", + "target": "cart.transform.run", + "input": { + "cart": { + "buyerIdentity": null, + "cost": { + "subtotalAmount": { + "amount": "100.0" + } + }, + "lines": [ + { + "quantity": 1 + } + ] + } + }, + "output": { + "operations": [] + } + } +} \ No newline at end of file diff --git a/functions-delivery-customization-js/tests/default.test.js b/functions-delivery-customization-js/tests/default.test.js new file mode 100644 index 00000000..df96761d --- /dev/null +++ b/functions-delivery-customization-js/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/cart_delivery_options_transform_run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-delivery-customization-js/tests/fixtures/log.json b/functions-delivery-customization-js/tests/fixtures/log.json new file mode 100644 index 00000000..61e9d73a --- /dev/null +++ b/functions-delivery-customization-js/tests/fixtures/log.json @@ -0,0 +1,24 @@ +{ + "payload": { + "export": "cart-delivery-options-transform-run", + "target": "cart.delivery-options.transform.run", + "input": { + "cart": { + "buyerIdentity": null, + "cost": { + "subtotalAmount": { + "amount": "100.0" + } + }, + "lines": [ + { + "quantity": 1 + } + ] + } + }, + "output": { + "operations": [] + } + } +} \ No newline at end of file diff --git a/functions-delivery-customization-rs/tests/default.test.js b/functions-delivery-customization-rs/tests/default.test.js new file mode 100644 index 00000000..df96761d --- /dev/null +++ b/functions-delivery-customization-rs/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/cart_delivery_options_transform_run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-delivery-customization-rs/tests/fixtures/log.json b/functions-delivery-customization-rs/tests/fixtures/log.json new file mode 100644 index 00000000..ae6edd91 --- /dev/null +++ b/functions-delivery-customization-rs/tests/fixtures/log.json @@ -0,0 +1,24 @@ +{ + "payload": { + "export": "cart_delivery_options_transform_run", + "target": "cart.delivery-options.transform.run", + "input": { + "cart": { + "buyerIdentity": null, + "cost": { + "subtotalAmount": { + "amount": "100.0" + } + }, + "lines": [ + { + "quantity": 1 + } + ] + } + }, + "output": { + "operations": [] + } + } +} \ No newline at end of file diff --git a/functions-delivery-customization-wasm/tests/default.test.js b/functions-delivery-customization-wasm/tests/default.test.js new file mode 100644 index 00000000..df96761d --- /dev/null +++ b/functions-delivery-customization-wasm/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/cart_delivery_options_transform_run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-delivery-customization-wasm/tests/fixtures/log.json b/functions-delivery-customization-wasm/tests/fixtures/log.json new file mode 100644 index 00000000..ae6edd91 --- /dev/null +++ b/functions-delivery-customization-wasm/tests/fixtures/log.json @@ -0,0 +1,24 @@ +{ + "payload": { + "export": "cart_delivery_options_transform_run", + "target": "cart.delivery-options.transform.run", + "input": { + "cart": { + "buyerIdentity": null, + "cost": { + "subtotalAmount": { + "amount": "100.0" + } + }, + "lines": [ + { + "quantity": 1 + } + ] + } + }, + "output": { + "operations": [] + } + } +} \ No newline at end of file diff --git a/functions-discount-js/tests/default.test.js b/functions-discount-js/tests/default.test.js new file mode 100644 index 00000000..70c40521 --- /dev/null +++ b/functions-discount-js/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/cart_delivery_options_discounts_generate_run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-discount-js/tests/fixtures/log.json b/functions-discount-js/tests/fixtures/log.json new file mode 100644 index 00000000..cabdbcc0 --- /dev/null +++ b/functions-discount-js/tests/fixtures/log.json @@ -0,0 +1,49 @@ +{ + "payload": { + "export": "cart-delivery-options-discounts-generate-run", + "target": "cart.delivery-options.discounts.generate.run", + "input": { + "discount": { + "discountClasses": ["SHIPPING"] + }, + "cart": { + "deliveryGroups": [ + { + "id": "gid://shopify/CartDeliveryGroup/1" + } + ], + "cost": { + "subtotalAmount": { + "amount": "100.0" + } + } + } + }, + "output": { + "operations": [ + { + "deliveryDiscountsAdd": { + "candidates": [ + { + "message": "FREE DELIVERY", + "targets": [ + { + "deliveryGroup": { + "id": "gid://shopify/CartDeliveryGroup/1" + } + } + ], + "value": { + "percentage": { + "value": 100 + } + } + } + ], + "selectionStrategy": "ALL" + } + } + ] + } + } +} \ No newline at end of file diff --git a/functions-discount-rs/tests/default.test.js b/functions-discount-rs/tests/default.test.js new file mode 100644 index 00000000..70c40521 --- /dev/null +++ b/functions-discount-rs/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/cart_delivery_options_discounts_generate_run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-discount-rs/tests/fixtures/log.json b/functions-discount-rs/tests/fixtures/log.json new file mode 100644 index 00000000..4b47644a --- /dev/null +++ b/functions-discount-rs/tests/fixtures/log.json @@ -0,0 +1,45 @@ +{ + "payload": { + "export": "cart_delivery_options_discounts_generate_run", + "target": "cart.delivery-options.discounts.generate.run", + "input": { + "discount": { + "discountClasses": ["SHIPPING"] + }, + "cart": { + "deliveryGroups": [ + { + "id": "gid://shopify/CartDeliveryGroup/1" + } + ] + } + }, + "output": { + "operations": [ + { + "deliveryDiscountsAdd": { + "candidates": [ + { + "associatedDiscountCode": null, + "message": "FREE DELIVERY", + "targets": [ + { + "deliveryGroup": { + "id": "gid://shopify/CartDeliveryGroup/1" + } + } + ], + "value": { + "percentage": { + "value": "100.0" + } + } + } + ], + "selectionStrategy": "ALL" + } + } + ] + } + } +} \ No newline at end of file diff --git a/functions-discount-wasm/tests/default.test.js b/functions-discount-wasm/tests/default.test.js new file mode 100644 index 00000000..70c40521 --- /dev/null +++ b/functions-discount-wasm/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/cart_delivery_options_discounts_generate_run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-discount-wasm/tests/fixtures/log.json b/functions-discount-wasm/tests/fixtures/log.json new file mode 100644 index 00000000..4b47644a --- /dev/null +++ b/functions-discount-wasm/tests/fixtures/log.json @@ -0,0 +1,45 @@ +{ + "payload": { + "export": "cart_delivery_options_discounts_generate_run", + "target": "cart.delivery-options.discounts.generate.run", + "input": { + "discount": { + "discountClasses": ["SHIPPING"] + }, + "cart": { + "deliveryGroups": [ + { + "id": "gid://shopify/CartDeliveryGroup/1" + } + ] + } + }, + "output": { + "operations": [ + { + "deliveryDiscountsAdd": { + "candidates": [ + { + "associatedDiscountCode": null, + "message": "FREE DELIVERY", + "targets": [ + { + "deliveryGroup": { + "id": "gid://shopify/CartDeliveryGroup/1" + } + } + ], + "value": { + "percentage": { + "value": "100.0" + } + } + } + ], + "selectionStrategy": "ALL" + } + } + ] + } + } +} \ No newline at end of file diff --git a/functions-discounts-allocator-js/tests/default.test.js b/functions-discounts-allocator-js/tests/default.test.js new file mode 100644 index 00000000..fafb13be --- /dev/null +++ b/functions-discounts-allocator-js/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-discounts-allocator-js/tests/fixtures/log.json b/functions-discounts-allocator-js/tests/fixtures/log.json new file mode 100644 index 00000000..b7d7c40c --- /dev/null +++ b/functions-discounts-allocator-js/tests/fixtures/log.json @@ -0,0 +1,17 @@ +{ + "payload": { + "export": "run", + "target": "purchase.discounts-allocator.run", + "input": { + "shop": { + "metafield": { + "value": "{\"discountConfiguration\": {\"enabled\": true, \"allocationType\": \"proportional\"}}" + } + } + }, + "output": { + "displayableErrors": [], + "lineDiscounts": [] + } + } +} \ No newline at end of file diff --git a/functions-discounts-allocator-rs/tests/default.test.js b/functions-discounts-allocator-rs/tests/default.test.js new file mode 100644 index 00000000..fafb13be --- /dev/null +++ b/functions-discounts-allocator-rs/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-discounts-allocator-rs/tests/fixtures/log.json b/functions-discounts-allocator-rs/tests/fixtures/log.json new file mode 100644 index 00000000..b7d7c40c --- /dev/null +++ b/functions-discounts-allocator-rs/tests/fixtures/log.json @@ -0,0 +1,17 @@ +{ + "payload": { + "export": "run", + "target": "purchase.discounts-allocator.run", + "input": { + "shop": { + "metafield": { + "value": "{\"discountConfiguration\": {\"enabled\": true, \"allocationType\": \"proportional\"}}" + } + } + }, + "output": { + "displayableErrors": [], + "lineDiscounts": [] + } + } +} \ No newline at end of file diff --git a/functions-discounts-allocator-wasm/tests/default.test.js b/functions-discounts-allocator-wasm/tests/default.test.js new file mode 100644 index 00000000..fafb13be --- /dev/null +++ b/functions-discounts-allocator-wasm/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-discounts-allocator-wasm/tests/fixtures/log.json b/functions-discounts-allocator-wasm/tests/fixtures/log.json new file mode 100644 index 00000000..b7d7c40c --- /dev/null +++ b/functions-discounts-allocator-wasm/tests/fixtures/log.json @@ -0,0 +1,17 @@ +{ + "payload": { + "export": "run", + "target": "purchase.discounts-allocator.run", + "input": { + "shop": { + "metafield": { + "value": "{\"discountConfiguration\": {\"enabled\": true, \"allocationType\": \"proportional\"}}" + } + } + }, + "output": { + "displayableErrors": [], + "lineDiscounts": [] + } + } +} \ No newline at end of file diff --git a/functions-fulfillment-constraints-js/tests/default.test.js b/functions-fulfillment-constraints-js/tests/default.test.js new file mode 100644 index 00000000..02b36ebe --- /dev/null +++ b/functions-fulfillment-constraints-js/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/cart_fulfillment_constraints_generate_run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-fulfillment-constraints-js/tests/fixtures/log.json b/functions-fulfillment-constraints-js/tests/fixtures/log.json new file mode 100644 index 00000000..7c3f9d9b --- /dev/null +++ b/functions-fulfillment-constraints-js/tests/fixtures/log.json @@ -0,0 +1,27 @@ +{ + "payload": { + "export": "cart-fulfillment-constraints-generate-run", + "target": "cart.fulfillment-constraints.generate.run", + "input": { + "cart": { + "deliverableLines": [ + { + "id": "gid://shopify/CartLine/1" + } + ] + }, + "fulfillmentConstraintRule": { + "metafield": { + "jsonValue": { + "constraintType": "shipping_method", + "restrictedMethods": ["standard"], + "allowedMethods": ["express", "overnight"] + } + } + } + }, + "output": { + "operations": [] + } + } +} \ No newline at end of file diff --git a/functions-fulfillment-constraints-rs/tests/default.test.js b/functions-fulfillment-constraints-rs/tests/default.test.js new file mode 100644 index 00000000..02b36ebe --- /dev/null +++ b/functions-fulfillment-constraints-rs/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/cart_fulfillment_constraints_generate_run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-fulfillment-constraints-rs/tests/fixtures/log.json b/functions-fulfillment-constraints-rs/tests/fixtures/log.json new file mode 100644 index 00000000..f31ffc47 --- /dev/null +++ b/functions-fulfillment-constraints-rs/tests/fixtures/log.json @@ -0,0 +1,27 @@ +{ + "payload": { + "export": "cart_fulfillment_constraints_generate_run", + "target": "cart.fulfillment-constraints.generate.run", + "input": { + "cart": { + "deliverableLines": [ + { + "id": "gid://shopify/CartLine/1" + } + ] + }, + "fulfillmentConstraintRule": { + "metafield": { + "jsonValue": { + "constraintType": "shipping_method", + "restrictedMethods": ["standard"], + "allowedMethods": ["express", "overnight"] + } + } + } + }, + "output": { + "operations": [] + } + } +} \ No newline at end of file diff --git a/functions-fulfillment-constraints-wasm/tests/default.test.js b/functions-fulfillment-constraints-wasm/tests/default.test.js new file mode 100644 index 00000000..02b36ebe --- /dev/null +++ b/functions-fulfillment-constraints-wasm/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/cart_fulfillment_constraints_generate_run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-fulfillment-constraints-wasm/tests/fixtures/log.json b/functions-fulfillment-constraints-wasm/tests/fixtures/log.json new file mode 100644 index 00000000..f31ffc47 --- /dev/null +++ b/functions-fulfillment-constraints-wasm/tests/fixtures/log.json @@ -0,0 +1,27 @@ +{ + "payload": { + "export": "cart_fulfillment_constraints_generate_run", + "target": "cart.fulfillment-constraints.generate.run", + "input": { + "cart": { + "deliverableLines": [ + { + "id": "gid://shopify/CartLine/1" + } + ] + }, + "fulfillmentConstraintRule": { + "metafield": { + "jsonValue": { + "constraintType": "shipping_method", + "restrictedMethods": ["standard"], + "allowedMethods": ["express", "overnight"] + } + } + } + }, + "output": { + "operations": [] + } + } +} \ No newline at end of file diff --git a/functions-local-pickup-delivery-option-generators-js/tests/default.test.js b/functions-local-pickup-delivery-option-generators-js/tests/default.test.js new file mode 100644 index 00000000..fafb13be --- /dev/null +++ b/functions-local-pickup-delivery-option-generators-js/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-local-pickup-delivery-option-generators-js/tests/fixtures/log.json b/functions-local-pickup-delivery-option-generators-js/tests/fixtures/log.json new file mode 100644 index 00000000..d71bbd53 --- /dev/null +++ b/functions-local-pickup-delivery-option-generators-js/tests/fixtures/log.json @@ -0,0 +1,57 @@ +{ + "payload": { + "export": "run", + "target": "purchase.local-pickup-delivery-option-generator.run", + "input": { + "cart": { + "lines": [ + { + "id": "gid://shopify/CartLine/1" + } + ] + }, + "fulfillmentGroups": [ + { + "handle": "group1", + "inventoryLocationHandles": ["location1"], + "lines": [ + { + "id": "gid://shopify/CartLine/1" + } + ], + "deliveryGroup": { + "id": "gid://shopify/CartDeliveryGroup/1" + } + } + ], + "locations": [ + { + "handle": "location1", + "name": "Main Store", + "address": { + "address1": "123 Main Street" + } + } + ], + "deliveryOptionGenerator": { + "metafield": { + "value": "[\"location1\", \"location2\"]" + } + } + }, + "output": { + "operations": [ + { + "add": { + "title": "Main St.", + "cost": 1.99, + "pickupLocation": { + "locationHandle": "2578303", + "pickupInstruction": "Usually ready in 24 hours." + } + } + } + ] + } + } +} \ No newline at end of file diff --git a/functions-local-pickup-delivery-option-generators-rs/tests/default.test.js b/functions-local-pickup-delivery-option-generators-rs/tests/default.test.js new file mode 100644 index 00000000..fafb13be --- /dev/null +++ b/functions-local-pickup-delivery-option-generators-rs/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-local-pickup-delivery-option-generators-rs/tests/fixtures/log.json b/functions-local-pickup-delivery-option-generators-rs/tests/fixtures/log.json new file mode 100644 index 00000000..9c044ca8 --- /dev/null +++ b/functions-local-pickup-delivery-option-generators-rs/tests/fixtures/log.json @@ -0,0 +1,58 @@ +{ + "payload": { + "export": "run", + "target": "purchase.local-pickup-delivery-option-generator.run", + "input": { + "cart": { + "lines": [ + { + "id": "gid://shopify/CartLine/1" + } + ] + }, + "fulfillmentGroups": [ + { + "handle": "group1", + "inventoryLocationHandles": ["location1"], + "lines": [ + { + "id": "gid://shopify/CartLine/1" + } + ], + "deliveryGroup": { + "id": "gid://shopify/CartDeliveryGroup/1" + } + } + ], + "locations": [ + { + "handle": "location1", + "name": "Main Store", + "address": { + "address1": "123 Main Street" + } + } + ], + "deliveryOptionGenerator": { + "metafield": { + "value": "[\"location1\", \"location2\"]" + } + } + }, + "output": { + "operations": [ + { + "add": { + "cost": "1.99", + "metafields": null, + "pickupLocation": { + "locationHandle": "2578303", + "pickupInstruction": "Usually ready in 24 hours." + }, + "title": "Main St." + } + } + ] + } + } +} \ No newline at end of file diff --git a/functions-local-pickup-delivery-option-generators-wasm/tests/default.test.js b/functions-local-pickup-delivery-option-generators-wasm/tests/default.test.js new file mode 100644 index 00000000..fafb13be --- /dev/null +++ b/functions-local-pickup-delivery-option-generators-wasm/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-local-pickup-delivery-option-generators-wasm/tests/fixtures/log.json b/functions-local-pickup-delivery-option-generators-wasm/tests/fixtures/log.json new file mode 100644 index 00000000..9c044ca8 --- /dev/null +++ b/functions-local-pickup-delivery-option-generators-wasm/tests/fixtures/log.json @@ -0,0 +1,58 @@ +{ + "payload": { + "export": "run", + "target": "purchase.local-pickup-delivery-option-generator.run", + "input": { + "cart": { + "lines": [ + { + "id": "gid://shopify/CartLine/1" + } + ] + }, + "fulfillmentGroups": [ + { + "handle": "group1", + "inventoryLocationHandles": ["location1"], + "lines": [ + { + "id": "gid://shopify/CartLine/1" + } + ], + "deliveryGroup": { + "id": "gid://shopify/CartDeliveryGroup/1" + } + } + ], + "locations": [ + { + "handle": "location1", + "name": "Main Store", + "address": { + "address1": "123 Main Street" + } + } + ], + "deliveryOptionGenerator": { + "metafield": { + "value": "[\"location1\", \"location2\"]" + } + } + }, + "output": { + "operations": [ + { + "add": { + "cost": "1.99", + "metafields": null, + "pickupLocation": { + "locationHandle": "2578303", + "pickupInstruction": "Usually ready in 24 hours." + }, + "title": "Main St." + } + } + ] + } + } +} \ No newline at end of file diff --git a/functions-location-rules-js/tests/default.test.js b/functions-location-rules-js/tests/default.test.js new file mode 100644 index 00000000..11435700 --- /dev/null +++ b/functions-location-rules-js/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/cart_fulfillment_groups_location_rankings_generate_run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-location-rules-js/tests/fixtures/default_success.json.liquid b/functions-location-rules-js/tests/fixtures/default_success.json.liquid new file mode 100644 index 00000000..196b211a --- /dev/null +++ b/functions-location-rules-js/tests/fixtures/default_success.json.liquid @@ -0,0 +1,56 @@ +{ + "payload": { + "export": "cart-fulfillment-groups-location-rankings-generate-run", + "target": "cart.fulfillment-groups.location-rankings.generate.run", + "input": { + "fulfillmentGroups": [ + { + "handle": "123", + "inventoryLocationHandles": ["456", "789"] + }, + { + "handle": "456", + "inventoryLocationHandles": ["101", "112", "131"] + } + ] + }, + "output": { + "operations": [ + { + "fulfillmentGroupLocationRankingAdd": { + "fulfillmentGroupHandle": "123", + "rankings": [ + { + "locationHandle": "456", + "rank": 0 + }, + { + "locationHandle": "789", + "rank": 0 + } + ] + } + }, + { + "fulfillmentGroupLocationRankingAdd": { + "fulfillmentGroupHandle": "456", + "rankings": [ + { + "locationHandle": "101", + "rank": 0 + }, + { + "locationHandle": "112", + "rank": 0 + }, + { + "locationHandle": "131", + "rank": 0 + } + ] + } + } + ] + } + } +} \ No newline at end of file diff --git a/functions-location-rules-rs/tests/default.test.js b/functions-location-rules-rs/tests/default.test.js new file mode 100644 index 00000000..11435700 --- /dev/null +++ b/functions-location-rules-rs/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/cart_fulfillment_groups_location_rankings_generate_run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-location-rules-rs/tests/fixtures/log.json b/functions-location-rules-rs/tests/fixtures/log.json new file mode 100644 index 00000000..57f04bb1 --- /dev/null +++ b/functions-location-rules-rs/tests/fixtures/log.json @@ -0,0 +1,56 @@ +{ + "payload": { + "export": "cart_fulfillment_groups_location_rankings_generate_run", + "target": "cart.fulfillment-groups.location-rankings.generate.run", + "input": { + "fulfillmentGroups": [ + { + "handle": "123", + "inventoryLocationHandles": ["456", "789"] + }, + { + "handle": "456", + "inventoryLocationHandles": ["101", "112", "131"] + } + ] + }, + "output": { + "operations": [ + { + "fulfillmentGroupLocationRankingAdd": { + "fulfillmentGroupHandle": "123", + "rankings": [ + { + "locationHandle": "456", + "rank": 0 + }, + { + "locationHandle": "789", + "rank": 0 + } + ] + } + }, + { + "fulfillmentGroupLocationRankingAdd": { + "fulfillmentGroupHandle": "456", + "rankings": [ + { + "locationHandle": "101", + "rank": 0 + }, + { + "locationHandle": "112", + "rank": 0 + }, + { + "locationHandle": "131", + "rank": 0 + } + ] + } + } + ] + } + } +} \ No newline at end of file diff --git a/functions-location-rules-wasm/tests/default.test.js b/functions-location-rules-wasm/tests/default.test.js new file mode 100644 index 00000000..11435700 --- /dev/null +++ b/functions-location-rules-wasm/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/cart_fulfillment_groups_location_rankings_generate_run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-location-rules-wasm/tests/fixtures/log.json b/functions-location-rules-wasm/tests/fixtures/log.json new file mode 100644 index 00000000..57f04bb1 --- /dev/null +++ b/functions-location-rules-wasm/tests/fixtures/log.json @@ -0,0 +1,56 @@ +{ + "payload": { + "export": "cart_fulfillment_groups_location_rankings_generate_run", + "target": "cart.fulfillment-groups.location-rankings.generate.run", + "input": { + "fulfillmentGroups": [ + { + "handle": "123", + "inventoryLocationHandles": ["456", "789"] + }, + { + "handle": "456", + "inventoryLocationHandles": ["101", "112", "131"] + } + ] + }, + "output": { + "operations": [ + { + "fulfillmentGroupLocationRankingAdd": { + "fulfillmentGroupHandle": "123", + "rankings": [ + { + "locationHandle": "456", + "rank": 0 + }, + { + "locationHandle": "789", + "rank": 0 + } + ] + } + }, + { + "fulfillmentGroupLocationRankingAdd": { + "fulfillmentGroupHandle": "456", + "rankings": [ + { + "locationHandle": "101", + "rank": 0 + }, + { + "locationHandle": "112", + "rank": 0 + }, + { + "locationHandle": "131", + "rank": 0 + } + ] + } + } + ] + } + } +} \ No newline at end of file diff --git a/functions-payment-customization-js/tests/default.test.js b/functions-payment-customization-js/tests/default.test.js new file mode 100644 index 00000000..3ed21811 --- /dev/null +++ b/functions-payment-customization-js/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/cart_payment_methods_transform_run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-payment-customization-js/tests/fixtures/log.json b/functions-payment-customization-js/tests/fixtures/log.json new file mode 100644 index 00000000..ad43d89a --- /dev/null +++ b/functions-payment-customization-js/tests/fixtures/log.json @@ -0,0 +1,16 @@ +{ + "payload": { + "export": "cart-payment-methods-transform-run", + "target": "cart.payment-methods.transform.run", + "input": { + "paymentCustomization": { + "metafield": { + "value": "{\"hidePaymentMethods\": [\"credit_card\"], \"showPaymentMethods\": [\"paypal\", \"apple_pay\"]}" + } + } + }, + "output": { + "operations": [] + } + } +} \ No newline at end of file diff --git a/functions-payment-customization-rs/tests/default.test.js b/functions-payment-customization-rs/tests/default.test.js new file mode 100644 index 00000000..3ed21811 --- /dev/null +++ b/functions-payment-customization-rs/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/cart_payment_methods_transform_run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-payment-customization-rs/tests/fixtures/log.json b/functions-payment-customization-rs/tests/fixtures/log.json new file mode 100644 index 00000000..c6ada242 --- /dev/null +++ b/functions-payment-customization-rs/tests/fixtures/log.json @@ -0,0 +1,19 @@ +{ + "payload": { + "export": "cart_payment_methods_transform_run", + "target": "cart.payment-methods.transform.run", + "input": { + "paymentCustomization": { + "metafield": { + "jsonValue": { + "hidePaymentMethods": ["credit_card"], + "showPaymentMethods": ["paypal", "apple_pay"] + } + } + } + }, + "output": { + "operations": [] + } + } +} \ No newline at end of file diff --git a/functions-payment-customization-wasm/tests/default.test.js b/functions-payment-customization-wasm/tests/default.test.js new file mode 100644 index 00000000..3ed21811 --- /dev/null +++ b/functions-payment-customization-wasm/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/cart_payment_methods_transform_run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-payment-customization-wasm/tests/fixtures/log.json b/functions-payment-customization-wasm/tests/fixtures/log.json new file mode 100644 index 00000000..c6ada242 --- /dev/null +++ b/functions-payment-customization-wasm/tests/fixtures/log.json @@ -0,0 +1,19 @@ +{ + "payload": { + "export": "cart_payment_methods_transform_run", + "target": "cart.payment-methods.transform.run", + "input": { + "paymentCustomization": { + "metafield": { + "jsonValue": { + "hidePaymentMethods": ["credit_card"], + "showPaymentMethods": ["paypal", "apple_pay"] + } + } + } + }, + "output": { + "operations": [] + } + } +} \ No newline at end of file diff --git a/functions-pickup-point-delivery-option-generators-js/tests/default.test.js b/functions-pickup-point-delivery-option-generators-js/tests/default.test.js new file mode 100644 index 00000000..fafb13be --- /dev/null +++ b/functions-pickup-point-delivery-option-generators-js/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-pickup-point-delivery-option-generators-js/tests/fixtures/log.json b/functions-pickup-point-delivery-option-generators-js/tests/fixtures/log.json new file mode 100644 index 00000000..8de085ff --- /dev/null +++ b/functions-pickup-point-delivery-option-generators-js/tests/fixtures/log.json @@ -0,0 +1,70 @@ +{ + "payload": { + "export": "run", + "target": "purchase.pickup-point-delivery-option-generator.run", + "input": { + "fetchResult": { + "status": 200, + "body": "{\"deliveryPoints\": [{\"pointId\": \"pickup1\", \"pointName\": \"Pickup Location 1\", \"location\": {\"addressComponents\": {\"streetNumber\": \"123\", \"route\": \"Main St\", \"locality\": \"New York\", \"country\": \"United States\", \"countryCode\": \"US\", \"postalCode\": \"10001\", \"administrativeArea\": {\"name\": \"New York\", \"code\": \"NY\"}}, \"geometry\": {\"location\": {\"lat\": 40.7589, \"lng\": -73.9851}}}}, {\"pointId\": \"pickup2\", \"pointName\": \"Pickup Location 2\", \"location\": {\"addressComponents\": {\"streetNumber\": \"456\", \"route\": \"Oak Ave\", \"locality\": \"New York\", \"country\": \"United States\", \"countryCode\": \"US\", \"postalCode\": \"10002\", \"administrativeArea\": {\"name\": \"New York\", \"code\": \"NY\"}}, \"geometry\": {\"location\": {\"lat\": 40.7614, \"lng\": -73.9776}}}}]}" + } + }, + "output": { + "operations": [ + { + "add": { + "cost": null, + "pickupPoint": { + "externalId": "pickup1", + "name": "Pickup Location 1", + "provider": { + "name": "Shopify Javascript Demo", + "logoUrl": "https://cdn.shopify.com/s/files/1/0628/3830/9033/files/shopify_icon_146101.png?v=1706120545" + }, + "address": { + "address1": "123 Main St", + "address2": null, + "city": "New York", + "country": "United States", + "countryCode": "US", + "latitude": 40.7589, + "longitude": -73.9851, + "phone": null, + "province": "New York", + "provinceCode": "NY", + "zip": "10001" + }, + "businessHours": null + } + } + }, + { + "add": { + "cost": null, + "pickupPoint": { + "externalId": "pickup2", + "name": "Pickup Location 2", + "provider": { + "name": "Shopify Javascript Demo", + "logoUrl": "https://cdn.shopify.com/s/files/1/0628/3830/9033/files/shopify_icon_146101.png?v=1706120545" + }, + "address": { + "address1": "456 Oak Ave", + "address2": null, + "city": "New York", + "country": "United States", + "countryCode": "US", + "latitude": 40.7614, + "longitude": -73.9776, + "phone": null, + "province": "New York", + "provinceCode": "NY", + "zip": "10002" + }, + "businessHours": null + } + } + } + ] + } + } +} \ No newline at end of file diff --git a/functions-pickup-point-delivery-option-generators-rs/tests/default.test.js b/functions-pickup-point-delivery-option-generators-rs/tests/default.test.js new file mode 100644 index 00000000..fafb13be --- /dev/null +++ b/functions-pickup-point-delivery-option-generators-rs/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-pickup-point-delivery-option-generators-rs/tests/fixtures/log.json b/functions-pickup-point-delivery-option-generators-rs/tests/fixtures/log.json new file mode 100644 index 00000000..0e3fc6f6 --- /dev/null +++ b/functions-pickup-point-delivery-option-generators-rs/tests/fixtures/log.json @@ -0,0 +1,72 @@ +{ + "payload": { + "export": "run", + "target": "purchase.pickup-point-delivery-option-generator.run", + "input": { + "fetchResult": { + "status": 200, + "body": "{\"deliveryPoints\": [{\"pointId\": \"pickup1\", \"pointName\": \"Pickup Location 1\", \"location\": {\"addressComponents\": {\"streetNumber\": \"123\", \"route\": \"Main St\", \"locality\": \"New York\", \"country\": \"United States\", \"countryCode\": \"US\", \"postalCode\": \"10001\", \"administrativeArea\": {\"name\": \"New York\", \"code\": \"NY\"}}, \"geometry\": {\"location\": {\"lat\": 40.7589, \"lng\": -73.9851}}}}, {\"pointId\": \"pickup2\", \"pointName\": \"Pickup Location 2\", \"location\": {\"addressComponents\": {\"streetNumber\": \"456\", \"route\": \"Oak Ave\", \"locality\": \"New York\", \"country\": \"United States\", \"countryCode\": \"US\", \"postalCode\": \"10002\", \"administrativeArea\": {\"name\": \"New York\", \"code\": \"NY\"}}, \"geometry\": {\"location\": {\"lat\": 40.7614, \"lng\": -73.9776}}}}]}" + } + }, + "output": { + "operations": [ + { + "add": { + "cost": null, + "metafields": [], + "pickupPoint": { + "address": { + "address1": "123 Main St", + "address2": null, + "city": "New York", + "country": "United States", + "countryCode": "US", + "latitude": 40.7589, + "longitude": -73.9851, + "phone": null, + "province": "New York", + "provinceCode": "NY", + "zip": "10001" + }, + "businessHours": null, + "externalId": "pickup1", + "name": "Pickup Location 1", + "provider": { + "logoUrl": "https://cdn.shopify.com/s/files/1/0628/3830/9033/files/shopify_icon_146101.png?v=1706120545", + "name": "Shopify Rust Demo" + } + } + } + }, + { + "add": { + "cost": null, + "metafields": [], + "pickupPoint": { + "address": { + "address1": "456 Oak Ave", + "address2": null, + "city": "New York", + "country": "United States", + "countryCode": "US", + "latitude": 40.7614, + "longitude": -73.9776, + "phone": null, + "province": "New York", + "provinceCode": "NY", + "zip": "10002" + }, + "businessHours": null, + "externalId": "pickup2", + "name": "Pickup Location 2", + "provider": { + "logoUrl": "https://cdn.shopify.com/s/files/1/0628/3830/9033/files/shopify_icon_146101.png?v=1706120545", + "name": "Shopify Rust Demo" + } + } + } + } + ] + } + } +} \ No newline at end of file diff --git a/functions-pickup-point-delivery-option-generators-wasm/tests/default.test.js b/functions-pickup-point-delivery-option-generators-wasm/tests/default.test.js new file mode 100644 index 00000000..fafb13be --- /dev/null +++ b/functions-pickup-point-delivery-option-generators-wasm/tests/default.test.js @@ -0,0 +1,40 @@ +import path from "path"; +import fs from "fs"; +import { describe, beforeAll, test, expect } from "vitest"; +import { buildFunction, loadFixture, runFunction, validateFixture } from "function-testing-helpers"; + +describe("Default Integration Test", () => { + beforeAll(async () => { + const functionDir = path.dirname(__dirname); + await buildFunction(functionDir); + }, 30000); // 30 second timeout for building the function + + const fixturesDir = path.join(__dirname, "fixtures"); + const fixtureFiles = fs + .readdirSync(fixturesDir) + .filter((file) => file.endsWith(".json")) + .map((file) => path.join(fixturesDir, file)); + + fixtureFiles.forEach((fixtureFile) => { + test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => { + const fixture = await loadFixture(fixtureFile); + + const functionDir = path.dirname(__dirname); + + const schemaPath = path.join(functionDir, "schema.graphql"); + const inputQueryPath = path.join(functionDir, "src/run.graphql"); + + await validateFixture(fixture); + + const runResult = await runFunction( + fixture.export, + fixture.input, + functionDir + ); + + const { result, error } = runResult; + expect(error).toBeNull(); + expect(result.output).toEqual(fixture.expectedOutput); + }, 10000); + }); +}); \ No newline at end of file diff --git a/functions-pickup-point-delivery-option-generators-wasm/tests/fixtures/log.json b/functions-pickup-point-delivery-option-generators-wasm/tests/fixtures/log.json new file mode 100644 index 00000000..0e3fc6f6 --- /dev/null +++ b/functions-pickup-point-delivery-option-generators-wasm/tests/fixtures/log.json @@ -0,0 +1,72 @@ +{ + "payload": { + "export": "run", + "target": "purchase.pickup-point-delivery-option-generator.run", + "input": { + "fetchResult": { + "status": 200, + "body": "{\"deliveryPoints\": [{\"pointId\": \"pickup1\", \"pointName\": \"Pickup Location 1\", \"location\": {\"addressComponents\": {\"streetNumber\": \"123\", \"route\": \"Main St\", \"locality\": \"New York\", \"country\": \"United States\", \"countryCode\": \"US\", \"postalCode\": \"10001\", \"administrativeArea\": {\"name\": \"New York\", \"code\": \"NY\"}}, \"geometry\": {\"location\": {\"lat\": 40.7589, \"lng\": -73.9851}}}}, {\"pointId\": \"pickup2\", \"pointName\": \"Pickup Location 2\", \"location\": {\"addressComponents\": {\"streetNumber\": \"456\", \"route\": \"Oak Ave\", \"locality\": \"New York\", \"country\": \"United States\", \"countryCode\": \"US\", \"postalCode\": \"10002\", \"administrativeArea\": {\"name\": \"New York\", \"code\": \"NY\"}}, \"geometry\": {\"location\": {\"lat\": 40.7614, \"lng\": -73.9776}}}}]}" + } + }, + "output": { + "operations": [ + { + "add": { + "cost": null, + "metafields": [], + "pickupPoint": { + "address": { + "address1": "123 Main St", + "address2": null, + "city": "New York", + "country": "United States", + "countryCode": "US", + "latitude": 40.7589, + "longitude": -73.9851, + "phone": null, + "province": "New York", + "provinceCode": "NY", + "zip": "10001" + }, + "businessHours": null, + "externalId": "pickup1", + "name": "Pickup Location 1", + "provider": { + "logoUrl": "https://cdn.shopify.com/s/files/1/0628/3830/9033/files/shopify_icon_146101.png?v=1706120545", + "name": "Shopify Rust Demo" + } + } + } + }, + { + "add": { + "cost": null, + "metafields": [], + "pickupPoint": { + "address": { + "address1": "456 Oak Ave", + "address2": null, + "city": "New York", + "country": "United States", + "countryCode": "US", + "latitude": 40.7614, + "longitude": -73.9776, + "phone": null, + "province": "New York", + "provinceCode": "NY", + "zip": "10002" + }, + "businessHours": null, + "externalId": "pickup2", + "name": "Pickup Location 2", + "provider": { + "logoUrl": "https://cdn.shopify.com/s/files/1/0628/3830/9033/files/shopify_icon_146101.png?v=1706120545", + "name": "Shopify Rust Demo" + } + } + } + } + ] + } + } +} \ No newline at end of file From ba7c9eaafa881ccd1ff55d7a2f9ed37c60b03416 Mon Sep 17 00:00:00 2001 From: Sagarika Dasgupta Date: Mon, 22 Sep 2025 15:13:17 -0500 Subject: [PATCH 2/2] Removing function unit tests in favor of wasm level tests --- .../cart_validations_generate_run.test.liquid | 118 ------ .../src/cart_validations_generate_run.rs | 63 --- .../src/cart_transform_run.test.liquid | 34 -- ...delivery_options_transform_run.test.liquid | 38 -- .../cart_delivery_options_transform_run.rs | 26 -- ...options_discounts_generate_run.test.liquid | 179 --------- ...t_lines_discounts_generate_run.test.liquid | 343 ----------------- .../src/run.test.liquid | 41 -- functions-discounts-allocator-rs/src/run.rs | 27 -- ...lment_constraints_generate_run.test.liquid | 58 --- ...rt_fulfillment_constraints_generate_run.rs | 35 -- .../src/run.test.liquid | 125 ------ .../src/run.rs | 67 ---- ...location_rankings_generate_run.test.liquid | 60 --- ...t_groups_location_rankings_generate_run.rs | 36 -- ..._payment_methods_transform_run.test.liquid | 38 -- .../src/cart_payment_methods_transform_run.rs | 24 -- .../src/fetch.test.liquid | 93 ----- .../src/run.test.liquid | 360 ------------------ .../src/fetch.rs | 63 --- .../src/run.rs | 244 ------------ 21 files changed, 2072 deletions(-) delete mode 100644 functions-cart-checkout-validation-js/src/cart_validations_generate_run.test.liquid delete mode 100644 functions-cart-transform-js/src/cart_transform_run.test.liquid delete mode 100644 functions-delivery-customization-js/src/cart_delivery_options_transform_run.test.liquid delete mode 100644 functions-discount-js/src/cart_delivery_options_discounts_generate_run.test.liquid delete mode 100644 functions-discount-js/src/cart_lines_discounts_generate_run.test.liquid delete mode 100644 functions-discounts-allocator-js/src/run.test.liquid delete mode 100644 functions-fulfillment-constraints-js/src/cart_fulfillment_constraints_generate_run.test.liquid delete mode 100644 functions-local-pickup-delivery-option-generators-js/src/run.test.liquid delete mode 100644 functions-location-rules-js/src/cart_fulfillment_groups_location_rankings_generate_run.test.liquid delete mode 100644 functions-payment-customization-js/src/cart_payment_methods_transform_run.test.liquid delete mode 100644 functions-pickup-point-delivery-option-generators-js/src/fetch.test.liquid delete mode 100644 functions-pickup-point-delivery-option-generators-js/src/run.test.liquid diff --git a/functions-cart-checkout-validation-js/src/cart_validations_generate_run.test.liquid b/functions-cart-checkout-validation-js/src/cart_validations_generate_run.test.liquid deleted file mode 100644 index b3942287..00000000 --- a/functions-cart-checkout-validation-js/src/cart_validations_generate_run.test.liquid +++ /dev/null @@ -1,118 +0,0 @@ -{%- if flavor contains "vanilla-js" -%} -import { describe, it, expect } from 'vitest'; -import { cartValidationsGenerateRun } from './cart_validations_generate_run'; - -/** - * @typedef {import("../generated/api").CartValidationsGenerateRunResult} CartValidationsGenerateRunResult - */ - -describe('cart checkout validation function', () => { - it('returns an error when quantity exceeds one', () => { - const result = cartValidationsGenerateRun({ - cart: { - lines: [ - { - quantity: 3 - } - ] - } - }); - const expected = /** @type {CartValidationsGenerateRunResult} */ ({ - operations: [ - { - validationAdd: { - errors: [ - { - message: "Not possible to order more than one of each", - target: "$.cart" - } - ] - } - } - ] - }); - - expect(result).toEqual(expected); - }); - - it('returns no errors when quantity is one', () => { - const result = cartValidationsGenerateRun({ - cart: { - lines: [ - { - quantity: 1 - } - ] - } - }); - const expected = /** @type {CartValidationsGenerateRunResult} */ ({ - operations: [ - { - validationAdd: { - errors: [] - } - } - ] - }); - - expect(result).toEqual(expected); - }); -}); -{%- elsif flavor contains "typescript" -%} -import { describe, it, expect } from 'vitest'; -import { cartValidationsGenerateRun } from './cart_validations_generate_run'; -import { CartValidationsGenerateRunResult } from "../generated/api"; - -describe('cart checkout validation function', () => { - it('returns an error when quantity exceeds one', () => { - const result = cartValidationsGenerateRun({ - cart: { - lines: [ - { - quantity: 3 - } - ] - } - }); - const expected: CartValidationsGenerateRunResult = { - operations: [ - { - validationAdd: { - errors: [ - { - message: "Not possible to order more than one of each", - target: "$.cart" - } - ] - } - } - ] - }; - - expect(result).toEqual(expected); - }); - - it('returns no errors when quantity is one', () => { - const result = cartValidationsGenerateRun({ - cart: { - lines: [ - { - quantity: 1 - } - ] - } - }); - const expected: CartValidationsGenerateRunResult = { - operations: [ - { - validationAdd: { - errors: [] - } - } - ] - }; - - expect(result).toEqual(expected); - }); -}); -{%- endif -%} diff --git a/functions-cart-checkout-validation-rs/src/cart_validations_generate_run.rs b/functions-cart-checkout-validation-rs/src/cart_validations_generate_run.rs index 92f161d4..6e7dac41 100644 --- a/functions-cart-checkout-validation-rs/src/cart_validations_generate_run.rs +++ b/functions-cart-checkout-validation-rs/src/cart_validations_generate_run.rs @@ -26,66 +26,3 @@ fn cart_validations_generate_run( Ok(schema::CartValidationsGenerateRunResult { operations }) } - -#[cfg(test)] -mod tests { - use super::*; - use shopify_function::{run_function_with_input, Result}; - - #[test] - fn test_result_contains_single_error_when_quantity_exceeds_one() -> Result<()> { - let result = run_function_with_input( - cart_validations_generate_run, - r#" - { - "cart": { - "lines": [ - { - "quantity": 3 - } - ] - } - } - "#, - )?; - let expected = schema::CartValidationsGenerateRunResult { - operations: vec![schema::Operation::ValidationAdd( - schema::ValidationAddOperation { - errors: vec![schema::ValidationError { - message: "Not possible to order more than one of each".to_owned(), - target: "$.cart".to_owned(), - }], - }, - )], - }; - - assert_eq!(result, expected); - Ok(()) - } - - #[test] - fn test_result_contains_no_errors_when_quantity_is_one() -> Result<()> { - let result = run_function_with_input( - cart_validations_generate_run, - r#" - { - "cart": { - "lines": [ - { - "quantity": 1 - } - ] - } - } - "#, - )?; - let expected = schema::CartValidationsGenerateRunResult { - operations: vec![schema::Operation::ValidationAdd( - schema::ValidationAddOperation { errors: vec![] }, - )], - }; - - assert_eq!(result, expected); - Ok(()) - } -} diff --git a/functions-cart-transform-js/src/cart_transform_run.test.liquid b/functions-cart-transform-js/src/cart_transform_run.test.liquid deleted file mode 100644 index d3f4e92a..00000000 --- a/functions-cart-transform-js/src/cart_transform_run.test.liquid +++ /dev/null @@ -1,34 +0,0 @@ -{%- if flavor contains "vanilla-js" -%} -import { describe, it, expect } from 'vitest'; -import { cartTransformRun } from './cart_transform_run'; - -/** - * @typedef {import("../generated/api").CartTransformRunResult} CartTransformRunResult - */ - -describe('cart transform function', () => { - it('returns no operations', () => { - const result = cartTransformRun({}); - const expected = /** @type {CartTransformRunResult} */ ({ operations: [] }); - - expect(result).toEqual(expected); - }); -}); -{%- elsif flavor contains "typescript" -%} -import { describe, it, expect } from 'vitest'; -import { cartTransformRun } from './cart_transform_run'; -import { CartTransformRunResult } from '../generated/api'; - -describe('cart transform function', () => { - it('returns no operations', () => { - const result = cartTransformRun({ - cart: { - lines: [] - } - }); - const expected: CartTransformRunResult = { operations: [] }; - - expect(result).toEqual(expected); - }); -}); -{%- endif -%} diff --git a/functions-delivery-customization-js/src/cart_delivery_options_transform_run.test.liquid b/functions-delivery-customization-js/src/cart_delivery_options_transform_run.test.liquid deleted file mode 100644 index 904796af..00000000 --- a/functions-delivery-customization-js/src/cart_delivery_options_transform_run.test.liquid +++ /dev/null @@ -1,38 +0,0 @@ -{%- if flavor contains "vanilla-js" -%} -import { describe, it, expect } from 'vitest'; -import { cartDeliveryOptionsTransformRun } from './cart_delivery_options_transform_run'; - -/** - * @typedef {import("../generated/api").CartDeliveryOptionsTransformRunResult} CartDeliveryOptionsTransformRunResult - */ - -describe('delivery customization function', () => { - it('returns no operations without configuration', () => { - const result = cartDeliveryOptionsTransformRun({ - deliveryCustomization: { - metafield: null - } - }); - const expected = /** @type {CartDeliveryOptionsTransformRunResult} */ ({ operations: [] }); - - expect(result).toEqual(expected); - }); -}); -{%- elsif flavor contains "typescript" -%} -import { describe, it, expect } from 'vitest'; -import { cartDeliveryOptionsTransformRun } from './cart_delivery_options_transform_run'; -import { CartDeliveryOptionsTransformRunResult } from '../generated/api'; - -describe('delivery customization function', () => { - it('returns no operations without configuration', () => { - const result = cartDeliveryOptionsTransformRun({ - deliveryCustomization: { - metafield: null - } - }); - const expected: CartDeliveryOptionsTransformRunResult = { operations: [] }; - - expect(result).toEqual(expected); - }); -}); -{% endif -%} diff --git a/functions-delivery-customization-rs/src/cart_delivery_options_transform_run.rs b/functions-delivery-customization-rs/src/cart_delivery_options_transform_run.rs index 4fa85d0d..57778782 100644 --- a/functions-delivery-customization-rs/src/cart_delivery_options_transform_run.rs +++ b/functions-delivery-customization-rs/src/cart_delivery_options_transform_run.rs @@ -19,29 +19,3 @@ fn cart_delivery_options_transform_run( Ok(schema::CartDeliveryOptionsTransformRunResult { operations: vec![] }) } - -#[cfg(test)] -mod tests { - use super::*; - use shopify_function::{run_function_with_input, Result}; - - #[test] - fn test_result_contains_no_operations() -> Result<()> { - use schema::CartDeliveryOptionsTransformRunResult; - - let result = run_function_with_input( - cart_delivery_options_transform_run, - r#" - { - "deliveryCustomization": { - "metafield": null - } - } - "#, - )?; - let expected = CartDeliveryOptionsTransformRunResult { operations: vec![] }; - - assert_eq!(result, expected); - Ok(()) - } -} diff --git a/functions-discount-js/src/cart_delivery_options_discounts_generate_run.test.liquid b/functions-discount-js/src/cart_delivery_options_discounts_generate_run.test.liquid deleted file mode 100644 index a34f21ae..00000000 --- a/functions-discount-js/src/cart_delivery_options_discounts_generate_run.test.liquid +++ /dev/null @@ -1,179 +0,0 @@ -{%- if flavor contains "vanilla-js" -%} -import {describe, it, expect} from "vitest"; - -import {cartDeliveryOptionsDiscountsGenerateRun} from "./cart_delivery_options_discounts_generate_run"; -import { - DeliveryDiscountSelectionStrategy, - DiscountClass, -} from "../generated/api"; - -/** - * @typedef {import("../generated/api").CartDeliveryOptionsDiscountsGenerateRunResult} CartDeliveryOptionsDiscountsGenerateRunResult - * @typedef {import("../generated/api").DeliveryInput} DeliveryInput - */ - -describe("cartDeliveryOptionsDiscountsGenerateRun", () => { - const baseInput = { - cart: { - deliveryGroups: [ - { - id: "gid://shopify/DeliveryGroup/0", - }, - ], - }, - discount: { - discountClasses: [], - }, - }; - - it("returns empty operations when no discount classes are present", () => { - const input = { - ...baseInput, - discount: { - discountClasses: [], - }, - }; - - const result = cartDeliveryOptionsDiscountsGenerateRun(input); - expect(result.operations).toHaveLength(0); - }); - - it("returns delivery discount when shipping discount class is present", () => { - const input = { - ...baseInput, - discount: { - discountClasses: [DiscountClass.Shipping], - }, - }; - - const result = cartDeliveryOptionsDiscountsGenerateRun(input); - expect(result.operations).toHaveLength(1); - expect(result.operations[0]).toMatchObject({ - deliveryDiscountsAdd: { - candidates: [ - { - message: "FREE DELIVERY", - targets: [ - { - deliveryGroup: { - id: "gid://shopify/DeliveryGroup/0", - }, - }, - ], - value: { - percentage: { - value: 100, - }, - }, - }, - ], - selectionStrategy: DeliveryDiscountSelectionStrategy.All, - }, - }); - }); - - it("throws error when no delivery groups are present", () => { - const input = { - cart: { - deliveryGroups: [], - }, - discount: { - discountClasses: [DiscountClass.Shipping], - }, - }; - - expect(() => cartDeliveryOptionsDiscountsGenerateRun(input)).toThrow( - "No delivery groups found", - ); - }); -}); -{%- elsif flavor contains "typescript" -%} -import {describe, it, expect} from "vitest"; - -import {cartDeliveryOptionsDiscountsGenerateRun} from "./cart_delivery_options_discounts_generate_run"; -import { - DeliveryDiscountSelectionStrategy, - DiscountClass, - DeliveryInput, - CartDeliveryOptionsDiscountsGenerateRunResult, -} from "../generated/api"; - -describe("cartDeliveryOptionsDiscountsGenerateRun", () => { - const baseInput: DeliveryInput = { - cart: { - deliveryGroups: [ - { - id: "gid://shopify/DeliveryGroup/0", - }, - ], - }, - discount: { - discountClasses: [], - }, - }; - - it("returns empty operations when no discount classes are present", () => { - const input: DeliveryInput = { - ...baseInput, - discount: { - discountClasses: [], - }, - }; - - const result: CartDeliveryOptionsDiscountsGenerateRunResult = - cartDeliveryOptionsDiscountsGenerateRun(input); - expect(result.operations).toHaveLength(0); - }); - - it("returns delivery discount when shipping discount class is present", () => { - const input: DeliveryInput = { - ...baseInput, - discount: { - discountClasses: [DiscountClass.Shipping], - }, - }; - - const result: CartDeliveryOptionsDiscountsGenerateRunResult = - cartDeliveryOptionsDiscountsGenerateRun(input); - expect(result.operations).toHaveLength(1); - expect(result.operations[0]).toMatchObject({ - deliveryDiscountsAdd: { - candidates: [ - { - message: "FREE DELIVERY", - targets: [ - { - deliveryGroup: { - id: "gid://shopify/DeliveryGroup/0", - }, - }, - ], - value: { - percentage: { - value: 100, - }, - }, - }, - ], - selectionStrategy: DeliveryDiscountSelectionStrategy.All, - }, - }); - }); - - it("throws error when no delivery groups are present", () => { - const input: DeliveryInput = { - cart: { - deliveryGroups: [], - }, - discount: { - discountClasses: [DiscountClass.Shipping], - }, - }; - - expect(() => cartDeliveryOptionsDiscountsGenerateRun(input)).toThrow( - "No delivery groups found", - ); - }); -}); - -{%- endif -%} diff --git a/functions-discount-js/src/cart_lines_discounts_generate_run.test.liquid b/functions-discount-js/src/cart_lines_discounts_generate_run.test.liquid deleted file mode 100644 index 3aafe88f..00000000 --- a/functions-discount-js/src/cart_lines_discounts_generate_run.test.liquid +++ /dev/null @@ -1,343 +0,0 @@ -{%- if flavor contains "vanilla-js" -%} -import {describe, it, expect} from "vitest"; - -import {cartLinesDiscountsGenerateRun} from "./cart_lines_discounts_generate_run"; -import { - OrderDiscountSelectionStrategy, - ProductDiscountSelectionStrategy, - DiscountClass, -} from "../generated/api"; - -/** - * @typedef {import("../generated/api").CartLinesDiscountsGenerateRunResult} CartLinesDiscountsGenerateRunResult - */ - -describe("cartLinesDiscountsGenerateRun", () => { - const baseInput = { - cart: { - lines: [ - { - id: "gid://shopify/CartLine/0", - cost: { - subtotalAmount: { - amount: 100, - }, - }, - }, - ], - }, - discount: { - discountClasses: [], - }, - }; - - it("returns empty operations when no discount classes are present", () => { - const input = { - ...baseInput, - discount: { - discountClasses: [], - }, - }; - - const result = cartLinesDiscountsGenerateRun(input); - expect(result.operations).toHaveLength(0); - }); - - it("returns only order discount when only order discount class is present", () => { - const input = { - ...baseInput, - discount: { - discountClasses: [DiscountClass.Order], - }, - }; - - const result = cartLinesDiscountsGenerateRun(input); - expect(result.operations).toHaveLength(1); - expect(result.operations[0]).toMatchObject({ - orderDiscountsAdd: { - candidates: [ - { - message: "10% OFF ORDER", - targets: [ - { - orderSubtotal: { - excludedCartLineIds: [], - }, - }, - ], - value: { - percentage: { - value: 10, - }, - }, - }, - ], - selectionStrategy: OrderDiscountSelectionStrategy.First, - }, - }); - }); - - it("returns only product discount when only product discount class is present", () => { - const input = { - ...baseInput, - discount: { - discountClasses: [DiscountClass.Product], - }, - }; - - const result = cartLinesDiscountsGenerateRun(input); - expect(result.operations).toHaveLength(1); - expect(result.operations[0]).toMatchObject({ - productDiscountsAdd: { - candidates: [ - { - message: "20% OFF PRODUCT", - targets: [ - { - cartLine: { - id: "gid://shopify/CartLine/0", - }, - }, - ], - value: { - percentage: { - value: 20, - }, - }, - }, - ], - selectionStrategy: ProductDiscountSelectionStrategy.First, - }, - }); - }); - - it("returns both discounts when both discount classes are present", () => { - const input = { - ...baseInput, - discount: { - discountClasses: [DiscountClass.Order, DiscountClass.Product], - }, - }; - - const result = cartLinesDiscountsGenerateRun(input); - expect(result.operations).toHaveLength(2); - expect(result.operations[0]).toMatchObject({ - orderDiscountsAdd: { - candidates: [ - { - message: "10% OFF ORDER", - targets: [ - { - orderSubtotal: { - excludedCartLineIds: [], - }, - }, - ], - value: { - percentage: { - value: 10, - }, - }, - }, - ], - selectionStrategy: OrderDiscountSelectionStrategy.First, - }, - }); - - expect(result.operations[1]).toMatchObject({ - productDiscountsAdd: { - candidates: [ - { - message: "20% OFF PRODUCT", - targets: [ - { - cartLine: { - id: "gid://shopify/CartLine/0", - }, - }, - ], - value: { - percentage: { - value: 20, - }, - }, - }, - ], - selectionStrategy: ProductDiscountSelectionStrategy.First, - }, - }); - }); -}); -{%- elsif flavor contains "typescript" -%} -import {describe, it, expect} from "vitest"; - -import {cartLinesDiscountsGenerateRun} from "./cart_lines_discounts_generate_run"; -import { - OrderDiscountSelectionStrategy, - ProductDiscountSelectionStrategy, - DiscountClass, - CartInput, - CartLinesDiscountsGenerateRunResult, -} from "../generated/api"; - -describe("cartLinesDiscountsGenerateRun", () => { - const baseInput: CartInput = { - cart: { - lines: [ - { - id: "gid://shopify/CartLine/0", - cost: { - subtotalAmount: { - amount: 100, - }, - }, - }, - ], - }, - discount: { - discountClasses: [], - }, - }; - - it("returns empty operations when no discount classes are present", () => { - const input: CartInput = { - ...baseInput, - discount: { - discountClasses: [], - }, - }; - - const result: CartLinesDiscountsGenerateRunResult = - cartLinesDiscountsGenerateRun(input); - expect(result.operations).toHaveLength(0); - }); - - it("returns only order discount when only order discount class is present", () => { - const input: CartInput = { - ...baseInput, - discount: { - discountClasses: [DiscountClass.Order], - }, - }; - - const result: CartLinesDiscountsGenerateRunResult = - cartLinesDiscountsGenerateRun(input); - expect(result.operations).toHaveLength(1); - expect(result.operations[0]).toMatchObject({ - orderDiscountsAdd: { - candidates: [ - { - message: "10% OFF ORDER", - targets: [ - { - orderSubtotal: { - excludedCartLineIds: [], - }, - }, - ], - value: { - percentage: { - value: 10, - }, - }, - }, - ], - selectionStrategy: OrderDiscountSelectionStrategy.First, - }, - }); - }); - - it("returns only product discount when only product discount class is present", () => { - const input: CartInput = { - ...baseInput, - discount: { - discountClasses: [DiscountClass.Product], - }, - }; - - const result: CartLinesDiscountsGenerateRunResult = - cartLinesDiscountsGenerateRun(input); - expect(result.operations).toHaveLength(1); - expect(result.operations[0]).toMatchObject({ - productDiscountsAdd: { - candidates: [ - { - message: "20% OFF PRODUCT", - targets: [ - { - cartLine: { - id: "gid://shopify/CartLine/0", - }, - }, - ], - value: { - percentage: { - value: 20, - }, - }, - }, - ], - selectionStrategy: ProductDiscountSelectionStrategy.First, - }, - }); - }); - - it("returns both discounts when both discount classes are present", () => { - const input: CartInput = { - ...baseInput, - discount: { - discountClasses: [DiscountClass.Order, DiscountClass.Product], - }, - }; - - const result: CartLinesDiscountsGenerateRunResult = - cartLinesDiscountsGenerateRun(input); - expect(result.operations).toHaveLength(2); - expect(result.operations[0]).toMatchObject({ - orderDiscountsAdd: { - candidates: [ - { - message: "10% OFF ORDER", - targets: [ - { - orderSubtotal: { - excludedCartLineIds: [], - }, - }, - ], - value: { - percentage: { - value: 10, - }, - }, - }, - ], - selectionStrategy: OrderDiscountSelectionStrategy.First, - }, - }); - - expect(result.operations[1]).toMatchObject({ - productDiscountsAdd: { - candidates: [ - { - message: "20% OFF PRODUCT", - targets: [ - { - cartLine: { - id: "gid://shopify/CartLine/0", - }, - }, - ], - value: { - percentage: { - value: 20, - }, - }, - }, - ], - selectionStrategy: ProductDiscountSelectionStrategy.First, - }, - }); - }); -}); -{%- endif -%} diff --git a/functions-discounts-allocator-js/src/run.test.liquid b/functions-discounts-allocator-js/src/run.test.liquid deleted file mode 100644 index 970c34ff..00000000 --- a/functions-discounts-allocator-js/src/run.test.liquid +++ /dev/null @@ -1,41 +0,0 @@ -{%- if flavor contains "vanilla-js" -%} -import {describe, it, expect} from 'vitest'; -import {run} from './run'; -import Decimal from 'decimal.js'; - -describe('discounts allocator function', () => { - it('returns no discounts without configuration', () => { - const result = run({ - shop: { - metafield: null - } - }); - const expected = { - displayableErrors: [], - lineDiscounts: [], - }; - - expect(result).toEqual(expected); - }); -}); -{%- elsif flavor contains "typescript" -%} -import {describe, it, expect} from 'vitest'; -import {run} from './run'; -import Decimal from 'decimal.js'; - -describe('discounts allocator function', () => { - it('returns no discounts without configuration', () => { - const result = run({ - shop: { - metafield: null - } - }); - const expected: FunctionResult = { - displayableErrors: [], - lineDiscounts: [], - }; - - expect(result).toEqual(expected); - }); -}); -{%- endif -%} diff --git a/functions-discounts-allocator-rs/src/run.rs b/functions-discounts-allocator-rs/src/run.rs index 7126b166..717ddcfb 100644 --- a/functions-discounts-allocator-rs/src/run.rs +++ b/functions-discounts-allocator-rs/src/run.rs @@ -11,30 +11,3 @@ fn run(_input: schema::run::Input) -> Result { Ok(no_discounts) } - -#[cfg(test)] -mod tests { - use super::*; - use shopify_function::run_function_with_input; - - #[test] - fn test_result_with_no_discounts() -> Result<()> { - let result = run_function_with_input( - run, - r#" - { - "shop": { - "metafield": null - } - } - "#, - )?; - let expected = schema::FunctionRunResult { - line_discounts: Some(vec![]), - displayable_errors: Some(vec![]), - }; - - assert_eq!(result, expected); - Ok(()) - } -} diff --git a/functions-fulfillment-constraints-js/src/cart_fulfillment_constraints_generate_run.test.liquid b/functions-fulfillment-constraints-js/src/cart_fulfillment_constraints_generate_run.test.liquid deleted file mode 100644 index 34f0df73..00000000 --- a/functions-fulfillment-constraints-js/src/cart_fulfillment_constraints_generate_run.test.liquid +++ /dev/null @@ -1,58 +0,0 @@ -{%- if flavor contains "vanilla-js" -%} -import { describe, it, expect } from 'vitest'; -import { cartFulfillmentConstraintsGenerateRun } from './cart_fulfillment_constraints_generate_run'; - -/** - * @typedef {import("../generated/api").CartFulfillmentConstraintsGenerateRunResult} CartFulfillmentConstraintsGenerateRunResult - */ - -describe('fulfillment constraint rule function', () => { - it('returns no operations without configuration', () => { - const result = cartFulfillmentConstraintsGenerateRun({ - cart: { - deliverableLines: [ - { - id: "gid://shopify/DeliverableCartLine/1" - }, - { - id: "gid://shopify/DeliverableCartLine/2" - } - ] - }, - fulfillmentConstraintRule: { - metafield: null - } - }); - const expected = /** @type {CartFulfillmentConstraintsGenerateRunResult} */ ({ operations: [] }); - - expect(result).toEqual(expected); - }); -}); -{%- elsif flavor contains "typescript" -%} -import { describe, it, expect } from 'vitest'; -import { cartFulfillmentConstraintsGenerateRun } from './cart_fulfillment_constraints_generate_run'; -import { CartFulfillmentConstraintsGenerateRunResult } from '../generated/api'; - -describe('fulfillment constraint rule function', () => { - it('returns no operations without configuration', () => { - const result = cartFulfillmentConstraintsGenerateRun({ - cart: { - deliverableLines: [ - { - id: "gid://shopify/DeliverableCartLine/1" - }, - { - id: "gid://shopify/DeliverableCartLine/2" - } - ] - }, - fulfillmentConstraintRule: { - metafield: null - } - }); - const expected: CartFulfillmentConstraintsGenerateRunResult = { operations: [] }; - - expect(result).toEqual(expected); - }); -}); -{%- endif -%} \ No newline at end of file diff --git a/functions-fulfillment-constraints-rs/src/cart_fulfillment_constraints_generate_run.rs b/functions-fulfillment-constraints-rs/src/cart_fulfillment_constraints_generate_run.rs index 9f39edce..4edceebf 100644 --- a/functions-fulfillment-constraints-rs/src/cart_fulfillment_constraints_generate_run.rs +++ b/functions-fulfillment-constraints-rs/src/cart_fulfillment_constraints_generate_run.rs @@ -12,38 +12,3 @@ fn cart_fulfillment_constraints_generate_run( Ok(schema::CartFulfillmentConstraintsGenerateRunResult { operations }) } - -#[cfg(test)] -mod tests { - use super::*; - use shopify_function::{run_function_with_input, Result}; - - #[test] - fn test_result_contains_no_operations() -> Result<()> { - let result = run_function_with_input( - cart_fulfillment_constraints_generate_run, - r#" - { - "cart": { - "deliverableLines": [ - { - "id": "gid://shopify/DeliverableCartLine/1" - }, - { - "id": "gid://shopify/DeliverableCartLine/2" - } - ] - }, - "fulfillmentConstraintRule": { - "metafield": null - } - } - "#, - )?; - - let expected = schema::CartFulfillmentConstraintsGenerateRunResult { operations: vec![] }; - - assert_eq!(result, expected); - Ok(()) - } -} diff --git a/functions-local-pickup-delivery-option-generators-js/src/run.test.liquid b/functions-local-pickup-delivery-option-generators-js/src/run.test.liquid deleted file mode 100644 index 30c67421..00000000 --- a/functions-local-pickup-delivery-option-generators-js/src/run.test.liquid +++ /dev/null @@ -1,125 +0,0 @@ -{%- if flavor contains "vanilla-js" -%} -import { describe, it, expect } from 'vitest'; -import { run } from './run'; - -/** - * @typedef {import("../generated/api").RunInput} RunInput - * @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult - */ - -describe('local pickup delivery option generator function', () => { - it('returns a delivery option', () => { - const result = run({ - cart: { - lines: [ - { - id: "gid://shopify/CartLine/1" - } - ] - }, - fulfillmentGroups: [ - { - handle: "1", - lines: [ - { - id: "gid://shopify/CartLine/1" - } - ], - deliveryGroup: { - id: "gid://shopify/CartDeliveryGroup/1" - }, - inventoryLocationHandles: ["2578303"] - } - ], - locations: [ - { - handle: "2578303", - name: "Main St.", - address: { - address1: "123 Main St." - } - } - ], - deliveryOptionGenerator: { - metafield: null - } - }); - const expected = /** @type {FunctionRunResult} */ ({ - operations: [ - { - add: { - title: "Main St.", - cost: 1.99, - pickupLocation: { - locationHandle: "2578303", - pickupInstruction: "Usually ready in 24 hours." - }, - }, - }, - ] - }); - - expect(result).toEqual(expected); - }); -}); -{%- elsif flavor contains "typescript" -%} -import { describe, it, expect } from 'vitest'; -import { run } from './run'; -import { RunInput, FunctionRunResult } from '../generated/api'; - -describe('local pickup delivery option generator function', () => { - it('returns a delivery option', () => { - const result = run({ - cart: { - lines: [ - { - id: "gid://shopify/CartLine/1" - } - ] - }, - fulfillmentGroups: [ - { - handle: "1", - lines: [ - { - id: "gid://shopify/CartLine/1" - } - ], - deliveryGroup: { - id: "gid://shopify/CartDeliveryGroup/1" - }, - inventoryLocationHandles: ["2578303"] - } - ], - locations: [ - { - handle: "2578303", - name: "Main St.", - address: { - address1: "123 Main St." - } - } - ], - deliveryOptionGenerator: { - metafield: null - } - }); - const expected: FunctionRunResult = { - operations: [ - { - add: { - title: "Main St.", - cost: 1.99, - pickupLocation: { - locationHandle: "2578303", - pickupInstruction: "Usually ready in 24 hours." - } - } - } - ] - }; - - expect(result).toEqual(expected); - }); -}); -{%- endif -%} diff --git a/functions-local-pickup-delivery-option-generators-rs/src/run.rs b/functions-local-pickup-delivery-option-generators-rs/src/run.rs index 7105d6e4..c5240426 100644 --- a/functions-local-pickup-delivery-option-generators-rs/src/run.rs +++ b/functions-local-pickup-delivery-option-generators-rs/src/run.rs @@ -20,70 +20,3 @@ fn run(_input: schema::run::Input) -> Result { Ok(schema::FunctionRunResult { operations }) } - -#[cfg(test)] -mod tests { - use super::*; - use shopify_function::{run_function_with_input, Result}; - - #[test] - fn test_result_contains_no_operations() -> Result<()> { - let result = run_function_with_input( - run, - r#" - { - "cart": { - "lines": [ - { - "id": "gid://shopify/CartLine/1" - } - ] - }, - "fulfillmentGroups": [ - { - "handle": "1", - "lines": [ - { - "id": "gid://shopify/CartLine/1" - } - ], - "deliveryGroup": { - "id": "gid://shopify/CartDeliveryGroup/1" - }, - "inventoryLocationHandles": ["2578303"] - } - ], - "locations": [ - { - "handle": "2578303", - "name": "Main St.", - "address": { - "address1": "123 Main St." - } - } - ], - "deliveryOptionGenerator": { - "metafield": null - } - } - "#, - )?; - - let operations = vec![schema::Operation { - add: schema::LocalPickupDeliveryOption { - title: Some("Main St.".to_string()), - cost: Some(Decimal(1.99)), - pickup_location: schema::PickupLocation { - location_handle: "2578303".to_string(), - pickup_instruction: Some("Usually ready in 24 hours.".to_string()), - }, - metafields: None, - }, - }]; - - let expected = schema::FunctionRunResult { operations }; - - assert_eq!(result, expected); - Ok(()) - } -} diff --git a/functions-location-rules-js/src/cart_fulfillment_groups_location_rankings_generate_run.test.liquid b/functions-location-rules-js/src/cart_fulfillment_groups_location_rankings_generate_run.test.liquid deleted file mode 100644 index dbec1816..00000000 --- a/functions-location-rules-js/src/cart_fulfillment_groups_location_rankings_generate_run.test.liquid +++ /dev/null @@ -1,60 +0,0 @@ -{%- if flavor contains "vanilla-js" -%} -import { describe, it, expect } from 'vitest'; -import { cartFulfillmentGroupsLocationRankingsGenerateRun } from './cart_fulfillment_groups_location_rankings_generate_run'; - -/** - * @typedef {import("../generated/api").CartFulfillmentGroupsLocationRankingsGenerateRunResult} CartFulfillmentGroupsLocationRankingsGenerateRunResult - */ - -describe('order routing location rule function', () => { - it('returns rank operations with all locations rank 0', () => { - const result = cartFulfillmentGroupsLocationRankingsGenerateRun({ - "fulfillmentGroups": [{ - "handle": "123", - "inventoryLocationHandles": ["456"] - }] - }); - const expected = /** @type {CartFulfillmentGroupsLocationRankingsGenerateRunResult} */ ({ - operations: [{ - fulfillmentGroupLocationRankingAdd: { - fulfillmentGroupHandle: "123", - rankings: [{ - locationHandle: "456", - rank: 0 - }] - } - }] - }); - - expect(result).toEqual(expected); - }); -}); -{%- elsif flavor contains "typescript" -%} -import { describe, it, expect } from 'vitest'; -import { cartFulfillmentGroupsLocationRankingsGenerateRun } from './cart_fulfillment_groups_location_rankings_generate_run'; -import { CartFulfillmentGroupsLocationRankingsGenerateRunResult } from '../generated/api'; - -describe('order routing location rule function', () => { - it('returns rank operations with all locations rank 0', () => { - const result = cartFulfillmentGroupsLocationRankingsGenerateRun({ - fulfillmentGroups: [{ - handle: "123", - inventoryLocationHandles: ["456"] - }] - }); - const expected: CartFulfillmentGroupsLocationRankingsGenerateRunResult = { - operations: [{ - fulfillmentGroupLocationRankingAdd: { - fulfillmentGroupHandle: "123", - rankings: [{ - locationHandle: "456", - rank: 0 - }] - } - }] - }; - - expect(result).toEqual(expected); - }); -}); -{%- endif -%} diff --git a/functions-location-rules-rs/src/cart_fulfillment_groups_location_rankings_generate_run.rs b/functions-location-rules-rs/src/cart_fulfillment_groups_location_rankings_generate_run.rs index 94eb0619..ea5514c1 100644 --- a/functions-location-rules-rs/src/cart_fulfillment_groups_location_rankings_generate_run.rs +++ b/functions-location-rules-rs/src/cart_fulfillment_groups_location_rankings_generate_run.rs @@ -30,39 +30,3 @@ fn cart_fulfillment_groups_location_rankings_generate_run( Ok(schema::CartFulfillmentGroupsLocationRankingsGenerateRunResult { operations }) } - -#[cfg(test)] -mod tests { - use super::schema; - use crate::cart_fulfillment_groups_location_rankings_generate_run::cart_fulfillment_groups_location_rankings_generate_run; - use shopify_function::{run_function_with_input, Result}; - - #[test] - fn test_result_ranks_all_locations_zero() -> Result<()> { - let result = run_function_with_input( - cart_fulfillment_groups_location_rankings_generate_run, - r#" - { - "fulfillmentGroups": [{ - "handle": "123", - "inventoryLocationHandles": ["456"] - }] - } - "#, - )?; - let expected = schema::CartFulfillmentGroupsLocationRankingsGenerateRunResult { - operations: vec![schema::Operation::FulfillmentGroupLocationRankingAdd( - schema::FulfillmentGroupLocationRankingAddOperation { - fulfillment_group_handle: "123".to_string(), - rankings: vec![schema::RankedLocation { - location_handle: "456".to_string(), - rank: 0, - }], - }, - )], - }; - - assert_eq!(result, expected); - Ok(()) - } -} diff --git a/functions-payment-customization-js/src/cart_payment_methods_transform_run.test.liquid b/functions-payment-customization-js/src/cart_payment_methods_transform_run.test.liquid deleted file mode 100644 index 15e66eb0..00000000 --- a/functions-payment-customization-js/src/cart_payment_methods_transform_run.test.liquid +++ /dev/null @@ -1,38 +0,0 @@ -{%- if flavor contains "vanilla-js" -%} -import { describe, it, expect } from 'vitest'; -import { cartPaymentMethodsTransformRun } from './cart_payment_methods_transform_run'; - -/** - * @typedef {import("../generated/api").CartPaymentMethodsTransformRunResult} CartPaymentMethodsTransformRunResult - */ - -describe('payment customization function', () => { - it('returns no operations without configuration', () => { - const result = cartPaymentMethodsTransformRun({ - paymentCustomization: { - metafield: null - } - }); - const expected = /** @type {CartPaymentMethodsTransformRunResult} */ ({ operations: [] }); - - expect(result).toEqual(expected); - }); -}); -{%- elsif flavor contains "typescript" -%} -import { describe, it, expect } from 'vitest'; -import { cartPaymentMethodsTransformRun } from './cart_payment_methods_transform_run'; -import { CartPaymentMethodsTransformRunResult } from '../generated/api'; - -describe('payment customization function', () => { - it('returns no operations without configuration', () => { - const result = cartPaymentMethodsTransformRun({ - paymentCustomization: { - metafield: null - } - }); - const expected: CartPaymentMethodsTransformRunResult = { operations: [] }; - - expect(result).toEqual(expected); - }); -}); -{%- endif -%} diff --git a/functions-payment-customization-rs/src/cart_payment_methods_transform_run.rs b/functions-payment-customization-rs/src/cart_payment_methods_transform_run.rs index ded3134c..3e6df00d 100644 --- a/functions-payment-customization-rs/src/cart_payment_methods_transform_run.rs +++ b/functions-payment-customization-rs/src/cart_payment_methods_transform_run.rs @@ -19,27 +19,3 @@ fn cart_payment_methods_transform_run( Ok(schema::CartPaymentMethodsTransformRunResult { operations: vec![] }) } - -#[cfg(test)] -mod tests { - use super::*; - use shopify_function::{run_function_with_input, Result}; - - #[test] - fn test_result_contains_no_operations() -> Result<()> { - let result = run_function_with_input( - cart_payment_methods_transform_run, - r#" - { - "paymentCustomization": { - "metafield": null - } - } - "#, - )?; - let expected = schema::CartPaymentMethodsTransformRunResult { operations: vec![] }; - - assert_eq!(result, expected); - Ok(()) - } -} diff --git a/functions-pickup-point-delivery-option-generators-js/src/fetch.test.liquid b/functions-pickup-point-delivery-option-generators-js/src/fetch.test.liquid deleted file mode 100644 index 84f8939a..00000000 --- a/functions-pickup-point-delivery-option-generators-js/src/fetch.test.liquid +++ /dev/null @@ -1,93 +0,0 @@ -{%- if flavor contains "vanilla-js" -%} -import { describe, it, expect } from 'vitest'; -import { fetch } from './fetch'; - -/** - * @typedef {import("../generated/api").FunctionFetchResult} FunctionFetchResult - */ - -describe('fetch function', () => { - it('returns a request when country is Canada', () => { - const result = fetch({ - deliveryAddress: { - countryCode: 'CA', - longitude: 12.3, - latitude: 45.6, - } - }); - const expected = ({ - request: { - body: null, - headers: [ - { name: "Accept", value: "application/json; charset=utf-8" }, - ], - method: 'GET', - policy: { - readTimeoutMs: 500, - }, - url: 'https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v2.json?v=1714588690&lat=45.6&lon=12.3', - } - }); - - expect(result).toEqual(expected); - }); - - it('returns no request when country is not Canada', () => { - const result = fetch({ - deliveryAddress: { - countryCode: 'US', - longitude: 12.3, - latitude: 45.6, - } - }); - const expected = ({ request: null }); - - expect(result).toEqual(expected); - }); -}); -{%- elsif flavor contains "typescript" -%} -import { describe, it, expect } from 'vitest'; -import { fetch } from './fetch'; - -import { CountryCode, FunctionFetchResult, HttpRequestMethod } from '../generated/api'; - -describe('fetch function', () => { - it('returns a request when country is Canada', () => { - const result = fetch({ - deliveryAddress: { - countryCode: CountryCode.Ca, - longitude: 12.3, - latitude: 45.6, - } - }); - const expected: FunctionFetchResult = ({ - request: { - body: null, - headers: [ - { name: "Accept", value: "application/json; charset=utf-8" }, - ], - method: HttpRequestMethod.Get, - policy: { - readTimeoutMs: 500, - }, - url: 'https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v2.json?v=1714588690&lat=45.6&lon=12.3', - } - }); - - expect(result).toEqual(expected); - }); - - it('returns no request when country is not Canada', () => { - const result = fetch({ - deliveryAddress: { - countryCode: CountryCode.Us, - longitude: 12.3, - latitude: 45.6, - } - }); - const expected: FunctionFetchResult = ({ request: null }); - - expect(result).toEqual(expected); - }); -}); -{%- endif -%} diff --git a/functions-pickup-point-delivery-option-generators-js/src/run.test.liquid b/functions-pickup-point-delivery-option-generators-js/src/run.test.liquid deleted file mode 100644 index 4d381e76..00000000 --- a/functions-pickup-point-delivery-option-generators-js/src/run.test.liquid +++ /dev/null @@ -1,360 +0,0 @@ -{%- if flavor contains "vanilla-js" -%} -import { describe, it, expect } from 'vitest'; -import { run } from './run'; - -describe('run function', () => { - it('returns operations when fetch result is successful', () => { - const result = run({ - fetchResult: { - status: 200, - body: JSON.stringify({ - deliveryPoints: [ - { - location: { - addressComponents: { - country: 'Canada', - countryCode: 'CA', - streetNumber: '123', - route: 'Main St', - locality: 'Toronto', - administrativeArea: { - name: 'Ontario', - code: 'ON' - }, - postalCode: 'M5V 2T6', - }, - geometry: { - location: { - lat: 43.70, - lng: -79.42, - }, - }, - }, - openingHours: { - weekdayText: [ - 'Monday: 9:00 AM – 5:00 PM', - 'Tuesday: 9:00 AM – 5:00 PM', - 'Wednesday: 9:00 AM – 5:00 PM', - 'Thursday: 9:00 AM – 5:00 PM', - 'Friday: 9:00 AM – 5:00 PM', - 'Saturday: Closed', - 'Sunday: Closed', - ], - }, - pointId: '1', - pointName: 'Point 1', - }, - ], - }), - }, - }); - - const expected = { - operations: [ - { - add: { - cost: null, - pickupPoint: { - address: { - address1: '123 Main St', - address2: null, - city: 'Toronto', - country: 'Canada', - countryCode: 'CA', - latitude: 43.70, - longitude: -79.42, - phone: null, - province: 'Ontario', - provinceCode: 'ON', - zip: 'M5V 2T6', - }, - businessHours: [ - { day: 'MONDAY', periods: [{ openingTime: '09:00:00', closingTime: '17:00:00' }] }, - { day: 'TUESDAY', periods: [{ openingTime: '09:00:00', closingTime: '17:00:00' }] }, - { day: 'WEDNESDAY', periods: [{ openingTime: '09:00:00', closingTime: '17:00:00' }] }, - { day: 'THURSDAY', periods: [{ openingTime: '09:00:00', closingTime: '17:00:00' }] }, - { day: 'FRIDAY', periods: [{ openingTime: '09:00:00', closingTime: '17:00:00' }] }, - { day: 'SATURDAY', periods: [] }, - { day: 'SUNDAY', periods: [] }, - ], - provider: { - name: 'Shopify Javascript Demo', - logoUrl: 'https://cdn.shopify.com/s/files/1/0628/3830/9033/files/shopify_icon_146101.png?v=1706120545', - }, - externalId: '1', - name: 'Point 1', - }, - }, - }, - ], - }; - - expect(result).toEqual(expected); - }); - - it('returns no operations when fetch result is unsuccessful', () => { - const result = run({ - fetchResult: { - status: 404, - body: null, - }, - }); - const expected = { - operations: [] - } - - expect(result).toEqual(expected); - }); - - it("returns an add operation with null pickup point business hours when the external API's delivery point has null opening hours", () => { - const result = run({ - fetchResult: { - status: 200, - body: JSON.stringify({ - deliveryPoints: [ - { - location: { - addressComponents: { - country: 'Canada', - countryCode: 'CA', - streetNumber: '123', - route: 'Main St', - locality: 'Toronto', - administrativeArea: { - name: "Ontario", - code: "ON" - }, - postalCode: 'M5V 2T6', - }, - geometry: { - location: { - lat: 43.70, - lng: -79.42, - }, - }, - }, - openingHours: null, - pointId: '1', - pointName: 'Point 1', - }, - ], - }), - }, - }); - - const expected = { - operations: [ - { - add: { - cost: null, - pickupPoint: { - address: { - address1: '123 Main St', - address2: null, - city: 'Toronto', - country: 'Canada', - countryCode: 'CA', - latitude: 43.70, - longitude: -79.42, - phone: null, - province: 'Ontario', - provinceCode: 'ON', - zip: 'M5V 2T6', - }, - businessHours: null, - provider: { - name: 'Shopify Javascript Demo', - logoUrl: 'https://cdn.shopify.com/s/files/1/0628/3830/9033/files/shopify_icon_146101.png?v=1706120545', - }, - externalId: '1', - name: 'Point 1', - }, - }, - }, - ], - }; - - expect(result).toEqual(expected); - }); -}); -{%- elsif flavor contains "typescript" -%} -import { describe, it, expect } from 'vitest'; -import { run } from './run'; -import { CountryCode, FunctionRunResult, Weekday } from '../generated/api'; - -describe('run function', () => { - it('returns operations when fetch result is successful', () => { - const result = run({ - fetchResult: { - status: 200, - body: JSON.stringify({ - deliveryPoints: [ - { - location: { - addressComponents: { - country: 'Canada', - countryCode: 'CA', - streetNumber: '123', - route: 'Main St', - locality: 'Toronto', - administrativeArea: { - name: 'Ontario', - code: 'ON' - }, - postalCode: 'M5V 2T6', - }, - geometry: { - location: { - lat: 43.70, - lng: -79.42, - }, - }, - }, - openingHours: { - weekdayText: [ - 'Monday: 9:00 AM – 5:00 PM', - 'Tuesday: 9:00 AM – 5:00 PM', - 'Wednesday: 9:00 AM – 5:00 PM', - 'Thursday: 9:00 AM – 5:00 PM', - 'Friday: 9:00 AM – 5:00 PM', - 'Saturday: Closed', - 'Sunday: Closed', - ], - }, - pointId: '1', - pointName: 'Point 1', - }, - ], - }), - }, - }); - - const expected: FunctionRunResult = { - operations: [ - { - add: { - cost: null, - pickupPoint: { - address: { - address1: '123 Main St', - address2: null, - city: 'Toronto', - country: 'Canada', - countryCode: CountryCode.Ca, - latitude: 43.70, - longitude: -79.42, - phone: null, - province: 'Ontario', - provinceCode: 'ON', - zip: 'M5V 2T6', - }, - businessHours: [ - { day: Weekday.Monday, periods: [{ openingTime: '09:00:00', closingTime: '17:00:00' }] }, - { day: Weekday.Tuesday, periods: [{ openingTime: '09:00:00', closingTime: '17:00:00' }] }, - { day: Weekday.Wednesday, periods: [{ openingTime: '09:00:00', closingTime: '17:00:00' }] }, - { day: Weekday.Thursday, periods: [{ openingTime: '09:00:00', closingTime: '17:00:00' }] }, - { day: Weekday.Friday, periods: [{ openingTime: '09:00:00', closingTime: '17:00:00' }] }, - { day: Weekday.Saturday, periods: [] }, - { day: Weekday.Sunday, periods: [] }, - ], - provider: { - name: 'Shopify TypeScript Demo', - logoUrl: 'https://cdn.shopify.com/s/files/1/0628/3830/9033/files/shopify_icon_146101.png?v=1706120545', - }, - externalId: '1', - name: 'Point 1', - }, - }, - }, - ], - }; - - expect(result).toEqual(expected); - }); - - it('returns no operations when fetch result is unsuccessful', () => { - const result = run({ - fetchResult: { - status: 404, - body: null, - }, - }); - const expected: FunctionRunResult = { - operations: [] - } - - expect(result).toEqual(expected); - }); - - it("returns an add operation with null pickup point business hours when the external API's delivery point has null opening hours", () => { - const result = run({ - fetchResult: { - status: 200, - body: JSON.stringify({ - deliveryPoints: [ - { - location: { - addressComponents: { - country: 'Canada', - countryCode: 'CA', - streetNumber: '123', - route: 'Main St', - locality: 'Toronto', - administrativeArea: { - name: 'Ontario', - code: 'ON' - }, - postalCode: 'M5V 2T6', - }, - geometry: { - location: { - lat: 43.70, - lng: -79.42, - }, - }, - }, - openingHours: null, - pointId: '1', - pointName: 'Point 1', - }, - ], - }), - }, - }); - - const expected: FunctionRunResult = { - operations: [ - { - add: { - cost: null, - pickupPoint: { - address: { - address1: '123 Main St', - address2: null, - city: 'Toronto', - country: 'Canada', - countryCode: CountryCode.Ca, - latitude: 43.70, - longitude: -79.42, - phone: null, - province: 'Ontario', - provinceCode: 'ON', - zip: 'M5V 2T6', - }, - businessHours: null, - provider: { - name: 'Shopify TypeScript Demo', - logoUrl: 'https://cdn.shopify.com/s/files/1/0628/3830/9033/files/shopify_icon_146101.png?v=1706120545', - }, - externalId: '1', - name: 'Point 1', - }, - }, - }, - ], - }; - - expect(result).toEqual(expected); - }); -}); -{%- endif -%} diff --git a/functions-pickup-point-delivery-option-generators-rs/src/fetch.rs b/functions-pickup-point-delivery-option-generators-rs/src/fetch.rs index e2dc6e8b..3b063793 100644 --- a/functions-pickup-point-delivery-option-generators-rs/src/fetch.rs +++ b/functions-pickup-point-delivery-option-generators-rs/src/fetch.rs @@ -40,66 +40,3 @@ fn build_external_api_request(latitude: &f64, longitude: &f64) -> schema::HttpRe }, } } - -#[cfg(test)] -mod tests { - use super::*; - use shopify_function::{run_function_with_input, Result}; - - #[test] - fn test_fetch_returns_request_when_country_is_canada() -> Result<()> { - let result = run_function_with_input( - fetch, - r#" - { - "deliveryAddress": { - "countryCode": "CA", - "longitude": 43.70, - "latitude": -79.42 - } - } - "#, - )?; - - let expected = schema::FunctionFetchResult { - request: Some(schema::HttpRequest { - method: schema::HttpRequestMethod::Get, - url: "https://cdn.shopify.com/s/files/1/0628/3830/9033/files/pickup-points-external-api-v2.json?v=1714588690&lat=-79.42&lon=43.7".to_string(), - - headers: vec![ - schema::HttpRequestHeader { - name: "Accept".to_string(), - value: "application/json; charset=utf-8".to_string(), - }, - ], - body: None, - json_body: None, - policy: schema::HttpRequestPolicy { - read_timeout_ms: 500, - }, - }), - }; - - assert_eq!(result, expected); - Ok(()) - } - - #[test] - fn test_fetch_returns_no_request_when_country_is_not_canada() -> Result<()> { - let result = run_function_with_input( - fetch, - r#" - { - "deliveryAddress": { - "countryCode": "US", - "longitude": 40.71, - "latitude": -74.01 - } - } - "#, - )?; - - assert!(result.request.is_none()); - Ok(()) - } -} diff --git a/functions-pickup-point-delivery-option-generators-rs/src/run.rs b/functions-pickup-point-delivery-option-generators-rs/src/run.rs index 456a655b..3cd1d341 100644 --- a/functions-pickup-point-delivery-option-generators-rs/src/run.rs +++ b/functions-pickup-point-delivery-option-generators-rs/src/run.rs @@ -194,247 +194,3 @@ fn format_time(time: &str) -> TimeWithoutTimezone { format!("{hour_in_24_format:02}:{min:02}:00") } - -#[cfg(test)] -mod tests { - use super::*; - use shopify_function::{run_function_with_input, Result}; - - #[test] - fn test_result_has_pickup_point_delivery_options_when_receiving_fetch_result_for_successful_response( - ) -> Result<()> { - use serde_json::json; - - let external_api_body = json!({ - "deliveryPoints": [ - { - "pointId": "001", - "pointName": "Toronto Store", - "location": { - "addressComponents": { - "streetNumber": "620", - "route": "King St W", - "locality": "Toronto", - "administrativeArea": { - "name": "Ontario", - "code": "ON" - }, - "postalCode": "M5V 1M6", - "country": "Canada", - "countryCode": "CA" - }, - "geometry": { - "location": { - "lat": 43.644664618786685, - "lng": -79.40066267417106 - } - } - }, - "openingHours": { - "weekdayText": [ - "Monday: 9:00 AM – 9:00 PM", - "Tuesday: 9:00 AM – 9:00 PM", - "Wednesday: 9:00 AM – 9:00 PM", - "Thursday: 9:00 AM – 9:00 PM", - "Friday: 9:00 AM – 9:00 PM", - "Saturday: 10:00 AM – 6:00 PM", - "Sunday: Closed" - ] - } - } - ] - }); - - let result = run_function_with_input( - run, - &json!({ - "fetchResult": { - "status": 200, - "body": external_api_body.to_string() - } - }) - .to_string(), - )?; - - let expected = schema::FunctionRunResult { - operations: vec![schema::Operation { - add: schema::PickupPointDeliveryOption { - cost: None, - pickup_point: schema::PickupPoint { - address: schema::PickupAddress { - address_1: "620 King St W".to_string(), - address_2: None, - city: "Toronto".to_string(), - country: Some("Canada".to_string()), - country_code: "CA".to_string(), - latitude: 43.644664618786685, - longitude: -79.40066267417106, - phone: None, - province: Some("Ontario".to_string()), - province_code: Some("ON".to_string()), - zip: Some("M5V 1M6".to_string()), - }, - business_hours: Some(vec![ - schema::BusinessHours { - day: schema::Weekday::Monday, - periods: vec![schema::BusinessHoursPeriod { - opening_time: "09:00:00".to_string(), - closing_time: "21:00:00".to_string(), - }], - }, - schema::BusinessHours { - day: schema::Weekday::Tuesday, - periods: vec![schema::BusinessHoursPeriod { - opening_time: "09:00:00".to_string(), - closing_time: "21:00:00".to_string(), - }], - }, - schema::BusinessHours { - day: schema::Weekday::Wednesday, - periods: vec![schema::BusinessHoursPeriod { - opening_time: "09:00:00".to_string(), - closing_time: "21:00:00".to_string(), - }], - }, - schema::BusinessHours { - day: schema::Weekday::Thursday, - periods: vec![schema::BusinessHoursPeriod { - opening_time: "09:00:00".to_string(), - closing_time: "21:00:00".to_string(), - }], - }, - schema::BusinessHours { - day: schema::Weekday::Friday, - periods: vec![schema::BusinessHoursPeriod { - opening_time: "09:00:00".to_string(), - closing_time: "21:00:00".to_string(), - }], - }, - schema::BusinessHours { - day: schema::Weekday::Saturday, - periods: vec![schema::BusinessHoursPeriod { - opening_time: "10:00:00".to_string(), - closing_time: "18:00:00".to_string(), - }], - }, - schema::BusinessHours { - day: schema::Weekday::Sunday, - periods: vec![], - }, - ]), - provider: schema::Provider { - name: "Shopify Rust Demo".to_string(), - logo_url: "https://cdn.shopify.com/s/files/1/0628/3830/9033/files/shopify_icon_146101.png?v=1706120545".to_string(), - }, - external_id: "001".to_string(), - name: "Toronto Store".to_string(), - }, - metafields: Some(vec![]), - }, - }], - }; - - assert_eq!(result, expected); - Ok(()) - } - #[test] - fn test_result_has_no_pickup_point_delivery_options_when_receiving_fetch_result_for_failed_response( - ) -> Result<()> { - let result = run_function_with_input( - run, - r#" - { - "fetchResult": { - "status": 500, - "body": "Server Error" - } - } - "#, - )?; - - let expected = schema::FunctionRunResult { operations: vec![] }; - assert_eq!(result, expected); - Ok(()) - } - - #[test] - fn test_result_has_pickup_point_delivery_option_with_null_business_hours_when_fetch_result_has_null_opening_hours( - ) -> Result<()> { - use serde_json::json; - - let external_api_body = json!({ - "deliveryPoints": [ - { - "pointId": "001", - "pointName": "Toronto Store", - "location": { - "addressComponents": { - "streetNumber": "620", - "route": "King St W", - "locality": "Toronto", - "administrativeArea": { - "name": "Ontario", - "code": "ON" - }, - "postalCode": "M5V 1M6", - "country": "Canada", - "countryCode": "CA" - }, - "geometry": { - "location": { - "lat": 43.644664618786685, - "lng": -79.40066267417106 - } - } - }, - "openingHours": null - } - ] - }); - - let result = run_function_with_input( - run, - &json!({ - "fetchResult": { - "status": 200, - "body": external_api_body.to_string() - } - }) - .to_string(), - )?; - - let expected = schema::FunctionRunResult { - operations: vec![schema::Operation { - add: schema::PickupPointDeliveryOption { - cost: None, - pickup_point: schema::PickupPoint { - address: schema::PickupAddress { - address_1: "620 King St W".to_string(), - address_2: None, - city: "Toronto".to_string(), - country: Some("Canada".to_string()), - country_code: "CA".to_string(), - latitude: 43.644664618786685, - longitude: -79.40066267417106, - phone: None, - province: Some("Ontario".to_string()), - province_code: Some("ON".to_string()), - zip: Some("M5V 1M6".to_string()), - }, - business_hours: None, - provider: schema::Provider { - name: "Shopify Rust Demo".to_string(), - logo_url: "https://cdn.shopify.com/s/files/1/0628/3830/9033/files/shopify_icon_146101.png?v=1706120545".to_string(), - }, - external_id: "001".to_string(), - name: "Toronto Store".to_string(), - }, - metafields: Some(vec![]), - }, - }], - }; - - assert_eq!(result, expected); - Ok(()) - } -}