Skip to content

Rename discount schema properties #602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("discount", () => {

expect(result.operations.length).toBe(2);
expect(result.operations[0]).toMatchObject({
addOrderDiscounts: {
orderDiscountsAdd: {
candidates: [
{
message: "10% OFF ORDER",
Expand All @@ -50,7 +50,7 @@ describe("discount", () => {
});

expect(result.operations[1]).toMatchObject({
addProductDiscounts: {
productDiscountsAdd: {
candidates: [
{
message: "20% OFF PRODUCT",
Expand Down Expand Up @@ -88,7 +88,7 @@ describe("discount", () => {

expect(result.operations.length).toBe(1);
expect(result.operations[0]).toMatchObject({
addDeliveryDiscounts: {
deliveryDiscountsAdd: {
candidates: [
{
message: "FREE DELIVERY",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {

/**
* @typedef {import("../generated/api").CartInput} CartInput
* @typedef {import("../generated/api").FunctionCartRunResult} FunctionCartRunResult
* @typedef {import("../generated/api").CartLinesDiscountsGenerateRunResult} CartLinesDiscountsGenerateRunResult
*/

/**
* generateCartRun
* @param {CartInput} input - The CartInput
* @returns {FunctionCartRunResult} - The function result with discounts.
* @returns {CartLinesDiscountsGenerateRunResult} - The function result with discounts.
*/
export function generateCartRun(input) {
if (!input.cart.lines.length) {
Expand All @@ -29,7 +29,7 @@ export function generateCartRun(input) {
return {
operations: [
{
addOrderDiscounts: {
orderDiscountsAdd: {
candidates: [
{
message: '10% OFF ORDER',
Expand All @@ -51,7 +51,7 @@ export function generateCartRun(input) {
},
},
{
addProductDiscounts: {
productDiscountsAdd: {
candidates: [
{
message: '20% OFF PRODUCT',
Expand Down Expand Up @@ -80,10 +80,10 @@ import {
OrderDiscountSelectionStrategy,
ProductDiscountSelectionStrategy,
CartInput,
FunctionCartRunResult,
CartLinesDiscountsGenerateRunResult,
} from '../generated/api';

export function generateCartRun(input: CartInput): FunctionCartRunResult {
export function generateCartRun(input: CartInput): CartLinesDiscountsGenerateRunResult {
if (!input.cart.lines.length) {
throw new Error('No cart lines found');
}
Expand All @@ -98,7 +98,7 @@ export function generateCartRun(input: CartInput): FunctionCartRunResult {
return {
operations: [
{
addOrderDiscounts: {
orderDiscountsAdd: {
candidates: [
{
message: '10% OFF ORDER',
Expand All @@ -120,7 +120,7 @@ export function generateCartRun(input: CartInput): FunctionCartRunResult {
},
},
{
addProductDiscounts: {
productDiscountsAdd: {
candidates: [
{
message: '20% OFF PRODUCT',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { DeliveryDiscountSelectionStrategy} from '../generated/api';

/**
* @typedef {import("../generated/api").DeliveryInput} RunInput
* @typedef {import("../generated/api").FunctionDeliveryRunResult} FunctionDeliveryRunResult
* @typedef {import("../generated/api").CartDeliveryOptionsDiscountsGenerateRunResult} CartDeliveryOptionsDiscountsGenerateRunResult
*/
/**
* generateDeliveryRun
* @param {RunInput} input - The DeliveryInput
* @returns {FunctionDeliveryRunResult} - The function result with discounts.
* @returns {CartDeliveryOptionsDiscountsGenerateRunResult} - The function result with discounts.
*/
export function generateDeliveryRun(input) {
const firstDeliveryGroup = input.cart.deliveryGroups[0];
Expand All @@ -20,7 +20,7 @@ export function generateDeliveryRun(input) {
return {
operations: [
{
addDeliveryDiscounts: {
deliveryDiscountsAdd: {
candidates: [
{
message: 'FREE DELIVERY',
Expand Down Expand Up @@ -48,12 +48,12 @@ export function generateDeliveryRun(input) {
import {
DeliveryDiscountSelectionStrategy,
DeliveryInput,
FunctionDeliveryRunResult,
CartDeliveryOptionsDiscountsGenerateRunResult,
} from '../generated/api';

export function generateDeliveryRun(
input: DeliveryInput,
): FunctionDeliveryRunResult {
): CartDeliveryOptionsDiscountsGenerateRunResult {
const firstDeliveryGroup = input.cart.deliveryGroups[0];
if (!firstDeliveryGroup) {
throw new Error('No delivery groups found');
Expand All @@ -62,7 +62,7 @@ export function generateDeliveryRun(
return {
operations: [
{
addDeliveryDiscounts: {
deliveryDiscountsAdd: {
candidates: [
{
message: 'FREE DELIVERY',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {HttpRequestMethod} from '../generated/api';

/**
* @typedef {import("../generated/api").InputCartFetch} InputCartFetch
* @typedef {import("../generated/api").FunctionCartFetchResult} FunctionCartFetchResult
* @typedef {import("../generated/api").CartLinesDiscountsGenerateFetchResult} CartLinesDiscountsGenerateFetchResult
*/
/**
* Generates a network request to fetch cart discount information
* @param {InputCartFetch} input - The cart fetch input data
* @returns {FunctionCartFetchResult} - The function result with network request configuration
* @returns {CartLinesDiscountsGenerateFetchResult} - The function result with network request configuration
*/
export function generateCartFetch(input) {
const { enteredDiscountCodes } = input;
Expand All @@ -36,12 +36,12 @@ export function generateCartFetch(input) {
import {
HttpRequestMethod,
InputCartFetch,
FunctionCartFetchResult,
CartLinesDiscountsGenerateFetchResult,
} from '../generated/api';

export function generateCartFetch(
input: InputCartFetch,
): FunctionCartFetchResult {
): CartLinesDiscountsGenerateFetchResult {
const {enteredDiscountCodes} = input;
const jsonBody = {enteredDiscountCodes};
const request = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// @ts-check
/**
* @typedef {import("../generated/api").InputCartRun} InputCartRun
* @typedef {import("../generated/api").FunctionCartRunResult} FunctionCartRunResult
* @typedef {import("../generated/api").CartLinesDiscountsGenerateRunResult} CartLinesDiscountsGenerateRunResult
*/
/**
* Processes the fetched cart discount data and generates operations
* @param {InputCartRun} input - The cart run input data including fetch results
* @returns {FunctionCartRunResult} - The function result with discount operations
* @returns {CartLinesDiscountsGenerateRunResult} - The function result with discount operations
*/
export function generateCartRun(input) {
const { fetchResult } = input;
Expand All @@ -20,9 +20,9 @@ export function generateCartRun(input) {
return { operations };
}
{%- elsif flavor contains "typescript" -%}
import {InputCartRun, FunctionCartRunResult} from '../generated/api';
import {InputCartRun, CartLinesDiscountsGenerateRunResult} from '../generated/api';

export function generateCartRun(input: InputCartRun): FunctionCartRunResult {
export function generateCartRun(input: InputCartRun): CartLinesDiscountsGenerateRunResult {
const {fetchResult} = input;
const body = fetchResult?.body;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {HttpRequestMethod} from '../generated/api';

/**
* @typedef {import("../generated/api").InputDeliveryFetch} InputDeliveryFetch
* @typedef {import("../generated/api").FunctionDeliveryFetchResult} FunctionDeliveryFetchResult
* @typedef {import("../generated/api").CartDeliveryOptionsDiscountsGenerateFetchResult} CartDeliveryOptionsDiscountsGenerateFetchResult
*/
/**
* Generates a network request to fetch delivery discount information
* @param {InputDeliveryFetch} input - The delivery fetch input data
* @returns {FunctionDeliveryFetchResult} - The function result with network request configuration
* @returns {CartDeliveryOptionsDiscountsGenerateFetchResult} - The function result with network request configuration
*/
export function generateDeliveryFetch(input) {
const { enteredDiscountCodes } = input;
Expand All @@ -35,11 +35,11 @@ export function generateDeliveryFetch(input) {
import {
HttpRequestMethod,
InputDeliveryFetch,
FunctionDeliveryFetchResult,
CartDeliveryOptionsDiscountsGenerateFetchResult,
} from '../generated/api';
export function generateDeliveryFetch(
input: InputDeliveryFetch,
): FunctionDeliveryFetchResult {
): CartDeliveryOptionsDiscountsGenerateFetchResult {
const {enteredDiscountCodes} = input;
const jsonBody = {enteredDiscountCodes};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// @ts-check
/**
* @typedef {import("../generated/api").InputDeliveryRun} InputDeliveryRun
* @typedef {import("../generated/api").FunctionDeliveryRunResult} FunctionDeliveryRunResult
* @typedef {import("../generated/api").CartDeliveryOptionsDiscountsGenerateRunResult} CartDeliveryOptionsDiscountsGenerateRunResult
*/
/**
* Processes the fetched delivery discount data and generates operations
* @param {InputDeliveryRun} input - The delivery run input data including fetch results
* @returns {FunctionDeliveryRunResult} - The function result with discount operations
* @returns {CartDeliveryOptionsDiscountsGenerateRunResult} - The function result with discount operations
*/
export function generateDeliveryRun(input) {
const { fetchResult } = input;
Expand All @@ -20,11 +20,11 @@ export function generateDeliveryRun(input) {
return { operations };
}
{%- elsif flavor contains "typescript" -%}
import {InputDeliveryRun, FunctionDeliveryRunResult} from '../generated/api';
import {InputDeliveryRun, CartDeliveryOptionsDiscountsGenerateRunResult} from '../generated/api';

export function generateDeliveryRun(
input: InputDeliveryRun,
): FunctionDeliveryRunResult {
): CartDeliveryOptionsDiscountsGenerateRunResult {
const {fetchResult} = input;
const body = fetchResult?.body;

Expand Down
10 changes: 5 additions & 5 deletions discounts/javascript/network/default/src/network.test.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ describe("discount", () => {
it("cart.lines.discounts.generate.run returns a list of operations", () => {
const operations = [
{
addDiscountCodeValidations: {
enteredDiscountCodesAccept: {
codes: ["10% OFF ORDER", "20% OFF PRODUCT"],
},
},
{
addOrderDiscounts: {
orderDiscountsAdd: {
candidates: [
{
message: "10% OFF ORDER",
Expand All @@ -89,7 +89,7 @@ describe("discount", () => {
},
},
{
addProductDiscounts: {
productDiscountsAdd: {
candidates: [
{
message: "20% OFF PRODUCT",
Expand Down Expand Up @@ -126,12 +126,12 @@ describe("discount", () => {
it("cart.delivery-options.discounts.generate.run returns a list of operations", () => {
const operations = [
{
addDiscountCodeValidations: {
enteredDiscountCodesAccept: {
codes: ["FREE_DELIVERY"],
},
},
{
addDeliveryDiscounts: {
deliveryDiscountsAdd: {
candidates: [
{
message: "FREE DELIVERY",
Expand Down
Loading