Skip to content

Commit bd1feaa

Browse files
committed
Add JS tests
1 parent 5333fdc commit bd1feaa

File tree

17 files changed

+398
-8
lines changed

17 files changed

+398
-8
lines changed

checkout/javascript/cart-checkout-validation/default/package.json.liquid

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"shopify": "npm exec -- shopify",
77
"typegen": "npm exec -- shopify app function typegen",
88
"build": "npm exec -- shopify app function build",
9-
"preview": "npm exec -- shopify app function run"
9+
"preview": "npm exec -- shopify app function run",
10+
"test": "vitest"
1011
},
1112
"codegen": {
1213
"schema": "schema.graphql",
@@ -19,5 +20,8 @@
1920
]
2021
}
2122
}
23+
},
24+
"devDependencies": {
25+
"vitest": "^0.29.8"
2226
}
2327
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{%- if flavor contains "vanilla-js" -%}
2+
import { describe, it, expect } from 'vitest';
3+
import validateCart from './index';
4+
5+
/**
6+
* @typedef {import("../generated/api").FunctionResult} FunctionResult
7+
*/
8+
9+
describe('cart checkout validation function', () => {
10+
it('returns an error when quantity exceeds one', () => {
11+
const result = validateCart({
12+
cart: {
13+
lines: [
14+
{
15+
quantity: 3
16+
}
17+
]
18+
}
19+
});
20+
const expected = /** @type {FunctionResult} */ ({ errors: [
21+
{
22+
localizedMessage: "Not possible to order more than one of each",
23+
target: "cart"
24+
}
25+
] });
26+
27+
expect(result).toEqual(expected);
28+
});
29+
30+
it('returns no errors when quantity is one', () => {
31+
const result = validateCart({
32+
cart: {
33+
lines: [
34+
{
35+
quantity: 1
36+
}
37+
]
38+
}
39+
});
40+
const expected = /** @type {FunctionResult} */ ({ errors: [] });
41+
42+
expect(result).toEqual(expected);
43+
});
44+
});
45+
{%- elsif flavor contains "typescript" -%}
46+
import { describe, it, expect } from 'vitest';
47+
import validateCart from './index';
48+
import { FunctionResult } from "../generated/api";
49+
50+
describe('cart checkout validation function', () => {
51+
it('returns an error when quantity exceeds one', () => {
52+
const result = validateCart({
53+
cart: {
54+
lines: [
55+
{
56+
quantity: 3
57+
}
58+
]
59+
}
60+
});
61+
const expected: FunctionResult = { errors: [
62+
{
63+
localizedMessage: "Not possible to order more than one of each",
64+
target: "cart"
65+
}
66+
] };
67+
68+
expect(result).toEqual(expected);
69+
});
70+
71+
it('returns no errors when quantity is one', () => {
72+
const result = validateCart({
73+
cart: {
74+
lines: [
75+
{
76+
quantity: 1
77+
}
78+
]
79+
}
80+
});
81+
const expected: FunctionResult = { errors: [] };
82+
83+
expect(result).toEqual(expected);
84+
});
85+
});
86+
{%- endif -%}

checkout/javascript/delivery-customization/default/package.json.liquid

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"shopify": "npm exec -- shopify",
77
"typegen": "npm exec -- shopify app function typegen",
88
"build": "npm exec -- shopify app function build",
9-
"preview": "npm exec -- shopify app function run"
9+
"preview": "npm exec -- shopify app function run",
10+
"test": "vitest"
1011
},
1112
"codegen": {
1213
"schema": "schema.graphql",
@@ -19,5 +20,8 @@
1920
]
2021
}
2122
}
23+
},
24+
"devDependencies": {
25+
"vitest": "^0.29.8"
2226
}
2327
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{%- if flavor contains "vanilla-js" -%}
2+
import { describe, it, expect } from 'vitest';
3+
import deliveryCustomization from './index';
4+
5+
/**
6+
* @typedef {import("../generated/api").FunctionResult} FunctionResult
7+
*/
8+
9+
describe('delivery customization function', () => {
10+
it('returns no operations without configuration', () => {
11+
const result = deliveryCustomization({
12+
deliveryCustomization: {
13+
metafield: null
14+
}
15+
});
16+
const expected = /** @type {FunctionResult} */ ({ operations: [] });
17+
18+
expect(result).toEqual(expected);
19+
});
20+
});
21+
{%- elsif flavor contains "typescript" -%}
22+
import { describe, it, expect } from 'vitest';
23+
import deliveryCustomization from './index';
24+
import { FunctionResult } from '../generated/api';
25+
26+
describe('delivery customization function', () => {
27+
it('returns no operations without configuration', () => {
28+
const result = deliveryCustomization({
29+
deliveryCustomization: {
30+
metafield: null
31+
}
32+
});
33+
const expected: FunctionResult = { operations: [] };
34+
35+
expect(result).toEqual(expected);
36+
});
37+
});
38+
{% endif -%}

