Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to the API contract are documented here.

## Unreleased

- Add `Order.totalAmount`. `Order.total` is deprecated and will be removed once
thicket-web and thicket-mobile have migrated.

## 0.1.0

- Initial schema: products, carts, orders, payments, checkout, and full refunds.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Example query:
orders(customerId: "cus_avery") {
number
status
total
totalAmount
payment { status last4 }
}
}
Expand Down
4 changes: 3 additions & 1 deletion schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ type Order {
"Sales tax, in USD."
tax: Float!
"Amount charged for the order (subtotal + tax), in USD."
total: Float!
totalAmount: Float!
"Amount charged for the order (subtotal + tax), in USD."
total: Float! @deprecated(reason: "Use totalAmount.")
"ISO 4217 currency code."
currency: String!
payment: Payment!
Expand Down
2 changes: 2 additions & 0 deletions src/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export const resolvers = {
},
subtotal: (order: OrderRecord) => computeTotals(order.items).subtotal,
tax: (order: OrderRecord) => computeTotals(order.items).tax,
totalAmount: (order: OrderRecord) => computeTotals(order.items).total,
/** @deprecated Use totalAmount. Kept until clients have migrated. */
total: (order: OrderRecord) => computeTotals(order.items).total,
currency: () => 'USD',
payment: (order: OrderRecord, _: unknown, { store }: Context) => {
Expand Down
12 changes: 11 additions & 1 deletion test/orders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const ORDER = /* GraphQL */ `
subtotal
tax
total
totalAmount
currency
items { quantity unitPrice lineTotal product { name } }
payment { status method last4 amount }
Expand All @@ -27,6 +28,7 @@ describe('orders', () => {
subtotal: 43.99,
tax: 3.63,
total: 47.62,
totalAmount: 47.62,
currency: 'USD',
});
});
Expand All @@ -35,7 +37,15 @@ describe('orders', () => {
const { execute } = setup();
const { data } = await execute(ORDER, { id: 'ord_1001' });
expect(data.order.payment).toEqual({ status: 'CAPTURED', method: 'card', last4: '4242', amount: 47.62 });
expect(data.order.payment.amount).toBe(data.order.total);
expect(data.order.payment.amount).toBe(data.order.totalAmount);
});

it('keeps the deprecated total field equal to totalAmount', async () => {
const { execute } = setup();
const { data } = await execute(`{ orders { total totalAmount } }`);
for (const order of data.orders) {
expect(order.total).toBe(order.totalAmount);
}
});

it('every order exposes a payment', async () => {
Expand Down
Loading