1
0

country.e2e-spec.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import {
  2. CreateCountry,
  3. DeletionResult,
  4. GetCountry,
  5. GetCountryList,
  6. LanguageCode,
  7. UpdateCountry,
  8. } from '@vendure/common/lib/generated-types';
  9. import gql from 'graphql-tag';
  10. import path from 'path';
  11. import {
  12. CREATE_COUNTRY,
  13. GET_COUNTRY,
  14. GET_COUNTRY_LIST,
  15. UPDATE_COUNTRY,
  16. } from '../../../admin-ui/src/app/data/definitions/settings-definitions';
  17. import { TEST_SETUP_TIMEOUT_MS } from './config/test-config';
  18. import { TestAdminClient } from './test-client';
  19. import { TestServer } from './test-server';
  20. // tslint:disable:no-non-null-assertion
  21. describe('Facet resolver', () => {
  22. const client = new TestAdminClient();
  23. const server = new TestServer();
  24. let countries: GetCountryList.Items[];
  25. let GB: GetCountryList.Items;
  26. let AT: GetCountryList.Items;
  27. beforeAll(async () => {
  28. await server.init({
  29. productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-minimal.csv'),
  30. customerCount: 1,
  31. });
  32. await client.init();
  33. }, TEST_SETUP_TIMEOUT_MS);
  34. afterAll(async () => {
  35. await server.destroy();
  36. });
  37. it('countries', async () => {
  38. const result = await client.query<GetCountryList.Query>(GET_COUNTRY_LIST, {});
  39. expect(result.countries.totalItems).toBe(7);
  40. countries = result.countries.items;
  41. GB = countries.find(c => c.code === 'GB')!;
  42. AT = countries.find(c => c.code === 'AT')!;
  43. });
  44. it('country', async () => {
  45. const result = await client.query<GetCountry.Query, GetCountry.Variables>(GET_COUNTRY, {
  46. id: GB.id,
  47. });
  48. expect(result.country!.name).toBe(GB.name);
  49. });
  50. it('updateCountry', async () => {
  51. const result = await client.query<UpdateCountry.Mutation, UpdateCountry.Variables>(UPDATE_COUNTRY, {
  52. input: {
  53. id: AT.id,
  54. enabled: false,
  55. },
  56. });
  57. expect(result.updateCountry.enabled).toBe(false);
  58. });
  59. it('createCountry', async () => {
  60. const result = await client.query<CreateCountry.Mutation, CreateCountry.Variables>(CREATE_COUNTRY, {
  61. input: {
  62. code: 'GL',
  63. enabled: true,
  64. translations: [{ languageCode: LanguageCode.en, name: 'Gondwanaland' }],
  65. },
  66. });
  67. expect(result.createCountry.name).toBe('Gondwanaland');
  68. });
  69. describe('deletion', () => {
  70. it('deletes Country not used in any address', async () => {
  71. const result1 = await client.query(DELETE_COUNTRY, { id: AT.id });
  72. expect(result1.deleteCountry).toEqual({
  73. result: DeletionResult.DELETED,
  74. message: '',
  75. });
  76. const result2 = await client.query<GetCountryList.Query>(GET_COUNTRY_LIST, {});
  77. expect(result2.countries.items.find(c => c.id === AT.id)).toBeUndefined();
  78. });
  79. it('does not delete Country that is used in one or more addresses', async () => {
  80. const result1 = await client.query(DELETE_COUNTRY, { id: GB.id });
  81. expect(result1.deleteCountry).toEqual({
  82. result: DeletionResult.NOT_DELETED,
  83. message: 'The selected Country cannot be deleted as it is used in 1 Address',
  84. });
  85. const result2 = await client.query<GetCountryList.Query>(GET_COUNTRY_LIST, {});
  86. expect(result2.countries.items.find(c => c.id === GB.id)).not.toBeUndefined();
  87. });
  88. });
  89. });
  90. const DELETE_COUNTRY = gql`
  91. mutation DeleteCountry($id: ID!) {
  92. deleteCountry(id: $id) {
  93. result
  94. message
  95. }
  96. }
  97. `;