product.e2e-spec.ts 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350
  1. import { omit } from '@vendure/common/lib/omit';
  2. import { pick } from '@vendure/common/lib/pick';
  3. import { notNullOrUndefined } from '@vendure/common/lib/shared-utils';
  4. import { createErrorResultGuard, createTestEnvironment, ErrorResultGuard } from '@vendure/testing';
  5. import gql from 'graphql-tag';
  6. import path from 'path';
  7. import { initialData } from '../../../e2e-common/e2e-initial-data';
  8. import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
  9. import { PRODUCT_WITH_OPTIONS_FRAGMENT } from './graphql/fragments';
  10. import {
  11. AddOptionGroupToProduct,
  12. CreateProduct,
  13. CreateProductVariants,
  14. DeleteProduct,
  15. DeleteProductVariant,
  16. DeletionResult,
  17. ErrorCode,
  18. GetAssetList,
  19. GetOptionGroup,
  20. GetProductList,
  21. GetProductSimple,
  22. GetProductVariant,
  23. GetProductVariantList,
  24. GetProductWithVariants,
  25. LanguageCode,
  26. ProductVariantFragment,
  27. ProductWithOptionsFragment,
  28. ProductWithVariants,
  29. RemoveOptionGroupFromProduct,
  30. SortOrder,
  31. UpdateProduct,
  32. UpdateProductVariants,
  33. } from './graphql/generated-e2e-admin-types';
  34. import {
  35. ADD_OPTION_GROUP_TO_PRODUCT,
  36. CREATE_PRODUCT,
  37. CREATE_PRODUCT_VARIANTS,
  38. DELETE_PRODUCT,
  39. DELETE_PRODUCT_VARIANT,
  40. GET_ASSET_LIST,
  41. GET_PRODUCT_LIST,
  42. GET_PRODUCT_SIMPLE,
  43. GET_PRODUCT_WITH_VARIANTS,
  44. UPDATE_PRODUCT,
  45. UPDATE_PRODUCT_VARIANTS,
  46. } from './graphql/shared-definitions';
  47. import { assertThrowsWithMessage } from './utils/assert-throws-with-message';
  48. // tslint:disable:no-non-null-assertion
  49. describe('Product resolver', () => {
  50. const { server, adminClient, shopClient } = createTestEnvironment(testConfig);
  51. const removeOptionGuard: ErrorResultGuard<ProductWithOptionsFragment> = createErrorResultGuard(
  52. input => !!input.optionGroups,
  53. );
  54. beforeAll(async () => {
  55. await server.init({
  56. initialData,
  57. customerCount: 1,
  58. productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-full.csv'),
  59. });
  60. await adminClient.asSuperAdmin();
  61. }, TEST_SETUP_TIMEOUT_MS);
  62. afterAll(async () => {
  63. await server.destroy();
  64. });
  65. describe('products list query', () => {
  66. it('returns all products when no options passed', async () => {
  67. const result = await adminClient.query<GetProductList.Query, GetProductList.Variables>(
  68. GET_PRODUCT_LIST,
  69. {},
  70. );
  71. expect(result.products.items.length).toBe(20);
  72. expect(result.products.totalItems).toBe(20);
  73. });
  74. it('limits result set with skip & take', async () => {
  75. const result = await adminClient.query<GetProductList.Query, GetProductList.Variables>(
  76. GET_PRODUCT_LIST,
  77. {
  78. options: {
  79. skip: 0,
  80. take: 3,
  81. },
  82. },
  83. );
  84. expect(result.products.items.length).toBe(3);
  85. expect(result.products.totalItems).toBe(20);
  86. });
  87. it('filters by name admin', async () => {
  88. const result = await adminClient.query<GetProductList.Query, GetProductList.Variables>(
  89. GET_PRODUCT_LIST,
  90. {
  91. options: {
  92. filter: {
  93. name: {
  94. contains: 'skateboard',
  95. },
  96. },
  97. },
  98. },
  99. );
  100. expect(result.products.items.length).toBe(1);
  101. expect(result.products.items[0].name).toBe('Cruiser Skateboard');
  102. });
  103. it('filters multiple admin', async () => {
  104. const result = await adminClient.query<GetProductList.Query, GetProductList.Variables>(
  105. GET_PRODUCT_LIST,
  106. {
  107. options: {
  108. filter: {
  109. name: {
  110. contains: 'camera',
  111. },
  112. slug: {
  113. contains: 'tent',
  114. },
  115. },
  116. },
  117. },
  118. );
  119. expect(result.products.items.length).toBe(0);
  120. });
  121. it('sorts by name admin', async () => {
  122. const result = await adminClient.query<GetProductList.Query, GetProductList.Variables>(
  123. GET_PRODUCT_LIST,
  124. {
  125. options: {
  126. sort: {
  127. name: SortOrder.ASC,
  128. },
  129. },
  130. },
  131. );
  132. expect(result.products.items.map(p => p.name)).toEqual([
  133. 'Bonsai Tree',
  134. 'Boxing Gloves',
  135. 'Camera Lens',
  136. 'Clacky Keyboard',
  137. 'Cruiser Skateboard',
  138. 'Curvy Monitor',
  139. 'Football',
  140. 'Gaming PC',
  141. 'Hard Drive',
  142. 'Instant Camera',
  143. 'Laptop',
  144. 'Orchid',
  145. 'Road Bike',
  146. 'Running Shoe',
  147. 'Skipping Rope',
  148. 'Slr Camera',
  149. 'Spiky Cactus',
  150. 'Tent',
  151. 'Tripod',
  152. 'USB Cable',
  153. ]);
  154. });
  155. it('filters by name shop', async () => {
  156. const result = await shopClient.query<GetProductList.Query, GetProductList.Variables>(
  157. GET_PRODUCT_LIST,
  158. {
  159. options: {
  160. filter: {
  161. name: {
  162. contains: 'skateboard',
  163. },
  164. },
  165. },
  166. },
  167. );
  168. expect(result.products.items.length).toBe(1);
  169. expect(result.products.items[0].name).toBe('Cruiser Skateboard');
  170. });
  171. it('sorts by name shop', async () => {
  172. const result = await shopClient.query<GetProductList.Query, GetProductList.Variables>(
  173. GET_PRODUCT_LIST,
  174. {
  175. options: {
  176. sort: {
  177. name: SortOrder.ASC,
  178. },
  179. },
  180. },
  181. );
  182. expect(result.products.items.map(p => p.name)).toEqual([
  183. 'Bonsai Tree',
  184. 'Boxing Gloves',
  185. 'Camera Lens',
  186. 'Clacky Keyboard',
  187. 'Cruiser Skateboard',
  188. 'Curvy Monitor',
  189. 'Football',
  190. 'Gaming PC',
  191. 'Hard Drive',
  192. 'Instant Camera',
  193. 'Laptop',
  194. 'Orchid',
  195. 'Road Bike',
  196. 'Running Shoe',
  197. 'Skipping Rope',
  198. 'Slr Camera',
  199. 'Spiky Cactus',
  200. 'Tent',
  201. 'Tripod',
  202. 'USB Cable',
  203. ]);
  204. });
  205. });
  206. describe('product query', () => {
  207. it('by id', async () => {
  208. const { product } = await adminClient.query<GetProductSimple.Query, GetProductSimple.Variables>(
  209. GET_PRODUCT_SIMPLE,
  210. { id: 'T_2' },
  211. );
  212. if (!product) {
  213. fail('Product not found');
  214. return;
  215. }
  216. expect(product.id).toBe('T_2');
  217. });
  218. it('by slug', async () => {
  219. const { product } = await adminClient.query<GetProductSimple.Query, GetProductSimple.Variables>(
  220. GET_PRODUCT_SIMPLE,
  221. { slug: 'curvy-monitor' },
  222. );
  223. if (!product) {
  224. fail('Product not found');
  225. return;
  226. }
  227. expect(product.slug).toBe('curvy-monitor');
  228. });
  229. // https://github.com/vendure-ecommerce/vendure/issues/538
  230. it('falls back to default language slug', async () => {
  231. const { product } = await adminClient.query<GetProductSimple.Query, GetProductSimple.Variables>(
  232. GET_PRODUCT_SIMPLE,
  233. { slug: 'curvy-monitor' },
  234. { languageCode: LanguageCode.de },
  235. );
  236. if (!product) {
  237. fail('Product not found');
  238. return;
  239. }
  240. expect(product.slug).toBe('curvy-monitor');
  241. });
  242. it(
  243. 'throws if neither id nor slug provided',
  244. assertThrowsWithMessage(async () => {
  245. await adminClient.query<GetProductSimple.Query, GetProductSimple.Variables>(
  246. GET_PRODUCT_SIMPLE,
  247. {},
  248. );
  249. }, 'Either the Product id or slug must be provided'),
  250. );
  251. it(
  252. 'throws if id and slug do not refer to the same Product',
  253. assertThrowsWithMessage(async () => {
  254. await adminClient.query<GetProductSimple.Query, GetProductSimple.Variables>(
  255. GET_PRODUCT_SIMPLE,
  256. {
  257. id: 'T_2',
  258. slug: 'laptop',
  259. },
  260. );
  261. }, 'The provided id and slug refer to different Products'),
  262. );
  263. it('returns expected properties', async () => {
  264. const { product } = await adminClient.query<
  265. GetProductWithVariants.Query,
  266. GetProductWithVariants.Variables
  267. >(GET_PRODUCT_WITH_VARIANTS, {
  268. id: 'T_2',
  269. });
  270. if (!product) {
  271. fail('Product not found');
  272. return;
  273. }
  274. expect(omit(product, ['variants'])).toMatchSnapshot();
  275. expect(product.variants.length).toBe(2);
  276. });
  277. it('ProductVariant price properties are correct', async () => {
  278. const result = await adminClient.query<
  279. GetProductWithVariants.Query,
  280. GetProductWithVariants.Variables
  281. >(GET_PRODUCT_WITH_VARIANTS, {
  282. id: 'T_2',
  283. });
  284. if (!result.product) {
  285. fail('Product not found');
  286. return;
  287. }
  288. expect(result.product.variants[0].price).toBe(14374);
  289. expect(result.product.variants[0].taxCategory).toEqual({
  290. id: 'T_1',
  291. name: 'Standard Tax',
  292. });
  293. });
  294. it('returns null when id not found', async () => {
  295. const result = await adminClient.query<
  296. GetProductWithVariants.Query,
  297. GetProductWithVariants.Variables
  298. >(GET_PRODUCT_WITH_VARIANTS, {
  299. id: 'bad_id',
  300. });
  301. expect(result.product).toBeNull();
  302. });
  303. });
  304. describe('productVariants list query', () => {
  305. it('returns list', async () => {
  306. const { productVariants } = await adminClient.query<
  307. GetProductVariantList.Query,
  308. GetProductVariantList.Variables
  309. >(GET_PRODUCT_VARIANT_LIST, {
  310. options: {
  311. take: 3,
  312. sort: {
  313. name: SortOrder.ASC,
  314. },
  315. },
  316. });
  317. expect(productVariants.items).toEqual([
  318. {
  319. id: 'T_34',
  320. name: 'Bonsai Tree',
  321. price: 1999,
  322. sku: 'B01MXFLUSV',
  323. },
  324. {
  325. id: 'T_24',
  326. name: 'Boxing Gloves',
  327. price: 3304,
  328. sku: 'B000ZYLPPU',
  329. },
  330. {
  331. id: 'T_19',
  332. name: 'Camera Lens',
  333. price: 10400,
  334. sku: 'B0012UUP02',
  335. },
  336. ]);
  337. });
  338. it('sort by price', async () => {
  339. const { productVariants } = await adminClient.query<
  340. GetProductVariantList.Query,
  341. GetProductVariantList.Variables
  342. >(GET_PRODUCT_VARIANT_LIST, {
  343. options: {
  344. take: 3,
  345. sort: {
  346. price: SortOrder.ASC,
  347. },
  348. },
  349. });
  350. expect(productVariants.items).toEqual([
  351. {
  352. id: 'T_23',
  353. name: 'Skipping Rope',
  354. price: 799,
  355. sku: 'B07CNGXVXT',
  356. },
  357. {
  358. id: 'T_20',
  359. name: 'Tripod',
  360. price: 1498,
  361. sku: 'B00XI87KV8',
  362. },
  363. {
  364. id: 'T_32',
  365. name: 'Spiky Cactus',
  366. price: 1550,
  367. sku: 'SC011001',
  368. },
  369. ]);
  370. });
  371. });
  372. describe('productVariant query', () => {
  373. it('by id', async () => {
  374. const { productVariant } = await adminClient.query<
  375. GetProductVariant.Query,
  376. GetProductVariant.Variables
  377. >(GET_PRODUCT_VARIANT, {
  378. id: 'T_1',
  379. });
  380. expect(productVariant?.id).toBe('T_1');
  381. expect(productVariant?.name).toBe('Laptop 13 inch 8GB');
  382. });
  383. it('returns null when id not found', async () => {
  384. const { productVariant } = await adminClient.query<
  385. GetProductVariant.Query,
  386. GetProductVariant.Variables
  387. >(GET_PRODUCT_VARIANT, {
  388. id: 'T_999',
  389. });
  390. expect(productVariant).toBeNull();
  391. });
  392. });
  393. describe('product mutation', () => {
  394. let newProduct: ProductWithVariants.Fragment;
  395. let newProductWithAssets: ProductWithVariants.Fragment;
  396. it('createProduct creates a new Product', async () => {
  397. const result = await adminClient.query<CreateProduct.Mutation, CreateProduct.Variables>(
  398. CREATE_PRODUCT,
  399. {
  400. input: {
  401. translations: [
  402. {
  403. languageCode: LanguageCode.en,
  404. name: 'en Baked Potato',
  405. slug: 'en Baked Potato',
  406. description: 'A baked potato',
  407. },
  408. {
  409. languageCode: LanguageCode.de,
  410. name: 'de Baked Potato',
  411. slug: 'de-baked-potato',
  412. description: 'Eine baked Erdapfel',
  413. },
  414. ],
  415. },
  416. },
  417. );
  418. expect(omit(result.createProduct, ['translations'])).toMatchSnapshot();
  419. expect(result.createProduct.translations.map(t => t.description).sort()).toEqual([
  420. 'A baked potato',
  421. 'Eine baked Erdapfel',
  422. ]);
  423. newProduct = result.createProduct;
  424. });
  425. it('createProduct creates a new Product with assets', async () => {
  426. const assetsResult = await adminClient.query<GetAssetList.Query, GetAssetList.Variables>(
  427. GET_ASSET_LIST,
  428. );
  429. const assetIds = assetsResult.assets.items.slice(0, 2).map(a => a.id);
  430. const featuredAssetId = assetsResult.assets.items[0].id;
  431. const result = await adminClient.query<CreateProduct.Mutation, CreateProduct.Variables>(
  432. CREATE_PRODUCT,
  433. {
  434. input: {
  435. assetIds,
  436. featuredAssetId,
  437. translations: [
  438. {
  439. languageCode: LanguageCode.en,
  440. name: 'en Has Assets',
  441. slug: 'en-has-assets',
  442. description: 'A product with assets',
  443. },
  444. ],
  445. },
  446. },
  447. );
  448. expect(result.createProduct.assets.map(a => a.id)).toEqual(assetIds);
  449. expect(result.createProduct.featuredAsset!.id).toBe(featuredAssetId);
  450. newProductWithAssets = result.createProduct;
  451. });
  452. it('createProduct creates a disabled Product', async () => {
  453. const result = await adminClient.query<CreateProduct.Mutation, CreateProduct.Variables>(
  454. CREATE_PRODUCT,
  455. {
  456. input: {
  457. enabled: false,
  458. translations: [
  459. {
  460. languageCode: LanguageCode.en,
  461. name: 'en Small apple',
  462. slug: 'en-small-apple',
  463. description: 'A small apple',
  464. },
  465. ],
  466. },
  467. },
  468. );
  469. expect(result.createProduct.enabled).toBe(false);
  470. newProduct = result.createProduct;
  471. });
  472. it('updateProduct updates a Product', async () => {
  473. const result = await adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(
  474. UPDATE_PRODUCT,
  475. {
  476. input: {
  477. id: newProduct.id,
  478. translations: [
  479. {
  480. languageCode: LanguageCode.en,
  481. name: 'en Mashed Potato',
  482. slug: 'en-mashed-potato',
  483. description: 'A blob of mashed potato',
  484. },
  485. {
  486. languageCode: LanguageCode.de,
  487. name: 'de Mashed Potato',
  488. slug: 'de-mashed-potato',
  489. description: 'Eine blob von gemashed Erdapfel',
  490. },
  491. ],
  492. },
  493. },
  494. );
  495. expect(result.updateProduct.translations.map(t => t.description).sort()).toEqual([
  496. 'A blob of mashed potato',
  497. 'Eine blob von gemashed Erdapfel',
  498. ]);
  499. });
  500. it('slug is normalized to be url-safe', async () => {
  501. const result = await adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(
  502. UPDATE_PRODUCT,
  503. {
  504. input: {
  505. id: newProduct.id,
  506. translations: [
  507. {
  508. languageCode: LanguageCode.en,
  509. name: 'en Mashed Potato',
  510. slug: 'A (very) nice potato!!',
  511. description: 'A blob of mashed potato',
  512. },
  513. ],
  514. },
  515. },
  516. );
  517. expect(result.updateProduct.slug).toBe('a-very-nice-potato');
  518. });
  519. it('create with duplicate slug is renamed to be unique', async () => {
  520. const result = await adminClient.query<CreateProduct.Mutation, CreateProduct.Variables>(
  521. CREATE_PRODUCT,
  522. {
  523. input: {
  524. translations: [
  525. {
  526. languageCode: LanguageCode.en,
  527. name: 'Another baked potato',
  528. slug: 'a-very-nice-potato',
  529. description: 'Another baked potato but a bit different',
  530. },
  531. ],
  532. },
  533. },
  534. );
  535. expect(result.createProduct.slug).toBe('a-very-nice-potato-2');
  536. });
  537. it('update with duplicate slug is renamed to be unique', async () => {
  538. const result = await adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(
  539. UPDATE_PRODUCT,
  540. {
  541. input: {
  542. id: newProduct.id,
  543. translations: [
  544. {
  545. languageCode: LanguageCode.en,
  546. name: 'Yet another baked potato',
  547. slug: 'a-very-nice-potato-2',
  548. description: 'Possibly the final baked potato',
  549. },
  550. ],
  551. },
  552. },
  553. );
  554. expect(result.updateProduct.slug).toBe('a-very-nice-potato-3');
  555. });
  556. it('slug duplicate check does not include self', async () => {
  557. const result = await adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(
  558. UPDATE_PRODUCT,
  559. {
  560. input: {
  561. id: newProduct.id,
  562. translations: [
  563. {
  564. languageCode: LanguageCode.en,
  565. slug: 'a-very-nice-potato-3',
  566. },
  567. ],
  568. },
  569. },
  570. );
  571. expect(result.updateProduct.slug).toBe('a-very-nice-potato-3');
  572. });
  573. it('updateProduct accepts partial input', async () => {
  574. const result = await adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(
  575. UPDATE_PRODUCT,
  576. {
  577. input: {
  578. id: newProduct.id,
  579. translations: [
  580. {
  581. languageCode: LanguageCode.en,
  582. name: 'en Very Mashed Potato',
  583. },
  584. ],
  585. },
  586. },
  587. );
  588. expect(result.updateProduct.translations.length).toBe(2);
  589. expect(
  590. result.updateProduct.translations.find(t => t.languageCode === LanguageCode.de)!.name,
  591. ).toBe('de Mashed Potato');
  592. expect(
  593. result.updateProduct.translations.find(t => t.languageCode === LanguageCode.en)!.name,
  594. ).toBe('en Very Mashed Potato');
  595. expect(
  596. result.updateProduct.translations.find(t => t.languageCode === LanguageCode.en)!.description,
  597. ).toBe('Possibly the final baked potato');
  598. });
  599. it('updateProduct adds Assets to a product and sets featured asset', async () => {
  600. const assetsResult = await adminClient.query<GetAssetList.Query, GetAssetList.Variables>(
  601. GET_ASSET_LIST,
  602. );
  603. const assetIds = assetsResult.assets.items.map(a => a.id);
  604. const featuredAssetId = assetsResult.assets.items[2].id;
  605. const result = await adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(
  606. UPDATE_PRODUCT,
  607. {
  608. input: {
  609. id: newProduct.id,
  610. assetIds,
  611. featuredAssetId,
  612. },
  613. },
  614. );
  615. expect(result.updateProduct.assets.map(a => a.id)).toEqual(assetIds);
  616. expect(result.updateProduct.featuredAsset!.id).toBe(featuredAssetId);
  617. });
  618. it('updateProduct sets a featured asset', async () => {
  619. const productResult = await adminClient.query<
  620. GetProductWithVariants.Query,
  621. GetProductWithVariants.Variables
  622. >(GET_PRODUCT_WITH_VARIANTS, {
  623. id: newProduct.id,
  624. });
  625. const assets = productResult.product!.assets;
  626. const result = await adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(
  627. UPDATE_PRODUCT,
  628. {
  629. input: {
  630. id: newProduct.id,
  631. featuredAssetId: assets[0].id,
  632. },
  633. },
  634. );
  635. expect(result.updateProduct.featuredAsset!.id).toBe(assets[0].id);
  636. });
  637. it('updateProduct updates assets', async () => {
  638. const result = await adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(
  639. UPDATE_PRODUCT,
  640. {
  641. input: {
  642. id: newProduct.id,
  643. featuredAssetId: 'T_1',
  644. assetIds: ['T_1', 'T_2'],
  645. },
  646. },
  647. );
  648. expect(result.updateProduct.assets.map(a => a.id)).toEqual(['T_1', 'T_2']);
  649. });
  650. it('updateProduct updates FacetValues', async () => {
  651. const result = await adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(
  652. UPDATE_PRODUCT,
  653. {
  654. input: {
  655. id: newProduct.id,
  656. facetValueIds: ['T_1'],
  657. },
  658. },
  659. );
  660. expect(result.updateProduct.facetValues.length).toEqual(1);
  661. });
  662. it(
  663. 'updateProduct errors with an invalid productId',
  664. assertThrowsWithMessage(
  665. () =>
  666. adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(UPDATE_PRODUCT, {
  667. input: {
  668. id: '999',
  669. translations: [
  670. {
  671. languageCode: LanguageCode.en,
  672. name: 'en Mashed Potato',
  673. slug: 'en-mashed-potato',
  674. description: 'A blob of mashed potato',
  675. },
  676. {
  677. languageCode: LanguageCode.de,
  678. name: 'de Mashed Potato',
  679. slug: 'de-mashed-potato',
  680. description: 'Eine blob von gemashed Erdapfel',
  681. },
  682. ],
  683. },
  684. }),
  685. `No Product with the id '999' could be found`,
  686. ),
  687. );
  688. it('addOptionGroupToProduct adds an option group', async () => {
  689. const result = await adminClient.query<
  690. AddOptionGroupToProduct.Mutation,
  691. AddOptionGroupToProduct.Variables
  692. >(ADD_OPTION_GROUP_TO_PRODUCT, {
  693. optionGroupId: 'T_2',
  694. productId: newProduct.id,
  695. });
  696. expect(result.addOptionGroupToProduct.optionGroups.length).toBe(1);
  697. expect(result.addOptionGroupToProduct.optionGroups[0].id).toBe('T_2');
  698. });
  699. it(
  700. 'addOptionGroupToProduct errors with an invalid productId',
  701. assertThrowsWithMessage(
  702. () =>
  703. adminClient.query<AddOptionGroupToProduct.Mutation, AddOptionGroupToProduct.Variables>(
  704. ADD_OPTION_GROUP_TO_PRODUCT,
  705. {
  706. optionGroupId: 'T_1',
  707. productId: '999',
  708. },
  709. ),
  710. `No Product with the id '999' could be found`,
  711. ),
  712. );
  713. it(
  714. 'addOptionGroupToProduct errors with an invalid optionGroupId',
  715. assertThrowsWithMessage(
  716. () =>
  717. adminClient.query<AddOptionGroupToProduct.Mutation, AddOptionGroupToProduct.Variables>(
  718. ADD_OPTION_GROUP_TO_PRODUCT,
  719. {
  720. optionGroupId: '999',
  721. productId: newProduct.id,
  722. },
  723. ),
  724. `No ProductOptionGroup with the id '999' could be found`,
  725. ),
  726. );
  727. it('removeOptionGroupFromProduct removes an option group', async () => {
  728. const { addOptionGroupToProduct } = await adminClient.query<
  729. AddOptionGroupToProduct.Mutation,
  730. AddOptionGroupToProduct.Variables
  731. >(ADD_OPTION_GROUP_TO_PRODUCT, {
  732. optionGroupId: 'T_1',
  733. productId: newProductWithAssets.id,
  734. });
  735. expect(addOptionGroupToProduct.optionGroups.length).toBe(1);
  736. const { removeOptionGroupFromProduct } = await adminClient.query<
  737. RemoveOptionGroupFromProduct.Mutation,
  738. RemoveOptionGroupFromProduct.Variables
  739. >(REMOVE_OPTION_GROUP_FROM_PRODUCT, {
  740. optionGroupId: 'T_1',
  741. productId: newProductWithAssets.id,
  742. });
  743. removeOptionGuard.assertSuccess(removeOptionGroupFromProduct);
  744. expect(removeOptionGroupFromProduct.id).toBe(newProductWithAssets.id);
  745. expect(removeOptionGroupFromProduct.optionGroups.length).toBe(0);
  746. });
  747. it('removeOptionGroupFromProduct return error result if the optionGroup is being used by variants', async () => {
  748. const { removeOptionGroupFromProduct } = await adminClient.query<
  749. RemoveOptionGroupFromProduct.Mutation,
  750. RemoveOptionGroupFromProduct.Variables
  751. >(REMOVE_OPTION_GROUP_FROM_PRODUCT, {
  752. optionGroupId: 'T_3',
  753. productId: 'T_2',
  754. });
  755. removeOptionGuard.assertErrorResult(removeOptionGroupFromProduct);
  756. expect(removeOptionGroupFromProduct.message).toBe(
  757. `Cannot remove ProductOptionGroup "curvy-monitor-monitor-size" as it is used by 2 ProductVariants`,
  758. );
  759. expect(removeOptionGroupFromProduct.errorCode).toBe(ErrorCode.PRODUCT_OPTION_IN_USE_ERROR);
  760. expect(removeOptionGroupFromProduct.optionGroupCode).toBe('curvy-monitor-monitor-size');
  761. expect(removeOptionGroupFromProduct.productVariantCount).toBe(2);
  762. });
  763. it(
  764. 'removeOptionGroupFromProduct errors with an invalid productId',
  765. assertThrowsWithMessage(
  766. () =>
  767. adminClient.query<
  768. RemoveOptionGroupFromProduct.Mutation,
  769. RemoveOptionGroupFromProduct.Variables
  770. >(REMOVE_OPTION_GROUP_FROM_PRODUCT, {
  771. optionGroupId: '1',
  772. productId: '999',
  773. }),
  774. `No Product with the id '999' could be found`,
  775. ),
  776. );
  777. it(
  778. 'removeOptionGroupFromProduct errors with an invalid optionGroupId',
  779. assertThrowsWithMessage(
  780. () =>
  781. adminClient.query<
  782. RemoveOptionGroupFromProduct.Mutation,
  783. RemoveOptionGroupFromProduct.Variables
  784. >(REMOVE_OPTION_GROUP_FROM_PRODUCT, {
  785. optionGroupId: '999',
  786. productId: newProduct.id,
  787. }),
  788. `No ProductOptionGroup with the id '999' could be found`,
  789. ),
  790. );
  791. describe('variants', () => {
  792. let variants: CreateProductVariants.CreateProductVariants[];
  793. let optionGroup2: GetOptionGroup.ProductOptionGroup;
  794. let optionGroup3: GetOptionGroup.ProductOptionGroup;
  795. beforeAll(async () => {
  796. await adminClient.query<AddOptionGroupToProduct.Mutation, AddOptionGroupToProduct.Variables>(
  797. ADD_OPTION_GROUP_TO_PRODUCT,
  798. {
  799. optionGroupId: 'T_3',
  800. productId: newProduct.id,
  801. },
  802. );
  803. const result1 = await adminClient.query<GetOptionGroup.Query, GetOptionGroup.Variables>(
  804. GET_OPTION_GROUP,
  805. { id: 'T_2' },
  806. );
  807. const result2 = await adminClient.query<GetOptionGroup.Query, GetOptionGroup.Variables>(
  808. GET_OPTION_GROUP,
  809. { id: 'T_3' },
  810. );
  811. optionGroup2 = result1.productOptionGroup!;
  812. optionGroup3 = result2.productOptionGroup!;
  813. });
  814. it(
  815. 'createProductVariants throws if optionIds not compatible with product',
  816. assertThrowsWithMessage(async () => {
  817. await adminClient.query<CreateProductVariants.Mutation, CreateProductVariants.Variables>(
  818. CREATE_PRODUCT_VARIANTS,
  819. {
  820. input: [
  821. {
  822. productId: newProduct.id,
  823. sku: 'PV1',
  824. optionIds: [],
  825. translations: [{ languageCode: LanguageCode.en, name: 'Variant 1' }],
  826. },
  827. ],
  828. },
  829. );
  830. }, 'ProductVariant optionIds must include one optionId from each of the groups: curvy-monitor-monitor-size, laptop-ram'),
  831. );
  832. it(
  833. 'createProductVariants throws if optionIds are duplicated',
  834. assertThrowsWithMessage(async () => {
  835. await adminClient.query<CreateProductVariants.Mutation, CreateProductVariants.Variables>(
  836. CREATE_PRODUCT_VARIANTS,
  837. {
  838. input: [
  839. {
  840. productId: newProduct.id,
  841. sku: 'PV1',
  842. optionIds: [optionGroup2.options[0].id, optionGroup2.options[1].id],
  843. translations: [{ languageCode: LanguageCode.en, name: 'Variant 1' }],
  844. },
  845. ],
  846. },
  847. );
  848. }, 'ProductVariant optionIds must include one optionId from each of the groups: curvy-monitor-monitor-size, laptop-ram'),
  849. );
  850. it('createProductVariants works', async () => {
  851. const { createProductVariants } = await adminClient.query<
  852. CreateProductVariants.Mutation,
  853. CreateProductVariants.Variables
  854. >(CREATE_PRODUCT_VARIANTS, {
  855. input: [
  856. {
  857. productId: newProduct.id,
  858. sku: 'PV1',
  859. optionIds: [optionGroup2.options[0].id, optionGroup3.options[0].id],
  860. translations: [{ languageCode: LanguageCode.en, name: 'Variant 1' }],
  861. },
  862. ],
  863. });
  864. expect(createProductVariants[0]!.name).toBe('Variant 1');
  865. expect(createProductVariants[0]!.options.map(pick(['id']))).toContainEqual({
  866. id: optionGroup2.options[0].id,
  867. });
  868. expect(createProductVariants[0]!.options.map(pick(['id']))).toContainEqual({
  869. id: optionGroup3.options[0].id,
  870. });
  871. });
  872. it('createProductVariants adds multiple variants at once', async () => {
  873. const { createProductVariants } = await adminClient.query<
  874. CreateProductVariants.Mutation,
  875. CreateProductVariants.Variables
  876. >(CREATE_PRODUCT_VARIANTS, {
  877. input: [
  878. {
  879. productId: newProduct.id,
  880. sku: 'PV2',
  881. optionIds: [optionGroup2.options[1].id, optionGroup3.options[0].id],
  882. translations: [{ languageCode: LanguageCode.en, name: 'Variant 2' }],
  883. },
  884. {
  885. productId: newProduct.id,
  886. sku: 'PV3',
  887. optionIds: [optionGroup2.options[1].id, optionGroup3.options[1].id],
  888. translations: [{ languageCode: LanguageCode.en, name: 'Variant 3' }],
  889. },
  890. ],
  891. });
  892. const variant2 = createProductVariants.find(v => v!.name === 'Variant 2')!;
  893. const variant3 = createProductVariants.find(v => v!.name === 'Variant 3')!;
  894. expect(variant2.options.map(pick(['id']))).toContainEqual({ id: optionGroup2.options[1].id });
  895. expect(variant2.options.map(pick(['id']))).toContainEqual({ id: optionGroup3.options[0].id });
  896. expect(variant3.options.map(pick(['id']))).toContainEqual({ id: optionGroup2.options[1].id });
  897. expect(variant3.options.map(pick(['id']))).toContainEqual({ id: optionGroup3.options[1].id });
  898. variants = createProductVariants.filter(notNullOrUndefined);
  899. });
  900. it(
  901. 'createProductVariants throws if options combination already exists',
  902. assertThrowsWithMessage(async () => {
  903. await adminClient.query<CreateProductVariants.Mutation, CreateProductVariants.Variables>(
  904. CREATE_PRODUCT_VARIANTS,
  905. {
  906. input: [
  907. {
  908. productId: newProduct.id,
  909. sku: 'PV2',
  910. optionIds: [optionGroup2.options[0].id, optionGroup3.options[0].id],
  911. translations: [{ languageCode: LanguageCode.en, name: 'Variant 2' }],
  912. },
  913. ],
  914. },
  915. );
  916. }, 'A ProductVariant already exists with the options:'),
  917. );
  918. it('updateProductVariants updates variants', async () => {
  919. const firstVariant = variants[0];
  920. const { updateProductVariants } = await adminClient.query<
  921. UpdateProductVariants.Mutation,
  922. UpdateProductVariants.Variables
  923. >(UPDATE_PRODUCT_VARIANTS, {
  924. input: [
  925. {
  926. id: firstVariant.id,
  927. translations: firstVariant.translations,
  928. sku: 'ABC',
  929. price: 432,
  930. },
  931. ],
  932. });
  933. const updatedVariant = updateProductVariants[0];
  934. if (!updatedVariant) {
  935. fail('no updated variant returned.');
  936. return;
  937. }
  938. expect(updatedVariant.sku).toBe('ABC');
  939. expect(updatedVariant.price).toBe(432);
  940. });
  941. it('updateProductVariants updates assets', async () => {
  942. const firstVariant = variants[0];
  943. const result = await adminClient.query<
  944. UpdateProductVariants.Mutation,
  945. UpdateProductVariants.Variables
  946. >(UPDATE_PRODUCT_VARIANTS, {
  947. input: [
  948. {
  949. id: firstVariant.id,
  950. assetIds: ['T_1', 'T_2'],
  951. featuredAssetId: 'T_2',
  952. },
  953. ],
  954. });
  955. const updatedVariant = result.updateProductVariants[0];
  956. if (!updatedVariant) {
  957. fail('no updated variant returned.');
  958. return;
  959. }
  960. expect(updatedVariant.assets.map(a => a.id)).toEqual(['T_1', 'T_2']);
  961. expect(updatedVariant.featuredAsset!.id).toBe('T_2');
  962. });
  963. it('updateProductVariants updates assets again', async () => {
  964. const firstVariant = variants[0];
  965. const result = await adminClient.query<
  966. UpdateProductVariants.Mutation,
  967. UpdateProductVariants.Variables
  968. >(UPDATE_PRODUCT_VARIANTS, {
  969. input: [
  970. {
  971. id: firstVariant.id,
  972. assetIds: ['T_4', 'T_3'],
  973. featuredAssetId: 'T_4',
  974. },
  975. ],
  976. });
  977. const updatedVariant = result.updateProductVariants[0];
  978. if (!updatedVariant) {
  979. fail('no updated variant returned.');
  980. return;
  981. }
  982. expect(updatedVariant.assets.map(a => a.id)).toEqual(['T_4', 'T_3']);
  983. expect(updatedVariant.featuredAsset!.id).toBe('T_4');
  984. });
  985. it('updateProductVariants updates taxCategory and price', async () => {
  986. const firstVariant = variants[0];
  987. const result = await adminClient.query<
  988. UpdateProductVariants.Mutation,
  989. UpdateProductVariants.Variables
  990. >(UPDATE_PRODUCT_VARIANTS, {
  991. input: [
  992. {
  993. id: firstVariant.id,
  994. price: 105,
  995. taxCategoryId: 'T_2',
  996. },
  997. ],
  998. });
  999. const updatedVariant = result.updateProductVariants[0];
  1000. if (!updatedVariant) {
  1001. fail('no updated variant returned.');
  1002. return;
  1003. }
  1004. expect(updatedVariant.price).toBe(105);
  1005. expect(updatedVariant.taxCategory.id).toBe('T_2');
  1006. });
  1007. it('updateProductVariants updates facetValues', async () => {
  1008. const firstVariant = variants[0];
  1009. const result = await adminClient.query<
  1010. UpdateProductVariants.Mutation,
  1011. UpdateProductVariants.Variables
  1012. >(UPDATE_PRODUCT_VARIANTS, {
  1013. input: [
  1014. {
  1015. id: firstVariant.id,
  1016. facetValueIds: ['T_1'],
  1017. },
  1018. ],
  1019. });
  1020. const updatedVariant = result.updateProductVariants[0];
  1021. if (!updatedVariant) {
  1022. fail('no updated variant returned.');
  1023. return;
  1024. }
  1025. expect(updatedVariant.facetValues.length).toBe(1);
  1026. expect(updatedVariant.facetValues[0].id).toBe('T_1');
  1027. });
  1028. it(
  1029. 'updateProductVariants throws with an invalid variant id',
  1030. assertThrowsWithMessage(
  1031. () =>
  1032. adminClient.query<UpdateProductVariants.Mutation, UpdateProductVariants.Variables>(
  1033. UPDATE_PRODUCT_VARIANTS,
  1034. {
  1035. input: [
  1036. {
  1037. id: 'T_999',
  1038. translations: variants[0].translations,
  1039. sku: 'ABC',
  1040. price: 432,
  1041. },
  1042. ],
  1043. },
  1044. ),
  1045. `No ProductVariant with the id '999' could be found`,
  1046. ),
  1047. );
  1048. let deletedVariant: ProductVariantFragment;
  1049. it('deleteProductVariant', async () => {
  1050. const result1 = await adminClient.query<
  1051. GetProductWithVariants.Query,
  1052. GetProductWithVariants.Variables
  1053. >(GET_PRODUCT_WITH_VARIANTS, {
  1054. id: newProduct.id,
  1055. });
  1056. const sortedVariantIds = result1.product!.variants.map(v => v.id).sort();
  1057. expect(sortedVariantIds).toEqual(['T_35', 'T_36', 'T_37']);
  1058. const { deleteProductVariant } = await adminClient.query<
  1059. DeleteProductVariant.Mutation,
  1060. DeleteProductVariant.Variables
  1061. >(DELETE_PRODUCT_VARIANT, {
  1062. id: sortedVariantIds[0],
  1063. });
  1064. expect(deleteProductVariant.result).toBe(DeletionResult.DELETED);
  1065. const result2 = await adminClient.query<
  1066. GetProductWithVariants.Query,
  1067. GetProductWithVariants.Variables
  1068. >(GET_PRODUCT_WITH_VARIANTS, {
  1069. id: newProduct.id,
  1070. });
  1071. expect(result2.product!.variants.map(v => v.id).sort()).toEqual(['T_36', 'T_37']);
  1072. deletedVariant = result1.product?.variants.find(v => v.id === 'T_35')!;
  1073. });
  1074. /** Testing https://github.com/vendure-ecommerce/vendure/issues/412 **/
  1075. it('createProductVariants ignores deleted variants when checking for existing combinations', async () => {
  1076. const { createProductVariants } = await adminClient.query<
  1077. CreateProductVariants.Mutation,
  1078. CreateProductVariants.Variables
  1079. >(CREATE_PRODUCT_VARIANTS, {
  1080. input: [
  1081. {
  1082. productId: newProduct.id,
  1083. sku: 'RE1',
  1084. optionIds: [deletedVariant.options[0].id, deletedVariant.options[1].id],
  1085. translations: [{ languageCode: LanguageCode.en, name: 'Re-created Variant' }],
  1086. },
  1087. ],
  1088. });
  1089. expect(createProductVariants.length).toBe(1);
  1090. expect(createProductVariants[0]!.options.map(o => o.code).sort()).toEqual(
  1091. deletedVariant.options.map(o => o.code).sort(),
  1092. );
  1093. });
  1094. });
  1095. });
  1096. describe('deletion', () => {
  1097. let allProducts: GetProductList.Items[];
  1098. let productToDelete: GetProductList.Items;
  1099. beforeAll(async () => {
  1100. const result = await adminClient.query<GetProductList.Query, GetProductList.Variables>(
  1101. GET_PRODUCT_LIST,
  1102. {
  1103. options: {
  1104. sort: {
  1105. id: SortOrder.ASC,
  1106. },
  1107. },
  1108. },
  1109. );
  1110. allProducts = result.products.items;
  1111. });
  1112. it('deletes a product', async () => {
  1113. productToDelete = allProducts[0];
  1114. const result = await adminClient.query<DeleteProduct.Mutation, DeleteProduct.Variables>(
  1115. DELETE_PRODUCT,
  1116. { id: productToDelete.id },
  1117. );
  1118. expect(result.deleteProduct).toEqual({ result: DeletionResult.DELETED });
  1119. });
  1120. it('cannot get a deleted product', async () => {
  1121. const result = await adminClient.query<
  1122. GetProductWithVariants.Query,
  1123. GetProductWithVariants.Variables
  1124. >(GET_PRODUCT_WITH_VARIANTS, {
  1125. id: productToDelete.id,
  1126. });
  1127. expect(result.product).toBe(null);
  1128. });
  1129. it('deleted product omitted from list', async () => {
  1130. const result = await adminClient.query<GetProductList.Query>(GET_PRODUCT_LIST);
  1131. expect(result.products.items.length).toBe(allProducts.length - 1);
  1132. expect(result.products.items.map(c => c.id).includes(productToDelete.id)).toBe(false);
  1133. });
  1134. it(
  1135. 'updateProduct throws for deleted product',
  1136. assertThrowsWithMessage(
  1137. () =>
  1138. adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(UPDATE_PRODUCT, {
  1139. input: {
  1140. id: productToDelete.id,
  1141. facetValueIds: ['T_1'],
  1142. },
  1143. }),
  1144. `No Product with the id '1' could be found`,
  1145. ),
  1146. );
  1147. it(
  1148. 'addOptionGroupToProduct throws for deleted product',
  1149. assertThrowsWithMessage(
  1150. () =>
  1151. adminClient.query<AddOptionGroupToProduct.Mutation, AddOptionGroupToProduct.Variables>(
  1152. ADD_OPTION_GROUP_TO_PRODUCT,
  1153. {
  1154. optionGroupId: 'T_1',
  1155. productId: productToDelete.id,
  1156. },
  1157. ),
  1158. `No Product with the id '1' could be found`,
  1159. ),
  1160. );
  1161. it(
  1162. 'removeOptionGroupToProduct throws for deleted product',
  1163. assertThrowsWithMessage(
  1164. () =>
  1165. adminClient.query<
  1166. RemoveOptionGroupFromProduct.Mutation,
  1167. RemoveOptionGroupFromProduct.Variables
  1168. >(REMOVE_OPTION_GROUP_FROM_PRODUCT, {
  1169. optionGroupId: 'T_1',
  1170. productId: productToDelete.id,
  1171. }),
  1172. `No Product with the id '1' could be found`,
  1173. ),
  1174. );
  1175. // https://github.com/vendure-ecommerce/vendure/issues/558
  1176. it('slug of a deleted product can be re-used', async () => {
  1177. const result = await adminClient.query<CreateProduct.Mutation, CreateProduct.Variables>(
  1178. CREATE_PRODUCT,
  1179. {
  1180. input: {
  1181. translations: [
  1182. {
  1183. languageCode: LanguageCode.en,
  1184. name: 'Product reusing deleted slug',
  1185. slug: productToDelete.slug,
  1186. description: 'stuff',
  1187. },
  1188. ],
  1189. },
  1190. },
  1191. );
  1192. expect(result.createProduct.slug).toBe(productToDelete.slug);
  1193. });
  1194. });
  1195. });
  1196. export const REMOVE_OPTION_GROUP_FROM_PRODUCT = gql`
  1197. mutation RemoveOptionGroupFromProduct($productId: ID!, $optionGroupId: ID!) {
  1198. removeOptionGroupFromProduct(productId: $productId, optionGroupId: $optionGroupId) {
  1199. ...ProductWithOptions
  1200. ... on ProductOptionInUseError {
  1201. errorCode
  1202. message
  1203. optionGroupCode
  1204. productVariantCount
  1205. }
  1206. }
  1207. }
  1208. ${PRODUCT_WITH_OPTIONS_FRAGMENT}
  1209. `;
  1210. export const GET_OPTION_GROUP = gql`
  1211. query GetOptionGroup($id: ID!) {
  1212. productOptionGroup(id: $id) {
  1213. id
  1214. code
  1215. options {
  1216. id
  1217. code
  1218. }
  1219. }
  1220. }
  1221. `;
  1222. export const GET_PRODUCT_VARIANT = gql`
  1223. query GetProductVariant($id: ID!) {
  1224. productVariant(id: $id) {
  1225. id
  1226. name
  1227. }
  1228. }
  1229. `;
  1230. export const GET_PRODUCT_VARIANT_LIST = gql`
  1231. query GetProductVariantLIST($options: ProductVariantListOptions) {
  1232. productVariants(options: $options) {
  1233. items {
  1234. id
  1235. name
  1236. sku
  1237. price
  1238. }
  1239. totalItems
  1240. }
  1241. }
  1242. `;