1
0

customer.e2e-spec.ts 25 KB

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