tax-rate.e2e-spec.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* eslint-disable @typescript-eslint/no-non-null-assertion */
  2. import { pick } from '@vendure/common/lib/pick';
  3. import { createTestEnvironment } from '@vendure/testing';
  4. import gql from 'graphql-tag';
  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 { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
  9. import { TAX_RATE_FRAGMENT } from './graphql/fragments';
  10. import * as Codegen from './graphql/generated-e2e-admin-types';
  11. import { DeletionResult } from './graphql/generated-e2e-admin-types';
  12. import { GET_TAX_RATES_LIST, UPDATE_TAX_RATE } from './graphql/shared-definitions';
  13. describe('TaxRate resolver', () => {
  14. const { server, adminClient, shopClient } = createTestEnvironment(testConfig());
  15. beforeAll(async () => {
  16. await server.init({
  17. initialData,
  18. productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-minimal.csv'),
  19. customerCount: 2,
  20. });
  21. await adminClient.asSuperAdmin();
  22. }, TEST_SETUP_TIMEOUT_MS);
  23. afterAll(async () => {
  24. await server.destroy();
  25. });
  26. it('taxRates list', async () => {
  27. const { taxRates } = await adminClient.query<Codegen.GetTaxRatesQuery>(GET_TAX_RATES_LIST);
  28. expect(taxRates.totalItems).toBe(15);
  29. });
  30. it('taxRate', async () => {
  31. const { taxRate } = await adminClient.query<
  32. Codegen.GetTaxRateQuery,
  33. Codegen.GetTaxRateQueryVariables
  34. >(GET_TAX_RATE, {
  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<
  48. Codegen.CreateTaxRateMutation,
  49. Codegen.CreateTaxRateMutationVariables
  50. >(CREATE_TAX_RATE, {
  51. input: {
  52. name: 'My Tax Rate',
  53. categoryId: 'T_1',
  54. zoneId: 'T_1',
  55. enabled: true,
  56. value: 17.5,
  57. },
  58. });
  59. expect(createTaxRate.name).toBe('My Tax Rate');
  60. expect(createTaxRate.value).toBe(17.5);
  61. });
  62. it('updateTaxRate', async () => {
  63. const { updateTaxRate } = await adminClient.query<
  64. Codegen.UpdateTaxRateMutation,
  65. Codegen.UpdateTaxRateMutationVariables
  66. >(UPDATE_TAX_RATE, {
  67. input: {
  68. id: 'T_1',
  69. value: 17.5,
  70. },
  71. });
  72. expect(updateTaxRate.value).toBe(17.5);
  73. });
  74. it('deleteTaxRate', async () => {
  75. const { deleteTaxRate } = await adminClient.query<
  76. Codegen.DeleteTaxRateMutation,
  77. Codegen.DeleteTaxRateMutationVariables
  78. >(DELETE_TAX_RATE, {
  79. id: 'T_3',
  80. });
  81. expect(deleteTaxRate.result).toBe(DeletionResult.DELETED);
  82. expect(deleteTaxRate.message).toBeNull();
  83. const { taxRates } = await adminClient.query<Codegen.GetTaxRatesQuery>(GET_TAX_RATES_LIST);
  84. expect(taxRates.items.find(x => x.id === 'T_3')).toBeUndefined();
  85. });
  86. });
  87. export const GET_TAX_RATE = gql`
  88. query GetTaxRate($id: ID!) {
  89. taxRate(id: $id) {
  90. ...TaxRate
  91. }
  92. }
  93. ${TAX_RATE_FRAGMENT}
  94. `;
  95. export const CREATE_TAX_RATE = gql`
  96. mutation CreateTaxRate($input: CreateTaxRateInput!) {
  97. createTaxRate(input: $input) {
  98. ...TaxRate
  99. }
  100. }
  101. ${TAX_RATE_FRAGMENT}
  102. `;
  103. export const DELETE_TAX_RATE = gql`
  104. mutation DeleteTaxRate($id: ID!) {
  105. deleteTaxRate(id: $id) {
  106. result
  107. message
  108. }
  109. }
  110. `;