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/log.json b/functions-location-rules-js/tests/fixtures/log.json new file mode 100644 index 00000000..196b211a --- /dev/null +++ b/functions-location-rules-js/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-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