Skip to content

Commit

Permalink
Fix up code
Browse files Browse the repository at this point in the history
  • Loading branch information
davejcameron committed Jan 28, 2025
1 parent 33d6b99 commit 3fa4bdb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,60 @@
// @ts-check

/**
* @typedef {import("../generated/api").InputQuery} InputQuery
* @typedef {import("../generated/api").FunctionResult} FunctionResult
* @typedef {import("../generated/api").RunInput} RunInput
* @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult
*/

/**
* @type {FunctionResult}
* @param {RunInput} input
* @returns {FunctionRunResult}
*/
const DELIVERY_OPTION = {
operations: [
{
add: {
title: "Main St.",
cost: 1.99,
pickupLocation: {
locationHandle: "2578303",
pickupInstruction: "Usually ready in 24 hours."
}
}
}
],
};

export default /**
* @param {InputQuery} input
* @returns {FunctionResult}
*/
(input) => {
export function run(input) {
const configuration = JSON.parse(
input?.deliveryOptionGenerator?.metafield?.value ?? "{}"
);

return DELIVERY_OPTION;
};
return {
operations: [
{
add: {
title: "Main St.",
cost: 1.99,
pickupLocation: {
locationHandle: "2578303",
pickupInstruction: "Usually ready in 24 hours."
}
}
}
],
};
}
{%- elsif flavor contains "typescript" -%}
import {
InputQuery,
FunctionResult,
RunInput,
FunctionRunResult,
} from "../generated/api";

const DELIVERY_OPTION: FunctionResult = {
operations: [
{
add: {
title: "Main St.",
cost: 1.99,
pickupLocation: {
locationHandle: "2578303",
pickupInstruction: "Usually ready in 24 hours."
}
}
}
],
};

type Configuration = {};

export default (input: InputQuery): FunctionResult => {
export function run(input: RunInput): FunctionRunResult {
const configuration: Configuration = JSON.parse(
input?.deliveryOptionGenerator?.metafield?.value ?? "{}"
);
return DELIVERY_OPTION;
};

return {
operations: [
{
add: {
title: "Main St.",
cost: 1.99,
pickupLocation: {
locationHandle: "2578303",
pickupInstruction: "Usually ready in 24 hours."
}
}
}
],
};
}
{%- endif -%}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{%- if flavor contains "vanilla-js" -%}
import { describe, it, expect } from 'vitest';
import deliveryOptionGenerator from './run';
import { run } from './run';

/**
* @typedef {import("../generated/api").FunctionResult} FunctionResult
* @typedef {import("../generated/api").RunInput} RunInput
* @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult
*/

describe('local pickup delivery option generator function', () => {
it('returns a delivery option', () => {
const result = deliveryOptionGenerator({
const result = run({
cart: {
lines: [
{
Expand Down Expand Up @@ -43,7 +44,7 @@ describe('local pickup delivery option generator function', () => {
metafield: null
}
});
const expected = /** @type {FunctionResult} */ ({
const expected = /** @type {FunctionRunResult} */ ({
operations: [
{
add: {
Expand All @@ -63,12 +64,12 @@ describe('local pickup delivery option generator function', () => {
});
{%- elsif flavor contains "typescript" -%}
import { describe, it, expect } from 'vitest';
import deliveryOptionGenerator from './index';
import { FunctionResult } from '../generated/api';
import { run } from './run';
import { RunInput, FunctionRunResult } from '../generated/api';

describe('local pickup delivery option generator function', () => {
it('returns a delivery option', () => {
const result = deliveryOptionGenerator({
const result = run({
cart: {
lines: [
{
Expand Down Expand Up @@ -103,7 +104,7 @@ describe('local pickup delivery option generator function', () => {
metafield: null
}
});
const expected: FunctionResult = {
const expected: FunctionRunResult = {
operations: [
{
add: {
Expand Down

0 comments on commit 3fa4bdb

Please sign in to comment.