customer.e2e-spec.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. import { OnModuleInit } from '@nestjs/common';
  2. import { HistoryEntryType } from '@vendure/common/lib/generated-types';
  3. import { omit } from '@vendure/common/lib/omit';
  4. import { pick } from '@vendure/common/lib/pick';
  5. import {
  6. AccountRegistrationEvent,
  7. EventBus,
  8. EventBusModule,
  9. mergeConfig,
  10. VendurePlugin,
  11. } from '@vendure/core';
  12. import { createErrorResultGuard, createTestEnvironment, ErrorResultGuard } from '@vendure/testing';
  13. import gql from 'graphql-tag';
  14. import path from 'path';
  15. import { initialData } from '../../../e2e-common/e2e-initial-data';
  16. import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
  17. import { CUSTOMER_FRAGMENT } from './graphql/fragments';
  18. import {
  19. AddNoteToCustomer,
  20. CreateAddress,
  21. CreateCustomer,
  22. CustomerFragment,
  23. DeleteCustomer,
  24. DeleteCustomerAddress,
  25. DeleteCustomerNote,
  26. DeletionResult,
  27. ErrorCode,
  28. GetCustomer,
  29. GetCustomerHistory,
  30. GetCustomerList,
  31. GetCustomerOrders,
  32. GetCustomerWithUser,
  33. UpdateAddress,
  34. UpdateCustomer,
  35. UpdateCustomerNote,
  36. } from './graphql/generated-e2e-admin-types';
  37. import { AddItemToOrder, UpdatedOrderFragment } from './graphql/generated-e2e-shop-types';
  38. import {
  39. CREATE_ADDRESS,
  40. CREATE_CUSTOMER,
  41. DELETE_CUSTOMER,
  42. DELETE_CUSTOMER_NOTE,
  43. GET_CUSTOMER,
  44. GET_CUSTOMER_HISTORY,
  45. GET_CUSTOMER_LIST,
  46. UPDATE_ADDRESS,
  47. UPDATE_CUSTOMER,
  48. UPDATE_CUSTOMER_NOTE,
  49. } from './graphql/shared-definitions';
  50. import { ADD_ITEM_TO_ORDER } from './graphql/shop-definitions';
  51. import { assertThrowsWithMessage } from './utils/assert-throws-with-message';
  52. // tslint:disable:no-non-null-assertion
  53. let sendEmailFn: jest.Mock;
  54. /**
  55. * This mock plugin simulates an EmailPlugin which would send emails
  56. * on the registration & password reset events.
  57. */
  58. @VendurePlugin({
  59. imports: [EventBusModule],
  60. })
  61. class TestEmailPlugin implements OnModuleInit {
  62. constructor(private eventBus: EventBus) {}
  63. onModuleInit() {
  64. this.eventBus.ofType(AccountRegistrationEvent).subscribe(event => {
  65. sendEmailFn(event);
  66. });
  67. }
  68. }
  69. describe('Customer resolver', () => {
  70. const { server, adminClient, shopClient } = createTestEnvironment(
  71. mergeConfig(testConfig, { plugins: [TestEmailPlugin] }),
  72. );
  73. let firstCustomer: GetCustomerList.Items;
  74. let secondCustomer: GetCustomerList.Items;
  75. let thirdCustomer: GetCustomerList.Items;
  76. const customerErrorGuard: ErrorResultGuard<CustomerFragment> = createErrorResultGuard(
  77. input => !!input.emailAddress,
  78. );
  79. beforeAll(async () => {
  80. await server.init({
  81. initialData,
  82. productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-minimal.csv'),
  83. customerCount: 5,
  84. });
  85. await adminClient.asSuperAdmin();
  86. }, TEST_SETUP_TIMEOUT_MS);
  87. afterAll(async () => {
  88. await server.destroy();
  89. });
  90. it('customers list', async () => {
  91. const result = await adminClient.query<GetCustomerList.Query, GetCustomerList.Variables>(
  92. GET_CUSTOMER_LIST,
  93. );
  94. expect(result.customers.items.length).toBe(5);
  95. expect(result.customers.totalItems).toBe(5);
  96. firstCustomer = result.customers.items[0];
  97. secondCustomer = result.customers.items[1];
  98. thirdCustomer = result.customers.items[2];
  99. });
  100. it('customer resolver resolves User', async () => {
  101. const { customer } = await adminClient.query<
  102. GetCustomerWithUser.Query,
  103. GetCustomerWithUser.Variables
  104. >(GET_CUSTOMER_WITH_USER, {
  105. id: firstCustomer.id,
  106. });
  107. expect(customer!.user).toEqual({
  108. id: 'T_2',
  109. identifier: firstCustomer.emailAddress,
  110. verified: true,
  111. });
  112. });
  113. describe('addresses', () => {
  114. let firstCustomerAddressIds: string[] = [];
  115. let firstCustomerThirdAddressId: string;
  116. it(
  117. 'createCustomerAddress throws on invalid countryCode',
  118. assertThrowsWithMessage(
  119. () =>
  120. adminClient.query<CreateAddress.Mutation, CreateAddress.Variables>(CREATE_ADDRESS, {
  121. id: firstCustomer.id,
  122. input: {
  123. streetLine1: 'streetLine1',
  124. countryCode: 'INVALID',
  125. },
  126. }),
  127. `The countryCode "INVALID" was not recognized`,
  128. ),
  129. );
  130. it('createCustomerAddress creates a new address', async () => {
  131. const result = await adminClient.query<CreateAddress.Mutation, CreateAddress.Variables>(
  132. CREATE_ADDRESS,
  133. {
  134. id: firstCustomer.id,
  135. input: {
  136. fullName: 'fullName',
  137. company: 'company',
  138. streetLine1: 'streetLine1',
  139. streetLine2: 'streetLine2',
  140. city: 'city',
  141. province: 'province',
  142. postalCode: 'postalCode',
  143. countryCode: 'GB',
  144. phoneNumber: 'phoneNumber',
  145. defaultShippingAddress: false,
  146. defaultBillingAddress: false,
  147. },
  148. },
  149. );
  150. expect(omit(result.createCustomerAddress, ['id'])).toEqual({
  151. fullName: 'fullName',
  152. company: 'company',
  153. streetLine1: 'streetLine1',
  154. streetLine2: 'streetLine2',
  155. city: 'city',
  156. province: 'province',
  157. postalCode: 'postalCode',
  158. country: {
  159. code: 'GB',
  160. name: 'United Kingdom',
  161. },
  162. phoneNumber: 'phoneNumber',
  163. defaultShippingAddress: false,
  164. defaultBillingAddress: false,
  165. });
  166. });
  167. it('customer query returns addresses', async () => {
  168. const result = await adminClient.query<GetCustomer.Query, GetCustomer.Variables>(GET_CUSTOMER, {
  169. id: firstCustomer.id,
  170. });
  171. expect(result.customer!.addresses!.length).toBe(2);
  172. firstCustomerAddressIds = result.customer!.addresses!.map(a => a.id).sort();
  173. });
  174. it('updateCustomerAddress updates the country', async () => {
  175. const result = await adminClient.query<UpdateAddress.Mutation, UpdateAddress.Variables>(
  176. UPDATE_ADDRESS,
  177. {
  178. input: {
  179. id: firstCustomerAddressIds[0],
  180. countryCode: 'AT',
  181. },
  182. },
  183. );
  184. expect(result.updateCustomerAddress.country).toEqual({
  185. code: 'AT',
  186. name: 'Austria',
  187. });
  188. });
  189. it('updateCustomerAddress allows only a single default address', async () => {
  190. // set the first customer's second address to be default
  191. const result1 = await adminClient.query<UpdateAddress.Mutation, UpdateAddress.Variables>(
  192. UPDATE_ADDRESS,
  193. {
  194. input: {
  195. id: firstCustomerAddressIds[1],
  196. defaultShippingAddress: true,
  197. defaultBillingAddress: true,
  198. },
  199. },
  200. );
  201. expect(result1.updateCustomerAddress.defaultShippingAddress).toBe(true);
  202. expect(result1.updateCustomerAddress.defaultBillingAddress).toBe(true);
  203. // assert the first customer's other addresse is not default
  204. const result2 = await adminClient.query<GetCustomer.Query, GetCustomer.Variables>(GET_CUSTOMER, {
  205. id: firstCustomer.id,
  206. });
  207. const otherAddress = result2.customer!.addresses!.filter(
  208. a => a.id !== firstCustomerAddressIds[1],
  209. )[0]!;
  210. expect(otherAddress.defaultShippingAddress).toBe(false);
  211. expect(otherAddress.defaultBillingAddress).toBe(false);
  212. // set the first customer's first address to be default
  213. const result3 = await adminClient.query<UpdateAddress.Mutation, UpdateAddress.Variables>(
  214. UPDATE_ADDRESS,
  215. {
  216. input: {
  217. id: firstCustomerAddressIds[0],
  218. defaultShippingAddress: true,
  219. defaultBillingAddress: true,
  220. },
  221. },
  222. );
  223. expect(result3.updateCustomerAddress.defaultShippingAddress).toBe(true);
  224. expect(result3.updateCustomerAddress.defaultBillingAddress).toBe(true);
  225. // assert the first customer's second address is not default
  226. const result4 = await adminClient.query<GetCustomer.Query, GetCustomer.Variables>(GET_CUSTOMER, {
  227. id: firstCustomer.id,
  228. });
  229. const otherAddress2 = result4.customer!.addresses!.filter(
  230. a => a.id !== firstCustomerAddressIds[0],
  231. )[0]!;
  232. expect(otherAddress2.defaultShippingAddress).toBe(false);
  233. expect(otherAddress2.defaultBillingAddress).toBe(false);
  234. // get the second customer's address id
  235. const result5 = await adminClient.query<GetCustomer.Query, GetCustomer.Variables>(GET_CUSTOMER, {
  236. id: secondCustomer.id,
  237. });
  238. const secondCustomerAddressId = result5.customer!.addresses![0].id;
  239. // set the second customer's address to be default
  240. const result6 = await adminClient.query<UpdateAddress.Mutation, UpdateAddress.Variables>(
  241. UPDATE_ADDRESS,
  242. {
  243. input: {
  244. id: secondCustomerAddressId,
  245. defaultShippingAddress: true,
  246. defaultBillingAddress: true,
  247. },
  248. },
  249. );
  250. expect(result6.updateCustomerAddress.defaultShippingAddress).toBe(true);
  251. expect(result6.updateCustomerAddress.defaultBillingAddress).toBe(true);
  252. // assets the first customer's address defaults are unchanged
  253. const result7 = await adminClient.query<GetCustomer.Query, GetCustomer.Variables>(GET_CUSTOMER, {
  254. id: firstCustomer.id,
  255. });
  256. expect(result7.customer!.addresses![0].defaultShippingAddress).toBe(true);
  257. expect(result7.customer!.addresses![0].defaultBillingAddress).toBe(true);
  258. expect(result7.customer!.addresses![1].defaultShippingAddress).toBe(false);
  259. expect(result7.customer!.addresses![1].defaultBillingAddress).toBe(false);
  260. });
  261. it('createCustomerAddress with true defaults unsets existing defaults', async () => {
  262. const { createCustomerAddress } = await adminClient.query<
  263. CreateAddress.Mutation,
  264. CreateAddress.Variables
  265. >(CREATE_ADDRESS, {
  266. id: firstCustomer.id,
  267. input: {
  268. streetLine1: 'new default streetline',
  269. countryCode: 'GB',
  270. defaultShippingAddress: true,
  271. defaultBillingAddress: true,
  272. },
  273. });
  274. expect(omit(createCustomerAddress, ['id'])).toEqual({
  275. fullName: '',
  276. company: '',
  277. streetLine1: 'new default streetline',
  278. streetLine2: '',
  279. city: '',
  280. province: '',
  281. postalCode: '',
  282. country: {
  283. code: 'GB',
  284. name: 'United Kingdom',
  285. },
  286. phoneNumber: '',
  287. defaultShippingAddress: true,
  288. defaultBillingAddress: true,
  289. });
  290. const { customer } = await adminClient.query<GetCustomer.Query, GetCustomer.Variables>(
  291. GET_CUSTOMER,
  292. {
  293. id: firstCustomer.id,
  294. },
  295. );
  296. for (const address of customer!.addresses!) {
  297. const shouldBeDefault = address.id === createCustomerAddress.id;
  298. expect(address.defaultShippingAddress).toEqual(shouldBeDefault);
  299. expect(address.defaultBillingAddress).toEqual(shouldBeDefault);
  300. }
  301. firstCustomerThirdAddressId = createCustomerAddress.id;
  302. });
  303. it('deleteCustomerAddress on default address resets defaults', async () => {
  304. const { deleteCustomerAddress } = await adminClient.query<
  305. DeleteCustomerAddress.Mutation,
  306. DeleteCustomerAddress.Variables
  307. >(
  308. gql`
  309. mutation DeleteCustomerAddress($id: ID!) {
  310. deleteCustomerAddress(id: $id) {
  311. success
  312. }
  313. }
  314. `,
  315. { id: firstCustomerThirdAddressId },
  316. );
  317. expect(deleteCustomerAddress.success).toBe(true);
  318. const { customer } = await adminClient.query<GetCustomer.Query, GetCustomer.Variables>(
  319. GET_CUSTOMER,
  320. {
  321. id: firstCustomer.id,
  322. },
  323. );
  324. expect(customer!.addresses!.length).toBe(2);
  325. const defaultAddress = customer!.addresses!.filter(
  326. a => a.defaultBillingAddress && a.defaultShippingAddress,
  327. );
  328. const otherAddress = customer!.addresses!.filter(
  329. a => !a.defaultBillingAddress && !a.defaultShippingAddress,
  330. );
  331. expect(defaultAddress.length).toBe(1);
  332. expect(otherAddress.length).toBe(1);
  333. });
  334. });
  335. describe('orders', () => {
  336. const orderResultGuard: ErrorResultGuard<UpdatedOrderFragment> = createErrorResultGuard(
  337. input => !!input.lines,
  338. );
  339. it(`lists that user\'s orders`, async () => {
  340. // log in as first customer
  341. await shopClient.asUserWithCredentials(firstCustomer.emailAddress, 'test');
  342. // add an item to the order to create an order
  343. const { addItemToOrder } = await shopClient.query<
  344. AddItemToOrder.Mutation,
  345. AddItemToOrder.Variables
  346. >(ADD_ITEM_TO_ORDER, {
  347. productVariantId: 'T_1',
  348. quantity: 1,
  349. });
  350. orderResultGuard.assertSuccess(addItemToOrder);
  351. const { customer } = await adminClient.query<
  352. GetCustomerOrders.Query,
  353. GetCustomerOrders.Variables
  354. >(GET_CUSTOMER_ORDERS, { id: firstCustomer.id });
  355. expect(customer!.orders.totalItems).toBe(1);
  356. expect(customer!.orders.items[0].id).toBe(addItemToOrder!.id);
  357. });
  358. });
  359. describe('creation', () => {
  360. it('triggers verification event if no password supplied', async () => {
  361. sendEmailFn = jest.fn();
  362. const { createCustomer } = await adminClient.query<
  363. CreateCustomer.Mutation,
  364. CreateCustomer.Variables
  365. >(CREATE_CUSTOMER, {
  366. input: {
  367. emailAddress: 'test1@test.com',
  368. firstName: 'New',
  369. lastName: 'Customer',
  370. },
  371. });
  372. customerErrorGuard.assertSuccess(createCustomer);
  373. expect(createCustomer.user!.verified).toBe(false);
  374. expect(sendEmailFn).toHaveBeenCalledTimes(1);
  375. expect(sendEmailFn.mock.calls[0][0] instanceof AccountRegistrationEvent).toBe(true);
  376. expect(sendEmailFn.mock.calls[0][0].user.identifier).toBe('test1@test.com');
  377. });
  378. it('creates a verified Customer', async () => {
  379. sendEmailFn = jest.fn();
  380. const { createCustomer } = await adminClient.query<
  381. CreateCustomer.Mutation,
  382. CreateCustomer.Variables
  383. >(CREATE_CUSTOMER, {
  384. input: {
  385. emailAddress: 'test2@test.com',
  386. firstName: 'New',
  387. lastName: 'Customer',
  388. },
  389. password: 'test',
  390. });
  391. customerErrorGuard.assertSuccess(createCustomer);
  392. expect(createCustomer.user!.verified).toBe(true);
  393. expect(sendEmailFn).toHaveBeenCalledTimes(0);
  394. });
  395. it('return error result when using an existing, non-deleted emailAddress', async () => {
  396. const { createCustomer } = await adminClient.query<
  397. CreateCustomer.Mutation,
  398. CreateCustomer.Variables
  399. >(CREATE_CUSTOMER, {
  400. input: {
  401. emailAddress: 'test2@test.com',
  402. firstName: 'New',
  403. lastName: 'Customer',
  404. },
  405. password: 'test',
  406. });
  407. customerErrorGuard.assertErrorResult(createCustomer);
  408. expect(createCustomer.message).toBe('The email address is not available.');
  409. expect(createCustomer.errorCode).toBe(ErrorCode.EMAIL_ADDRESS_CONFLICT_ERROR);
  410. });
  411. });
  412. describe('update', () => {
  413. it('returns error result when emailAddress not available', async () => {
  414. const { updateCustomer } = await adminClient.query<
  415. UpdateCustomer.Mutation,
  416. UpdateCustomer.Variables
  417. >(UPDATE_CUSTOMER, {
  418. input: {
  419. id: thirdCustomer.id,
  420. emailAddress: firstCustomer.emailAddress,
  421. },
  422. });
  423. customerErrorGuard.assertErrorResult(updateCustomer);
  424. expect(updateCustomer.message).toBe('The email address is not available.');
  425. expect(updateCustomer.errorCode).toBe(ErrorCode.EMAIL_ADDRESS_CONFLICT_ERROR);
  426. });
  427. it('succeeds when emailAddress is available', async () => {
  428. const { updateCustomer } = await adminClient.query<
  429. UpdateCustomer.Mutation,
  430. UpdateCustomer.Variables
  431. >(UPDATE_CUSTOMER, {
  432. input: {
  433. id: thirdCustomer.id,
  434. emailAddress: 'unique-email@test.com',
  435. },
  436. });
  437. customerErrorGuard.assertSuccess(updateCustomer);
  438. expect(updateCustomer.emailAddress).toBe('unique-email@test.com');
  439. });
  440. });
  441. describe('deletion', () => {
  442. it('deletes a customer', async () => {
  443. const result = await adminClient.query<DeleteCustomer.Mutation, DeleteCustomer.Variables>(
  444. DELETE_CUSTOMER,
  445. { id: thirdCustomer.id },
  446. );
  447. expect(result.deleteCustomer).toEqual({ result: DeletionResult.DELETED });
  448. });
  449. it('cannot get a deleted customer', async () => {
  450. const result = await adminClient.query<GetCustomer.Query, GetCustomer.Variables>(GET_CUSTOMER, {
  451. id: thirdCustomer.id,
  452. });
  453. expect(result.customer).toBe(null);
  454. });
  455. it('deleted customer omitted from list', async () => {
  456. const result = await adminClient.query<GetCustomerList.Query, GetCustomerList.Variables>(
  457. GET_CUSTOMER_LIST,
  458. );
  459. expect(result.customers.items.map(c => c.id).includes(thirdCustomer.id)).toBe(false);
  460. });
  461. it(
  462. 'updateCustomer throws for deleted customer',
  463. assertThrowsWithMessage(
  464. () =>
  465. adminClient.query<UpdateCustomer.Mutation, UpdateCustomer.Variables>(UPDATE_CUSTOMER, {
  466. input: {
  467. id: thirdCustomer.id,
  468. firstName: 'updated',
  469. },
  470. }),
  471. `No Customer with the id '3' could be found`,
  472. ),
  473. );
  474. it(
  475. 'createCustomerAddress throws for deleted customer',
  476. assertThrowsWithMessage(
  477. () =>
  478. adminClient.query<CreateAddress.Mutation, CreateAddress.Variables>(CREATE_ADDRESS, {
  479. id: thirdCustomer.id,
  480. input: {
  481. streetLine1: 'test',
  482. countryCode: 'GB',
  483. },
  484. }),
  485. `No Customer with the id '3' could be found`,
  486. ),
  487. );
  488. it('new Customer can be created with same emailAddress as a deleted Customer', async () => {
  489. const { createCustomer } = await adminClient.query<
  490. CreateCustomer.Mutation,
  491. CreateCustomer.Variables
  492. >(CREATE_CUSTOMER, {
  493. input: {
  494. emailAddress: thirdCustomer.emailAddress,
  495. firstName: 'Reusing Email',
  496. lastName: 'Customer',
  497. },
  498. });
  499. customerErrorGuard.assertSuccess(createCustomer);
  500. expect(createCustomer.emailAddress).toBe(thirdCustomer.emailAddress);
  501. expect(createCustomer.firstName).toBe('Reusing Email');
  502. expect(createCustomer.user?.identifier).toBe(thirdCustomer.emailAddress);
  503. });
  504. });
  505. describe('customer notes', () => {
  506. let noteId: string;
  507. it('addNoteToCustomer', async () => {
  508. const { addNoteToCustomer } = await adminClient.query<
  509. AddNoteToCustomer.Mutation,
  510. AddNoteToCustomer.Variables
  511. >(ADD_NOTE_TO_CUSTOMER, {
  512. input: {
  513. id: firstCustomer.id,
  514. isPublic: false,
  515. note: 'Test note',
  516. },
  517. });
  518. const { customer } = await adminClient.query<
  519. GetCustomerHistory.Query,
  520. GetCustomerHistory.Variables
  521. >(GET_CUSTOMER_HISTORY, {
  522. id: firstCustomer.id,
  523. options: {
  524. filter: {
  525. type: {
  526. eq: HistoryEntryType.CUSTOMER_NOTE,
  527. },
  528. },
  529. },
  530. });
  531. expect(customer?.history.items.map(pick(['type', 'data']))).toEqual([
  532. {
  533. type: HistoryEntryType.CUSTOMER_NOTE,
  534. data: {
  535. note: 'Test note',
  536. },
  537. },
  538. ]);
  539. noteId = customer?.history.items[0].id!;
  540. });
  541. it('update note', async () => {
  542. const { updateCustomerNote } = await adminClient.query<
  543. UpdateCustomerNote.Mutation,
  544. UpdateCustomerNote.Variables
  545. >(UPDATE_CUSTOMER_NOTE, {
  546. input: {
  547. noteId,
  548. note: 'An updated note',
  549. },
  550. });
  551. expect(updateCustomerNote.data).toEqual({
  552. note: 'An updated note',
  553. });
  554. });
  555. it('delete note', async () => {
  556. const { customer: before } = await adminClient.query<
  557. GetCustomerHistory.Query,
  558. GetCustomerHistory.Variables
  559. >(GET_CUSTOMER_HISTORY, { id: firstCustomer.id });
  560. const historyCount = before?.history.totalItems!;
  561. const { deleteCustomerNote } = await adminClient.query<
  562. DeleteCustomerNote.Mutation,
  563. DeleteCustomerNote.Variables
  564. >(DELETE_CUSTOMER_NOTE, {
  565. id: noteId,
  566. });
  567. expect(deleteCustomerNote.result).toBe(DeletionResult.DELETED);
  568. const { customer: after } = await adminClient.query<
  569. GetCustomerHistory.Query,
  570. GetCustomerHistory.Variables
  571. >(GET_CUSTOMER_HISTORY, { id: firstCustomer.id });
  572. expect(after?.history.totalItems).toBe(historyCount - 1);
  573. });
  574. });
  575. });
  576. const GET_CUSTOMER_WITH_USER = gql`
  577. query GetCustomerWithUser($id: ID!) {
  578. customer(id: $id) {
  579. id
  580. user {
  581. id
  582. identifier
  583. verified
  584. }
  585. }
  586. }
  587. `;
  588. const GET_CUSTOMER_ORDERS = gql`
  589. query GetCustomerOrders($id: ID!) {
  590. customer(id: $id) {
  591. orders {
  592. items {
  593. id
  594. }
  595. totalItems
  596. }
  597. }
  598. }
  599. `;
  600. const ADD_NOTE_TO_CUSTOMER = gql`
  601. mutation AddNoteToCustomer($input: AddNoteToCustomerInput!) {
  602. addNoteToCustomer(input: $input) {
  603. ...Customer
  604. }
  605. }
  606. ${CUSTOMER_FRAGMENT}
  607. `;