diff --git a/README.md b/README.md index 98612a9..3b0f0ba 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Example query: orders(customerId: "cus_avery") { number status - total + totalAmount payment { status last4 } } } diff --git a/schema/schema.graphql b/schema/schema.graphql index d118aa5..0444031 100644 --- a/schema/schema.graphql +++ b/schema/schema.graphql @@ -63,7 +63,7 @@ type Order { "Sales tax, in USD." tax: Float! "Amount charged for the order (subtotal + tax), in USD." - total: Float! + totalAmount: Float! "ISO 4217 currency code." currency: String! payment: Payment! diff --git a/src/resolvers/index.ts b/src/resolvers/index.ts index 75861b1..1bfa683 100644 --- a/src/resolvers/index.ts +++ b/src/resolvers/index.ts @@ -76,7 +76,7 @@ export const resolvers = { }, subtotal: (order: OrderRecord) => computeTotals(order.items).subtotal, tax: (order: OrderRecord) => computeTotals(order.items).tax, - total: (order: OrderRecord) => computeTotals(order.items).total, + totalAmount: (order: OrderRecord) => computeTotals(order.items).total, currency: () => 'USD', payment: (order: OrderRecord, _: unknown, { store }: Context) => { const payment = store.payments.get(order.paymentId); diff --git a/test/checkout.test.ts b/test/checkout.test.ts index bf01a92..1e9ced3 100644 --- a/test/checkout.test.ts +++ b/test/checkout.test.ts @@ -4,7 +4,7 @@ import { setup } from './helpers'; const CHECKOUT = /* GraphQL */ ` mutation Checkout($input: CheckoutInput!) { checkout(input: $input) { - order { number status total items { quantity product { id } } } + order { number status totalAmount items { quantity product { id } } } payment { status last4 amount } } } @@ -19,7 +19,7 @@ describe('checkout', () => { input: { cartId: 'cart_avery', email: 'avery@example.com', shippingAddress: address, cardToken: 'tok_visa_4242' }, }); expect(errors).toBeUndefined(); - expect(data.checkout.order).toMatchObject({ number: 'TH-1005', status: 'PAID', total: 73.07 }); + expect(data.checkout.order).toMatchObject({ number: 'TH-1005', status: 'PAID', totalAmount: 73.07 }); expect(data.checkout.payment).toEqual({ status: 'CAPTURED', last4: '4242', amount: 73.07 }); expect(store.carts.get('cart_avery')!.items).toHaveLength(0); }); diff --git a/test/orders.test.ts b/test/orders.test.ts index 486d092..488c514 100644 --- a/test/orders.test.ts +++ b/test/orders.test.ts @@ -8,7 +8,7 @@ const ORDER = /* GraphQL */ ` status subtotal tax - total + totalAmount currency items { quantity unitPrice lineTotal product { name } } payment { status method last4 amount } @@ -26,7 +26,7 @@ describe('orders', () => { status: 'PAID', subtotal: 43.99, tax: 3.63, - total: 47.62, + totalAmount: 47.62, currency: 'USD', }); }); @@ -35,7 +35,7 @@ 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('every order exposes a payment', async () => {