global-settings.e2e-spec.ts 4.2 KB

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