global-settings.e2e-spec.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import { createErrorResultGuard, createTestEnvironment, ErrorResultGuard } from '@vendure/testing';
  2. import gql from 'graphql-tag';
  3. import path from 'path';
  4. import { initialData } from '../../../e2e-common/e2e-initial-data';
  5. import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
  6. import { GLOBAL_SETTINGS_FRAGMENT } from './graphql/fragments';
  7. import {
  8. GetGlobalSettingsQuery,
  9. GlobalSettingsFragment,
  10. LanguageCode,
  11. UpdateGlobalSettingsMutation,
  12. UpdateGlobalSettingsMutationVariables,
  13. } from './graphql/generated-e2e-admin-types';
  14. import { UPDATE_GLOBAL_SETTINGS } from './graphql/shared-definitions';
  15. describe('GlobalSettings resolver', () => {
  16. const { server, adminClient } = createTestEnvironment({
  17. ...testConfig(),
  18. ...{
  19. customFields: {
  20. Customer: [{ name: 'age', type: 'int' }],
  21. },
  22. },
  23. });
  24. let globalSettings: GlobalSettingsFragment;
  25. const globalSettingsGuard: ErrorResultGuard<GlobalSettingsFragment> = createErrorResultGuard(
  26. input => !!input.availableLanguages,
  27. );
  28. beforeAll(async () => {
  29. await server.init({
  30. initialData,
  31. productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-full.csv'),
  32. customerCount: 1,
  33. });
  34. await adminClient.asSuperAdmin();
  35. await adminClient.query<UpdateGlobalSettingsMutation, UpdateGlobalSettingsMutationVariables>(
  36. UPDATE_GLOBAL_SETTINGS,
  37. {
  38. input: {
  39. trackInventory: false,
  40. },
  41. },
  42. );
  43. const result = await adminClient.query<GetGlobalSettingsQuery>(GET_GLOBAL_SETTINGS);
  44. globalSettings = result.globalSettings;
  45. }, TEST_SETUP_TIMEOUT_MS);
  46. afterAll(async () => {
  47. await server.destroy();
  48. });
  49. describe('globalSettings query', () => {
  50. it('includes basic settings', () => {
  51. expect(globalSettings.availableLanguages).toEqual([LanguageCode.en]);
  52. expect(globalSettings.trackInventory).toBe(false);
  53. });
  54. it('includes orderProcess', () => {
  55. expect(globalSettings.serverConfig.orderProcess[0]).toEqual({
  56. name: 'Created',
  57. to: ['AddingItems'],
  58. });
  59. });
  60. it('includes permittedAssetTypes', () => {
  61. expect(globalSettings.serverConfig.permittedAssetTypes).toEqual([
  62. 'image/*',
  63. 'video/*',
  64. 'audio/*',
  65. '.pdf',
  66. ]);
  67. });
  68. it('includes customFieldConfig', () => {
  69. expect(globalSettings.serverConfig.customFieldConfig.Customer).toEqual([{ name: 'age' }]);
  70. });
  71. it('includes non-internal permission definitions', () => {
  72. const permissionNames = globalSettings.serverConfig.permissions.map(p => p.name);
  73. expect(permissionNames).toContain('CreateAdministrator');
  74. expect(permissionNames).not.toContain('SuperAdmin');
  75. expect(permissionNames).not.toContain('Owner');
  76. expect(permissionNames).not.toContain('Authenticated');
  77. });
  78. });
  79. describe('update', () => {
  80. it('returns error result when removing required language', async () => {
  81. const { updateGlobalSettings } = await adminClient.query<
  82. UpdateGlobalSettingsMutation,
  83. UpdateGlobalSettingsMutationVariables
  84. >(UPDATE_GLOBAL_SETTINGS, {
  85. input: {
  86. availableLanguages: [LanguageCode.zh],
  87. },
  88. });
  89. globalSettingsGuard.assertErrorResult(updateGlobalSettings);
  90. expect(updateGlobalSettings.message).toBe(
  91. 'Cannot make language "en" unavailable as it is used as the defaultLanguage by the channel "__default_channel__"',
  92. );
  93. });
  94. it('successful update', async () => {
  95. const { updateGlobalSettings } = await adminClient.query<
  96. UpdateGlobalSettingsMutation,
  97. UpdateGlobalSettingsMutationVariables
  98. >(UPDATE_GLOBAL_SETTINGS, {
  99. input: {
  100. availableLanguages: [LanguageCode.en, LanguageCode.zh],
  101. trackInventory: true,
  102. },
  103. });
  104. globalSettingsGuard.assertSuccess(updateGlobalSettings);
  105. expect(updateGlobalSettings.availableLanguages).toEqual([LanguageCode.en, LanguageCode.zh]);
  106. expect(updateGlobalSettings.trackInventory).toBe(true);
  107. });
  108. });
  109. });
  110. const GET_GLOBAL_SETTINGS = gql`
  111. query GetGlobalSettings {
  112. globalSettings {
  113. ...GlobalSettings
  114. }
  115. }
  116. ${GLOBAL_SETTINGS_FRAGMENT}
  117. `;