tax-rate.e2e-spec.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* eslint-disable @typescript-eslint/no-non-null-assertion */
  2. import { DeletionResult } from '@vendure/common/lib/generated-types';
  3. import { pick } from '@vendure/common/lib/pick';
  4. import { createTestEnvironment } from '@vendure/testing';
  5. import path from 'path';
  6. import { afterAll, beforeAll, describe, expect, it } from 'vitest';
  7. import { initialData } from '../../../e2e-common/e2e-initial-data';
  8. import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config';
  9. import {
  10. createTaxRateDocument,
  11. deleteTaxRateDocument,
  12. getTaxRateDocument,
  13. getTaxRatesListDocument,
  14. updateTaxRateDocument,
  15. } from './graphql/shared-definitions';
  16. describe('TaxRate resolver', () => {
  17. const { server, adminClient, shopClient } = createTestEnvironment(testConfig());
  18. beforeAll(async () => {
  19. await server.init({
  20. initialData,
  21. productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-minimal.csv'),
  22. customerCount: 2,
  23. });
  24. await adminClient.asSuperAdmin();
  25. }, TEST_SETUP_TIMEOUT_MS);
  26. afterAll(async () => {
  27. await server.destroy();
  28. });
  29. it('taxRates list', async () => {
  30. const { taxRates } = await adminClient.query(getTaxRatesListDocument);
  31. expect(taxRates.totalItems).toBe(15);
  32. });
  33. it('taxRate', async () => {
  34. const { taxRate } = await adminClient.query(getTaxRateDocument, {
  35. id: 'T_1',
  36. });
  37. expect(pick(taxRate!, ['id', 'name', 'enabled', 'value'])).toEqual({
  38. id: 'T_1',
  39. name: 'Standard Tax Oceania',
  40. enabled: true,
  41. value: 20,
  42. });
  43. expect(taxRate!.category.name).toBe('Standard Tax');
  44. expect(taxRate!.zone.name).toBe('Oceania');
  45. });
  46. it('createTaxRate', async () => {
  47. const { createTaxRate } = await adminClient.query(createTaxRateDocument, {
  48. input: {
  49. name: 'My Tax Rate',
  50. categoryId: 'T_1',
  51. zoneId: 'T_1',
  52. enabled: true,
  53. value: 17.5,
  54. },
  55. });
  56. expect(createTaxRate.name).toBe('My Tax Rate');
  57. expect(createTaxRate.value).toBe(17.5);
  58. });
  59. it('updateTaxRate', async () => {
  60. const { updateTaxRate } = await adminClient.query(updateTaxRateDocument, {
  61. input: {
  62. id: 'T_1',
  63. value: 17.5,
  64. },
  65. });
  66. expect(updateTaxRate.value).toBe(17.5);
  67. });
  68. it('deleteTaxRate', async () => {
  69. const { deleteTaxRate } = await adminClient.query(deleteTaxRateDocument, {
  70. id: 'T_3',
  71. });
  72. expect(deleteTaxRate.result).toBe(DeletionResult.DELETED);
  73. expect(deleteTaxRate.message).toBeNull();
  74. const { taxRates } = await adminClient.query(getTaxRatesListDocument);
  75. expect(taxRates.items.find(x => x.id === 'T_3')).toBeUndefined();
  76. });
  77. });