checkout/javascript/payment-customization/default/package.json.liquid

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"shopify": "npm exec -- shopify",
77
"typegen": "npm exec -- shopify app function typegen",
88
"build": "npm exec -- shopify app function build",
9-
"preview": "npm exec -- shopify app function run"
9+
"preview": "npm exec -- shopify app function run",
10+
"test": "vitest"
1011
},
1112
"codegen": {
1213
"schema": "schema.graphql",
@@ -19,5 +20,8 @@
1920
]
2021
}
2122
}
23+
},
24+
"devDependencies": {
25+
"vitest": "^0.29.8"
2226
}
2327
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{%- if flavor contains "vanilla-js" -%}
2+
import { describe, it, expect } from 'vitest';
3+
import paymentCustomization from './index';
4+
5+
/**
6+
* @typedef {import("../generated/api").FunctionResult} FunctionResult
7+
*/
8+
9+
describe('payment customization function', () => {
10+
it('returns no operations without configuration', () => {
11+
const result = paymentCustomization({
12+
paymentCustomization: {
13+
metafield: null
14+
}
15+
});
16+
const expected = /** @type {FunctionResult} */ ({ operations: [] });
17+
18+
expect(result).toEqual(expected);
19+
});
20+
});
21+
{%- elsif flavor contains "typescript" -%}
22+
import { describe, it, expect } from 'vitest';
23+
import paymentCustomization from './index';
24+
import { FunctionResult } from '../generated/api';
25+
26+
describe('payment customization function', () => {
27+
it('returns no operations without configuration', () => {
28+
const result = paymentCustomization({
29+
paymentCustomization: {
30+
metafield: null
31+
}
32+
});
33+
const expected: FunctionResult = { operations: [] };
34+
35+
expect(result).toEqual(expected);
36+
});
37+
});
38+
{%- endif -%}

discounts/javascript/order-discounts/default/package.json.liquid

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"shopify": "npm exec -- shopify",
77
"typegen": "npm exec -- shopify app function typegen",
88
"build": "npm exec -- shopify app function build",
9-
"preview": "npm exec -- shopify app function run"
9+
"preview": "npm exec -- shopify app function run",
10+
"test": "vitest"
1011
},
1112
"codegen": {
1213
"schema": "schema.graphql",
@@ -19,5 +20,8 @@
1920
]
2021
}
2122
}
23+
},
24+
"devDependencies": {
25+
"vitest": "^0.29.8"
2226
}
2327
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{%- if flavor contains "vanilla-js" -%}
2+
import { describe, it, expect } from 'vitest';
3+
import orderDiscounts from './index';
4+
5+
/**
6+
* @typedef {import("../generated/api").FunctionResult} FunctionResult
7+
*/
8+
9+
describe('order discounts function', () => {
10+
it('returns no discounts without configuration', () => {
11+
const result = orderDiscounts({
12+
discountNode: {
13+
metafield: null
14+
}
15+
});
16+
const expected = /** @type {FunctionResult} */ ({
17+
discounts: [],
18+
discountApplicationStrategy: "FIRST",
19+
});
20+
21+
expect(result).toEqual(expected);
22+
});
23+
});
24+
{%- elsif flavor contains "typescript" -%}
25+
import { describe, it, expect } from 'vitest';
26+
import orderDiscounts from './index';
27+
import { FunctionResult, DiscountApplicationStrategy } from '../generated/api';
28+
29+
describe('order discounts function', () => {
30+
it('returns no discounts without configuration', () => {
31+
const result = orderDiscounts({
32+
discountNode: {
33+
metafield: null
34+
}
35+
});
36+
const expected: FunctionResult = {
37+
discounts: [],
38+
discountApplicationStrategy: DiscountApplicationStrategy.First,
39+
};
40+
41+
expect(result).toEqual(expected);
42+
});
43+
});
44+
{%- endif -%}

discounts/javascript/product-discounts/default/package.json.liquid

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"shopify": "npm exec -- shopify",
77
"typegen": "npm exec -- shopify app function typegen",
88
"build": "npm exec -- shopify app function build",
9-
"preview": "npm exec -- shopify app function run"
9+
"preview": "npm exec -- shopify app function run",
10+
"test": "vitest"
1011
},
1112
"codegen": {
1213
"schema": "schema.graphql",
@@ -19,5 +20,8 @@
1920
]
2021
}
2122
}
23+
},
24+
"devDependencies": {
25+
"vitest": "^0.29.8"
2226
}
2327
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{%- if flavor contains "vanilla-js" -%}
2+
import { describe, it, expect } from 'vitest';
3+
import productDiscounts from './index';
4+
5+
/**
6+
* @typedef {import("../generated/api").FunctionResult} FunctionResult
7+
*/
8+
9+
describe('product discounts function', () => {
10+
it('returns no discounts without configuration', () => {
11+
const result = productDiscounts({
12+
discountNode: {
13+
metafield: null
14+
}
15+
});
16+
const expected = /** @type {FunctionResult} */ ({
17+
discounts: [],
18+
discountApplicationStrategy: "FIRST",
19+
});
20+
21+
expect(result).toEqual(expected);
22+
});
23+
});
24+
{%- elsif flavor contains "typescript" -%}
25+
import { describe, it, expect } from 'vitest';
26+
import productDiscounts from './index';
27+
import { FunctionResult, DiscountApplicationStrategy } from '../generated/api';
28+
29+
describe('product discounts function', () => {
30+
it('returns no discounts without configuration', () => {
31+
const result = productDiscounts({
32+
discountNode: {
33+
metafield: null
34+
}
35+
});
36+
const expected: FunctionResult = {
37+
discounts: [],
38+
discountApplicationStrategy: DiscountApplicationStrategy.First,
39+
};
40+
41+
expect(result).toEqual(expected);
42+
});
43+
});
44+
{%- endif -%}

0 commit comments

Comments
 (0)