Skip to content

Commit

Permalink
test: unit test fixes (#126)
Browse files Browse the repository at this point in the history
* test: moved gateway inside test.

* chore: lock file

* test: updated to work with latest devkit changes

* fix: should never have been a manual plp option

* fix: build issue

* chore: lock file
  • Loading branch information
field123 authored Nov 16, 2023
1 parent 88d82d2 commit 92c36ee
Show file tree
Hide file tree
Showing 15 changed files with 227 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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`),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
47 changes: 30 additions & 17 deletions packages/d2c-schematics/__tests__/application.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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"])
Expand All @@ -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([
Expand All @@ -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(
Expand Down Expand Up @@ -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",
Expand Down
21 changes: 12 additions & 9 deletions packages/d2c-schematics/__tests__/cart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
10 changes: 3 additions & 7 deletions packages/d2c-schematics/__tests__/d2c.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,16 @@ 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")
})

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([
Expand Down
27 changes: 17 additions & 10 deletions packages/d2c-schematics/__tests__/featured-product.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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([
Expand Down
23 changes: 13 additions & 10 deletions packages/d2c-schematics/__tests__/footer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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([
Expand Down
35 changes: 20 additions & 15 deletions packages/d2c-schematics/__tests__/header.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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",
Expand All @@ -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",
Expand Down
Loading

0 comments on commit 92c36ee

Please sign in to comment.