country.e2e-spec.ts 4.0 KB

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