diff --git a/packages/composable-common/src/payment-gateways/check-gateway.test.ts b/packages/composable-common/src/payment-gateways/check-gateway.test.ts index 9d717336..2212f7c2 100644 --- a/packages/composable-common/src/payment-gateways/check-gateway.test.ts +++ b/packages/composable-common/src/payment-gateways/check-gateway.test.ts @@ -2,15 +2,14 @@ import { gateway, MemoryStorageFactory } from "@moltin/sdk" import { it, describe, expect } from "vitest" import { checkGateway } from "./check-gateway" -const client = gateway({ - client_id: "123", - client_secret: "456", - host: "mock-host.com", - storage: new MemoryStorageFactory(), -}) - describe("check-gateway", () => { it("checkGateway should give success response when gateway is active", async () => { + const client = gateway({ + client_id: "123", + client_secret: "456", + host: "mock-host.com", + storage: new MemoryStorageFactory(), + }) expect(await checkGateway(client, "manual")).toEqual({ success: true, data: { @@ -23,6 +22,12 @@ describe("check-gateway", () => { }) it("checkGateway should give failure response when gateway is not enabled", async () => { + const client = gateway({ + client_id: "123", + client_secret: "456", + host: "mock-host.com", + storage: new MemoryStorageFactory(), + }) expect(await checkGateway(client, "elastic_path_payments_stripe")).toEqual({ success: false, error: new Error(`elastic_path_payments_stripe gateway is not enabled`), diff --git a/packages/composable-common/src/payment-gateways/ep-payments/update-gateway.test.ts b/packages/composable-common/src/payment-gateways/ep-payments/update-gateway.test.ts index 3212b84d..72b2685a 100644 --- a/packages/composable-common/src/payment-gateways/ep-payments/update-gateway.test.ts +++ b/packages/composable-common/src/payment-gateways/ep-payments/update-gateway.test.ts @@ -2,15 +2,14 @@ import { it, describe, expect } from "vitest" import { updateEpPaymentGateway } from "./update-gateway" import { gateway, MemoryStorageFactory } from "@moltin/sdk" -const client = gateway({ - client_id: "123", - client_secret: "456", - host: "mock-host.com", - storage: new MemoryStorageFactory(), -}) - describe("update-gateway", () => { it("updateEpPaymentGateway should give success response", async () => { + const client = gateway({ + client_id: "123", + client_secret: "456", + host: "mock-host.com", + storage: new MemoryStorageFactory(), + }) expect(await updateEpPaymentGateway(client, "new-account-id")).toEqual({ success: true, data: { diff --git a/packages/d2c-schematics/__tests__/application.test.ts b/packages/d2c-schematics/__tests__/application.test.ts index 8d02c644..22466a92 100644 --- a/packages/d2c-schematics/__tests__/application.test.ts +++ b/packages/d2c-schematics/__tests__/application.test.ts @@ -32,21 +32,25 @@ describe("Application Schematic", () => { let workspaceTree: UnitTestTree beforeEach(async () => { - workspaceTree = await schematicRunner - .runSchematicAsync("workspace", workspaceOptions) - .toPromise() + workspaceTree = await schematicRunner.runSchematic( + "workspace", + workspaceOptions, + ) }) it("should create public files for core application", async () => { const options = { ...defaultOptions } try { - const tree = await schematicRunner - .runSchematicAsync("application", options, workspaceTree) - .toPromise() + const tree = await schematicRunner.runSchematic( + "application", + options, + workspaceTree, + ) + const files = tree.files - expect(files).toIncludeAllPartialMembers(["/public/favicon.ico"]) + expect(files).toContain("/public/favicon.ico") } catch (err) { throw new Error(err) } @@ -56,9 +60,12 @@ describe("Application Schematic", () => { const options = { ...defaultOptions } try { - const tree = await schematicRunner - .runSchematicAsync("application", options, workspaceTree) - .toPromise() + const tree = await schematicRunner.runSchematic( + "application", + options, + workspaceTree, + ) + const files = tree.files expect(files).toIncludeAllPartialMembers(["/src/styles/globals.css"]) @@ -69,9 +76,12 @@ describe("Application Schematic", () => { it("should create middleware files of an application", async () => { const options = { ...defaultOptions } - const tree = await schematicRunner - .runSchematicAsync("application", options, workspaceTree) - .toPromise() + const tree = await schematicRunner.runSchematic( + "application", + options, + workspaceTree, + ) + const files = tree.files expect(files).toIncludeAllPartialMembers([ @@ -88,9 +98,12 @@ describe("Application Schematic", () => { it("should create core files of an application", async () => { const options = { ...defaultOptions } - const tree = await schematicRunner - .runSchematicAsync("application", options, workspaceTree) - .toPromise() + const tree = await schematicRunner.runSchematic( + "application", + options, + workspaceTree, + ) + const files = tree.files expect(files.filter((f) => f.startsWith("/src/")).sort()).toEqual( @@ -120,9 +133,9 @@ describe("Application Schematic", () => { "/src/lib/epcc-server-client.ts", "/src/lib/epcc-server-side-implicit-client.ts", "/src/lib/form-url-encode-body.ts", - "/src/lib/get-cookie.ts", "/src/lib/get-store-context.ts", "/src/lib/is-empty-object.ts", + "/src/lib/middleware/apply-set-cookie.ts", "/src/lib/middleware/cart-cookie-middleware.ts", "/src/lib/middleware/create-missing-environment-variable-url.ts", "/src/lib/middleware/implicit-auth-middleware.ts", diff --git a/packages/d2c-schematics/__tests__/cart.test.ts b/packages/d2c-schematics/__tests__/cart.test.ts index c4f30f23..54f54557 100644 --- a/packages/d2c-schematics/__tests__/cart.test.ts +++ b/packages/d2c-schematics/__tests__/cart.test.ts @@ -30,19 +30,22 @@ describe("Cart Schematic", () => { /** * Cart schematic depends on workspace and application schematics */ - const workspaceTree = await schematicRunner - .runSchematicAsync("workspace", workspaceOptions) - .toPromise() - initTree = await schematicRunner - .runSchematicAsync("application", applicationOptions, workspaceTree) - .toPromise() + const workspaceTree = await schematicRunner.runSchematic( + "workspace", + workspaceOptions, + ) + + initTree = await schematicRunner.runSchematic( + "application", + applicationOptions, + workspaceTree, + ) }) it("should create cart page files of an application", async () => { const options = { ...defaultOptions } - const tree = await schematicRunner - .runSchematicAsync("cart", options, initTree) - .toPromise() + const tree = await schematicRunner.runSchematic("cart", options, initTree) + const files = tree.files expect(files).toIncludeAllPartialMembers([ diff --git a/packages/d2c-schematics/__tests__/d2c.test.ts b/packages/d2c-schematics/__tests__/d2c.test.ts index bd1e40f5..82c3698a 100644 --- a/packages/d2c-schematics/__tests__/d2c.test.ts +++ b/packages/d2c-schematics/__tests__/d2c.test.ts @@ -25,10 +25,7 @@ describe("EP New Schematic", () => { it("should create files of a workspace", async () => { const options = { ...defaultOptions } - const tree: any = await schematicRunner - .runSchematicAsync("d2c", options) - .toPromise() - .catch((err) => console.log("error caught:", err)) + const tree = await schematicRunner.runSchematic("d2c", options) const files = tree.files expect(files).toContain("/bar/package.json") @@ -36,9 +33,8 @@ describe("EP New Schematic", () => { it("should create cart schematic files", async () => { const options = { ...defaultOptions } - const tree = await schematicRunner - .runSchematicAsync("d2c", options) - .toPromise() + const tree = await schematicRunner.runSchematic("d2c", options) + const files = tree.files expect(files).toIncludeAllPartialMembers([ diff --git a/packages/d2c-schematics/__tests__/featured-product.test.ts b/packages/d2c-schematics/__tests__/featured-product.test.ts index 8de173d0..63eb5498 100644 --- a/packages/d2c-schematics/__tests__/featured-product.test.ts +++ b/packages/d2c-schematics/__tests__/featured-product.test.ts @@ -10,7 +10,7 @@ import { Schema as FeaturedProductOptions } from "../featured-products/schema" describe("Featured Products Schematic", () => { const schematicRunner = new SchematicTestRunner( "@schematics/angular", - require.resolve("../collection.json") + require.resolve("../collection.json"), ) const workspaceOptions: WorkspaceOptions = { @@ -31,19 +31,26 @@ describe("Featured Products Schematic", () => { /** * Featured Products schematic depends on workspace and application schematics */ - const workspaceTree = await schematicRunner - .runSchematicAsync("workspace", workspaceOptions) - .toPromise() - initTree = await schematicRunner - .runSchematicAsync("application", applicationOptions, workspaceTree) - .toPromise() + const workspaceTree = await schematicRunner.runSchematic( + "workspace", + workspaceOptions, + ) + + initTree = await schematicRunner.runSchematic( + "application", + applicationOptions, + workspaceTree, + ) }) it("featured products schematic should create component files", async () => { const options = { ...defaultOptions } - const tree = await schematicRunner - .runSchematicAsync("featured-products", options, initTree) - .toPromise() + const tree = await schematicRunner.runSchematic( + "featured-products", + options, + initTree, + ) + const files = tree.files expect(files).toIncludeAnyMembers([ diff --git a/packages/d2c-schematics/__tests__/footer.test.ts b/packages/d2c-schematics/__tests__/footer.test.ts index 73f1b1cc..a032f716 100644 --- a/packages/d2c-schematics/__tests__/footer.test.ts +++ b/packages/d2c-schematics/__tests__/footer.test.ts @@ -9,7 +9,7 @@ import { Schema as ApplicationOptions } from "../application/schema" describe("Footer Schematic", () => { const schematicRunner = new SchematicTestRunner( "@schematics/angular", - require.resolve("../collection.json") + require.resolve("../collection.json"), ) const workspaceOptions: WorkspaceOptions = { @@ -30,19 +30,22 @@ describe("Footer Schematic", () => { /** * Footer schematic depends on workspace and application schematics */ - const workspaceTree = await schematicRunner - .runSchematicAsync("workspace", workspaceOptions) - .toPromise() - initTree = await schematicRunner - .runSchematicAsync("application", applicationOptions, workspaceTree) - .toPromise() + const workspaceTree = await schematicRunner.runSchematic( + "workspace", + workspaceOptions, + ) + + initTree = await schematicRunner.runSchematic( + "application", + applicationOptions, + workspaceTree, + ) }) it("should create footer component files of an application", async () => { const options = { ...defaultOptions } - const tree = await schematicRunner - .runSchematicAsync("footer", options, initTree) - .toPromise() + const tree = await schematicRunner.runSchematic("footer", options, initTree) + const files = tree.files expect(files).toIncludeAllPartialMembers([ diff --git a/packages/d2c-schematics/__tests__/header.test.ts b/packages/d2c-schematics/__tests__/header.test.ts index bc9a5f05..e334e542 100644 --- a/packages/d2c-schematics/__tests__/header.test.ts +++ b/packages/d2c-schematics/__tests__/header.test.ts @@ -32,19 +32,22 @@ describe("Header Schematic", () => { /** * Header schematic depends on workspace and application schematics */ - const workspaceTree = await schematicRunner - .runSchematicAsync("workspace", workspaceOptions) - .toPromise() - initTree = await schematicRunner - .runSchematicAsync("application", applicationOptions, workspaceTree) - .toPromise() + const workspaceTree = await schematicRunner.runSchematic( + "workspace", + workspaceOptions, + ) + + initTree = await schematicRunner.runSchematic( + "application", + applicationOptions, + workspaceTree, + ) }) it("should create header component files of an application", async () => { const options = { ...defaultOptions } - const tree = await schematicRunner - .runSchematicAsync("header", options, initTree) - .toPromise() + const tree = await schematicRunner.runSchematic("header", options, initTree) + const files = tree.files expect( @@ -65,9 +68,10 @@ describe("Header Schematic", () => { }) it("header schematic should not import search modal module when search=false", async () => { - const tree = await schematicRunner - .runSchematicAsync("header", { ...defaultOptions, search: false }) - .toPromise() + const tree = await schematicRunner.runSchematic("header", { + ...defaultOptions, + search: false, + }) const tsSrcFile = createSourceFile( "Header.tsx", @@ -82,9 +86,10 @@ describe("Header Schematic", () => { }) it("header schematic should import search modal module when search=true", async () => { - const tree = await schematicRunner - .runSchematicAsync("header", { ...defaultOptions, search: true }) - .toPromise() + const tree = await schematicRunner.runSchematic("header", { + ...defaultOptions, + search: true, + }) const tsSrcFile = createSourceFile( "Header.tsx", diff --git a/packages/d2c-schematics/__tests__/home.test.ts b/packages/d2c-schematics/__tests__/home.test.ts index 1108497a..fceb7e4d 100644 --- a/packages/d2c-schematics/__tests__/home.test.ts +++ b/packages/d2c-schematics/__tests__/home.test.ts @@ -5,8 +5,8 @@ import { import { createSourceFile, ScriptTarget } from "typescript" -import { Schema as WorkspaceOptions } from "../workspace/schema" -import { Schema as ApplicationOptions } from "../application/schema" +import { Schema as WorkspaceOptions } from "../../../dist-schema/packages/d2c-schematics/workspace/schema" +import { Schema as ApplicationOptions } from "../../../dist-schema/packages/d2c-schematics/application/schema" describe("Home Schematic", () => { const schematicRunner = new SchematicTestRunner( @@ -32,32 +32,33 @@ describe("Home Schematic", () => { /** * Home schematic depends on workspace and application schematics */ - const workspaceTree = await schematicRunner - .runSchematicAsync("workspace", workspaceOptions) - .toPromise() - initTree = await schematicRunner - .runSchematicAsync("application", applicationOptions, workspaceTree) - .toPromise() + const workspaceTree = await schematicRunner.runSchematic( + "workspace", + workspaceOptions, + ) + + initTree = await schematicRunner.runSchematic( + "application", + applicationOptions, + workspaceTree, + ) }) it("should create home page files of an application", async () => { const options = { ...defaultOptions, } - const tree = await schematicRunner - .runSchematicAsync("home", options, initTree) - .toPromise() + const tree = await schematicRunner.runSchematic("home", options, initTree) + const files = tree.files - expect(files).toIncludeAllPartialMembers(["/src/app/page.tsx"]) + expect(files).toContain("/src/app/page.tsx") }) xit("home schematic should include default components when now are specified", async () => { - const tree = await schematicRunner - .runSchematicAsync("home", { - ...defaultOptions, - }) - .toPromise() + const tree = await schematicRunner.runSchematic("home", { + ...defaultOptions, + }) const tsSrcFile = createSourceFile( "index.tsx", @@ -73,11 +74,9 @@ describe("Home Schematic", () => { }) xit("home schematic should include only the specified components", async () => { - const tree = await schematicRunner - .runSchematicAsync("home", { - ...defaultOptions, - }) - .toPromise() + const tree = await schematicRunner.runSchematic("home", { + ...defaultOptions, + }) const tsSrcFile = createSourceFile( "index.tsx", diff --git a/packages/d2c-schematics/__tests__/product-details-page.test.ts b/packages/d2c-schematics/__tests__/product-details-page.test.ts index 267e1678..232869b6 100644 --- a/packages/d2c-schematics/__tests__/product-details-page.test.ts +++ b/packages/d2c-schematics/__tests__/product-details-page.test.ts @@ -30,19 +30,26 @@ describe("Product Details Page Schematic", () => { /** * Product Details Page schematic depends on workspace and application schematics */ - const workspaceTree = await schematicRunner - .runSchematicAsync("workspace", workspaceOptions) - .toPromise() - initTree = await schematicRunner - .runSchematicAsync("application", applicationOptions, workspaceTree) - .toPromise() + const workspaceTree = await schematicRunner.runSchematic( + "workspace", + workspaceOptions, + ) + + initTree = await schematicRunner.runSchematic( + "application", + applicationOptions, + workspaceTree, + ) }) it("should create product detail component files", async () => { const options = { ...defaultOptions } - const tree = await schematicRunner - .runSchematicAsync("product-details-page", options, initTree) - .toPromise() + const tree = await schematicRunner.runSchematic( + "product-details-page", + options, + initTree, + ) + const files = tree.files // console.log("files: ", JSON.stringify(files)) expect( @@ -80,9 +87,12 @@ describe("Product Details Page Schematic", () => { it("should create product detail utility files", async () => { const options = { ...defaultOptions } - const tree = await schematicRunner - .runSchematicAsync("product-details-page", options, initTree) - .toPromise() + const tree = await schematicRunner.runSchematic( + "product-details-page", + options, + initTree, + ) + const files = tree.files // console.log("files: ", JSON.stringify(files)) expect(files).toIncludeAllPartialMembers([ @@ -98,9 +108,12 @@ describe("Product Details Page Schematic", () => { it("should create product detail page files", async () => { const options = { ...defaultOptions } - const tree = await schematicRunner - .runSchematicAsync("product-details-page", options, initTree) - .toPromise() + const tree = await schematicRunner.runSchematic( + "product-details-page", + options, + initTree, + ) + const files = tree.files expect(files).toIncludeAllPartialMembers([ "/src/app/products/[productId]/page.tsx", @@ -109,9 +122,12 @@ describe("Product Details Page Schematic", () => { it("should have files provided by application schematic", async () => { const options = { ...defaultOptions } - const tree = await schematicRunner - .runSchematicAsync("product-details-page", options, initTree) - .toPromise() + const tree = await schematicRunner.runSchematic( + "product-details-page", + options, + initTree, + ) + const files = tree.files expect(files).toIncludeAllPartialMembers([ diff --git a/packages/d2c-schematics/__tests__/product-list-page-algolia.test.ts b/packages/d2c-schematics/__tests__/product-list-page-algolia.test.ts index 8f80fea1..3c9987ec 100644 --- a/packages/d2c-schematics/__tests__/product-list-page-algolia.test.ts +++ b/packages/d2c-schematics/__tests__/product-list-page-algolia.test.ts @@ -17,7 +17,7 @@ import { parseEnv } from "../utility/add-env-variable" describe("Product List Page Algolia Schematic", () => { const schematicRunner = new SchematicTestRunner( "@schematics/angular", - require.resolve("../collection.json") + require.resolve("../collection.json"), ) const epccMockOptions = { @@ -47,22 +47,25 @@ describe("Product List Page Algolia Schematic", () => { /** * Algolia Product List Page schematic depends on workspace and application schematics */ - const workspaceTree = await schematicRunner - .runSchematicAsync("workspace", workspaceOptions) - .toPromise() - initTree = await schematicRunner - .runSchematicAsync("application", applicationOptions, workspaceTree) - .toPromise() + const workspaceTree = await schematicRunner.runSchematic( + "workspace", + workspaceOptions, + ) + + initTree = await schematicRunner.runSchematic( + "application", + applicationOptions, + workspaceTree, + ) }) it("algolia product list page schematic should create example files", async () => { - const tree = await schematicRunner - .runSchematicAsync( - "plp", - { plpType: "Algolia", ...epccMockOptions, ...xPromptValues }, - initTree - ) - .toPromise() + const tree = await schematicRunner.runSchematic( + "plp", + { plpType: "Algolia", ...epccMockOptions, ...xPromptValues }, + initTree, + ) + const files = tree.files // TODO add rest of expected files @@ -70,13 +73,11 @@ describe("Product List Page Algolia Schematic", () => { }) it("algolia product list page schematic should add algolia dependencies to package.json", async () => { - const tree = await schematicRunner - .runSchematicAsync( - "plp", - { plpType: "Algolia", ...epccMockOptions, ...xPromptValues }, - initTree - ) - .toPromise() + const tree = await schematicRunner.runSchematic( + "plp", + { plpType: "Algolia", ...epccMockOptions, ...xPromptValues }, + initTree, + ) const pkg = JSON.parse(tree.readContent("/package.json")) @@ -86,13 +87,11 @@ describe("Product List Page Algolia Schematic", () => { }) it("algolia product list page schematic should update .env.local", async () => { - const tree = await schematicRunner - .runSchematicAsync( - "plp", - { plpType: "Algolia", ...epccMockOptions, ...xPromptValues }, - initTree - ) - .toPromise() + const tree = await schematicRunner.runSchematic( + "plp", + { plpType: "Algolia", ...epccMockOptions, ...xPromptValues }, + initTree, + ) const rawText = tree.readText("/.env.local") const parsed = parseEnv(rawText) diff --git a/packages/d2c-schematics/__tests__/promotion-banner.test.ts b/packages/d2c-schematics/__tests__/promotion-banner.test.ts index b208680f..6a8d0ac6 100644 --- a/packages/d2c-schematics/__tests__/promotion-banner.test.ts +++ b/packages/d2c-schematics/__tests__/promotion-banner.test.ts @@ -10,7 +10,7 @@ import { Schema as PromotionBannerOptions } from "../promotion-banner/schema" describe("Promotion Banner Schematic", () => { const schematicRunner = new SchematicTestRunner( "@schematics/angular", - require.resolve("../collection.json") + require.resolve("../collection.json"), ) const workspaceOptions: WorkspaceOptions = { @@ -31,19 +31,26 @@ describe("Promotion Banner Schematic", () => { /** * Promotion Banner schematic depends on workspace and application schematics */ - const workspaceTree = await schematicRunner - .runSchematicAsync("workspace", workspaceOptions) - .toPromise() - initTree = await schematicRunner - .runSchematicAsync("application", applicationOptions, workspaceTree) - .toPromise() + const workspaceTree = await schematicRunner.runSchematic( + "workspace", + workspaceOptions, + ) + + initTree = await schematicRunner.runSchematic( + "application", + applicationOptions, + workspaceTree, + ) }) it("promotion banner schematic should create component files", async () => { const options = { ...defaultOptions } - const tree = await schematicRunner - .runSchematicAsync("promotion-banner", options, initTree) - .toPromise() + const tree = await schematicRunner.runSchematic( + "promotion-banner", + options, + initTree, + ) + const files = tree.files expect(files).toIncludeAnyMembers([ diff --git a/packages/d2c-schematics/__tests__/workspace.test.ts b/packages/d2c-schematics/__tests__/workspace.test.ts index cc4c6e83..6ca8346c 100644 --- a/packages/d2c-schematics/__tests__/workspace.test.ts +++ b/packages/d2c-schematics/__tests__/workspace.test.ts @@ -51,9 +51,11 @@ describe("Workspace Schematic", () => { }) it("workspace schematic should not configure testing when tests=false", async () => { - const tree = await schematicRunner - .runSchematicAsync("workspace", { ...defaultOptions, tests: false }) - .toPromise() + const tree = await schematicRunner.runSchematic("workspace", { + ...defaultOptions, + tests: false, + }) + const { scripts, devDependencies } = parseJson( tree.readContent("package.json").toString(), ) diff --git a/packages/d2c-schematics/d2c/schema.json b/packages/d2c-schematics/d2c/schema.json index 926f1fa0..d8a95766 100644 --- a/packages/d2c-schematics/d2c/schema.json +++ b/packages/d2c-schematics/d2c/schema.json @@ -84,7 +84,7 @@ "plpType": { "description": "The type of product list page to use.", "type": "string", - "enum": ["Algolia", "Manual", "None"] + "enum": ["Algolia", "None"] } }, "required": ["name", "epccClientId", "epccClientSecret", "epccEndpointUrl"] diff --git a/packages/d2c-schematics/tsconfig.json b/packages/d2c-schematics/tsconfig.json new file mode 100644 index 00000000..6d58ea0c --- /dev/null +++ b/packages/d2c-schematics/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "exclude": [ + "packages/d2c-schematics/node_modules", + "dist", + "**/node_modules/**/*", + ], + "include": ["**/*/*test.ts"] +}