order.e2e-spec.ts 2.5 KB

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