Skip to content

Commit

Permalink
test: update test to multitenant runtintime config
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoa committed Dec 15, 2022
1 parent 48c7b88 commit 40afff8
Showing 1 changed file with 51 additions and 36 deletions.
87 changes: 51 additions & 36 deletions src/initialize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,52 @@ jest.mock('./auth/LocalForageCache');

let config = null;
const newConfig = {
common: {
SITE_NAME: 'Test Case',
LOGO_URL: 'http://test.example.com:18000/theme/logo.png',
LOGO_TRADEMARK_URL: 'http://test.example.com:18000/theme/logo.png',
LOGO_WHITE_URL: 'http://test.example.com:18000/theme/logo.png',
ACCESS_TOKEN_COOKIE_NAME: 'edx-jwt-cookie-header-payload',
FAVICON_URL: 'http://test.example.com:18000/theme/favicon.ico',
CSRF_TOKEN_API_PATH: '/csrf/api/v1/token',
DISCOVERY_API_BASE_URL: 'http://test.example.com:18381',
PUBLISHER_BASE_URL: 'http://test.example.com:18400',
ECOMMERCE_BASE_URL: 'http://test.example.com:18130',
LANGUAGE_PREFERENCE_COOKIE_NAME: 'openedx-language-preference',
LEARNING_BASE_URL: 'http://test.example.com:2000',
LMS_BASE_URL: 'http://test.example.com:18000',
LOGIN_URL: 'http://test.example.com:18000/login',
LOGOUT_URL: 'http://test.example.com:18000/logout',
STUDIO_BASE_URL: 'http://studio.example.com:18010',
MARKETING_SITE_BASE_URL: 'http://test.example.com:18000',
ORDER_HISTORY_URL: 'http://test.example.com:1996/orders',
REFRESH_ACCESS_TOKEN_ENDPOINT: 'http://test.example.com:18000/login_refresh',
SEGMENT_KEY: '',
USER_INFO_COOKIE_NAME: 'edx-user-info',
IGNORED_ERROR_REGEX: '',
CREDENTIALS_BASE_URL: 'http://test.example.com:18150',
localhost: {
common: {
SITE_NAME: 'Test Case',
LOGO_URL: 'http://test.example.com:18000/theme/logo.png',
LOGO_TRADEMARK_URL: 'http://test.example.com:18000/theme/logo.png',
LOGO_WHITE_URL: 'http://test.example.com:18000/theme/logo.png',
ACCESS_TOKEN_COOKIE_NAME: 'edx-jwt-cookie-header-payload',
FAVICON_URL: 'http://test.example.com:18000/theme/favicon.ico',
CSRF_TOKEN_API_PATH: '/csrf/api/v1/token',
DISCOVERY_API_BASE_URL: 'http://test.example.com:18381',
PUBLISHER_BASE_URL: 'http://test.example.com:18400',
ECOMMERCE_BASE_URL: 'http://test.example.com:18130',
LANGUAGE_PREFERENCE_COOKIE_NAME: 'openedx-language-preference',
LEARNING_BASE_URL: 'http://test.example.com:2000',
LMS_BASE_URL: 'http://test.example.com:18000',
LOGIN_URL: 'http://test.example.com:18000/login',
LOGOUT_URL: 'http://test.example.com:18000/logout',
STUDIO_BASE_URL: 'http://studio.example.com:18010',
MARKETING_SITE_BASE_URL: 'http://test.example.com:18000',
ORDER_HISTORY_URL: 'http://test.example.com:1996/orders',
REFRESH_ACCESS_TOKEN_ENDPOINT: 'http://test.example.com:18000/login_refresh',
SEGMENT_KEY: '',
USER_INFO_COOKIE_NAME: 'edx-user-info',
IGNORED_ERROR_REGEX: '',
CREDENTIALS_BASE_URL: 'http://test.example.com:18150',
},
auth: {
INFO_EMAIL: 'openedx@example.com',
ACTIVATION_EMAIL_SUPPORT_LINK: 'http//support.test.com',
},
learning: {
LEGACY_THEME_NAME: 'example',
DISCUSSIONS_MFE_BASE_URL: 'http://test.example.com:2002',
},
},
auth: {
INFO_EMAIL: 'openedx@example.com',
ACTIVATION_EMAIL_SUPPORT_LINK: 'http//support.test.com',
},
learning: {
LEGACY_THEME_NAME: 'example',
DISCUSSIONS_MFE_BASE_URL: 'http://test.example.com:2002',
site2: {
common: {
SITE_NAME: 'Site 2',
LOGO_URL: 'http://test.example-site2.com:18000/theme/logo.png',
LOGO_TRADEMARK_URL: 'http://test.example-site2.com:18000/theme/logo.png',
LOGO_WHITE_URL: 'http://test.example-site2.com:18000/theme/logo.png',
LMS_BASE_URL: 'http://test.example-site2.com:18000',
LOGIN_URL: 'http://test.example-site2.com:18000/login',
LOGOUT_URL: 'http://test.example-site2.com:18000/logout',

},
},
};

Expand Down Expand Up @@ -279,14 +293,15 @@ describe('initialize', () => {
expect(overrideHandlers.initError).toHaveBeenCalledWith(new Error('uhoh!'));
});

it('should initialize the app with runtime configuration', async () => {
it('should initialize the app with runtime configuration by site', async () => {
config.MFE_CONFIG_API_URL = 'http://localhost:18000/api/mfe/v1/config';
config.APP_ID = 'auth';
configureCache.mockReturnValueOnce(Promise.resolve({
get: (url) => {
const params = new URL(url).search;
const mfe = new URLSearchParams(params).get('mfe');
return ({ data: { ...newConfig.common, ...newConfig[mfe] } });
const site = new URLSearchParams(params).get('site');
return ({ data: { ...newConfig[site].common, ...newConfig[site][mfe] } });
},
}));

Expand Down Expand Up @@ -315,9 +330,9 @@ describe('initialize', () => {
expect(ensureAuthenticatedUser).not.toHaveBeenCalled();
expect(hydrateAuthenticatedUser).not.toHaveBeenCalled();
expect(logError).not.toHaveBeenCalled();
expect(config.SITE_NAME).toBe(newConfig.common.SITE_NAME);
expect(config.INFO_EMAIL).toBe(newConfig.auth.INFO_EMAIL);
expect(Object.values(config).includes(newConfig.learning.DISCUSSIONS_MFE_BASE_URL)).toBeFalsy();
expect(config.SITE_NAME).toBe(newConfig.localhost.common.SITE_NAME);
expect(config.INFO_EMAIL).toBe(newConfig.localhost.auth.INFO_EMAIL);
expect(Object.values(config).includes(newConfig.localhost.learning.DISCUSSIONS_MFE_BASE_URL)).toBeFalsy();
});

it('should initialize the app with the build config when runtime configuration fails', async () => {
Expand Down

0 comments on commit 40afff8

Please sign in to comment.