order.e2e-spec.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* tslint:disable:no-non-null-assertion */
  2. import gql from 'graphql-tag';
  3. import path from 'path';
  4. import { TEST_SETUP_TIMEOUT_MS } from './config/test-config';
  5. import { ORDER_FRAGMENT, ORDER_WITH_LINES_FRAGMENT } from './graphql/fragments';
  6. import { GetCustomerList, GetOrder, GetOrderList } from './graphql/generated-e2e-admin-types';
  7. import { AddItemToOrder } from './graphql/generated-e2e-shop-types';
  8. import { GET_CUSTOMER_LIST } from './graphql/shared-definitions';
  9. import { ADD_ITEM_TO_ORDER } from './graphql/shop-definitions';
  10. import { TestAdminClient, TestShopClient } from './test-client';
  11. import { TestServer } from './test-server';
  12. describe('Orders resolver', () => {
  13. const adminClient = new TestAdminClient();
  14. const shopClient = new TestShopClient();
  15. const server = new TestServer();
  16. let customers: GetCustomerList.Items[];
  17. const password = 'test';
  18. beforeAll(async () => {
  19. const token = await server.init({
  20. productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-full.csv'),
  21. customerCount: 2,
  22. });
  23. await adminClient.init();
  24. // Create a couple of orders to be queried
  25. const result = await adminClient.query<GetCustomerList.Query, GetCustomerList.Variables>(
  26. GET_CUSTOMER_LIST,
  27. {
  28. options: {
  29. take: 2,
  30. },
  31. },
  32. );
  33. customers = result.customers.items;
  34. await shopClient.asUserWithCredentials(customers[0].emailAddress, password);
  35. await shopClient.query<AddItemToOrder.Mutation, AddItemToOrder.Variables>(ADD_ITEM_TO_ORDER, {
  36. productVariantId: 'T_1',
  37. quantity: 1,
  38. });
  39. await shopClient.asUserWithCredentials(customers[1].emailAddress, password);
  40. await shopClient.query<AddItemToOrder.Mutation, AddItemToOrder.Variables>(ADD_ITEM_TO_ORDER, {
  41. productVariantId: 'T_2',
  42. quantity: 1,
  43. });
  44. }, TEST_SETUP_TIMEOUT_MS);
  45. afterAll(async () => {
  46. await server.destroy();
  47. });
  48. it('orders', async () => {
  49. const result = await adminClient.query<GetOrderList.Query>(GET_ORDERS_LIST);
  50. expect(result.orders.items.map(o => o.id)).toEqual(['T_1', 'T_2']);
  51. });
  52. it('order', async () => {
  53. const result = await adminClient.query<GetOrder.Query, GetOrder.Variables>(GET_ORDER, { id: 'T_2' });
  54. expect(result.order!.id).toBe('T_2');
  55. });
  56. });
  57. export const GET_ORDERS_LIST = gql`
  58. query GetOrderList($options: OrderListOptions) {
  59. orders(options: $options) {
  60. items {
  61. ...Order
  62. }
  63. totalItems
  64. }
  65. }
  66. ${ORDER_FRAGMENT}
  67. `;
  68. export const GET_ORDER = gql`
  69. query GetOrder($id: ID!) {
  70. order(id: $id) {
  71. ...OrderWithLines
  72. }
  73. }
  74. ${ORDER_WITH_LINES_FRAGMENT}
  75. `;