Skip to content

Commit 3fa4bdb

Browse files
committed
Fix up code
1 parent 33d6b99 commit 3fa4bdb

File tree

2 files changed

+48
-53
lines changed

2 files changed

+48
-53
lines changed

order-routing/javascript/local-pickup-delivery-option-generators/default/src/run.liquid

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,60 @@
22
// @ts-check
33

44
/**
5-
* @typedef {import("../generated/api").InputQuery} InputQuery
6-
* @typedef {import("../generated/api").FunctionResult} FunctionResult
5+
* @typedef {import("../generated/api").RunInput} RunInput
6+
* @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult
77
*/
88

99
/**
10-
* @type {FunctionResult}
10+
* @param {RunInput} input
11+
* @returns {FunctionRunResult}
1112
*/
12-
const DELIVERY_OPTION = {
13-
operations: [
14-
{
15-
add: {
16-
title: "Main St.",
17-
cost: 1.99,
18-
pickupLocation: {
19-
locationHandle: "2578303",
20-
pickupInstruction: "Usually ready in 24 hours."
21-
}
22-
}
23-
}
24-
],
25-
};
26-
27-
export default /**
28-
* @param {InputQuery} input
29-
* @returns {FunctionResult}
30-
*/
31-
(input) => {
13+
export function run(input) {
3214
const configuration = JSON.parse(
3315
input?.deliveryOptionGenerator?.metafield?.value ?? "{}"
3416
);
3517

36-
return DELIVERY_OPTION;
37-
};
18+
return {
19+
operations: [
20+
{
21+
add: {
22+
title: "Main St.",
23+
cost: 1.99,
24+
pickupLocation: {
25+
locationHandle: "2578303",
26+
pickupInstruction: "Usually ready in 24 hours."
27+
}
28+
}
29+
}
30+
],
31+
};
32+
}
3833
{%- elsif flavor contains "typescript" -%}
3934
import {
40-
InputQuery,
41-
FunctionResult,
35+
RunInput,
36+
FunctionRunResult,
4237
} from "../generated/api";
4338

44-
const DELIVERY_OPTION: FunctionResult = {
45-
operations: [
46-
{
47-
add: {
48-
title: "Main St.",
49-
cost: 1.99,
50-
pickupLocation: {
51-
locationHandle: "2578303",
52-
pickupInstruction: "Usually ready in 24 hours."
53-
}
54-
}
55-
}
56-
],
57-
};
58-
5939
type Configuration = {};
6040

61-
export default (input: InputQuery): FunctionResult => {
41+
export function run(input: RunInput): FunctionRunResult {
6242
const configuration: Configuration = JSON.parse(
6343
input?.deliveryOptionGenerator?.metafield?.value ?? "{}"
6444
);
65-
return DELIVERY_OPTION;
66-
};
45+
46+
return {
47+
operations: [
48+
{
49+
add: {
50+
title: "Main St.",
51+
cost: 1.99,
52+
pickupLocation: {
53+
locationHandle: "2578303",
54+
pickupInstruction: "Usually ready in 24 hours."
55+
}
56+
}
57+
}
58+
],
59+
};
60+
}
6761
{%- endif -%}

order-routing/javascript/local-pickup-delivery-option-generators/default/src/run.test.liquid

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{%- if flavor contains "vanilla-js" -%}
22
import { describe, it, expect } from 'vitest';
3-
import deliveryOptionGenerator from './run';
3+
import { run } from './run';
44

55
/**
6-
* @typedef {import("../generated/api").FunctionResult} FunctionResult
6+
* @typedef {import("../generated/api").RunInput} RunInput
7+
* @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult
78
*/
89

910
describe('local pickup delivery option generator function', () => {
1011
it('returns a delivery option', () => {
11-
const result = deliveryOptionGenerator({
12+
const result = run({
1213
cart: {
1314
lines: [
1415
{
@@ -43,7 +44,7 @@ describe('local pickup delivery option generator function', () => {
4344
metafield: null
4445
}
4546
});
46-
const expected = /** @type {FunctionResult} */ ({
47+
const expected = /** @type {FunctionRunResult} */ ({
4748
operations: [
4849
{
4950
add: {
@@ -63,12 +64,12 @@ describe('local pickup delivery option generator function', () => {
6364
});
6465
{%- elsif flavor contains "typescript" -%}
6566
import { describe, it, expect } from 'vitest';
66-
import deliveryOptionGenerator from './index';
67-
import { FunctionResult } from '../generated/api';
67+
import { run } from './run';
68+
import { RunInput, FunctionRunResult } from '../generated/api';
6869

6970
describe('local pickup delivery option generator function', () => {
7071
it('returns a delivery option', () => {
71-
const result = deliveryOptionGenerator({
72+
const result = run({
7273
cart: {
7374
lines: [
7475
{
@@ -103,7 +104,7 @@ describe('local pickup delivery option generator function', () => {
103104
metafield: null
104105
}
105106
});
106-
const expected: FunctionResult = {
107+
const expected: FunctionRunResult = {
107108
operations: [
108109
{
109110
add: {

0 commit comments

Comments
 (0)