Skip to content

Commit

Permalink
Merge pull request #1266 from contentstack/fix/CS-43652
Browse files Browse the repository at this point in the history
CS-43652-fixed the test cases and modified the env created for angular, stencil and nuxt
  • Loading branch information
cs-raj authored Jan 25, 2024
2 parents 0214eba + 78051a4 commit 7eba02c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
16 changes: 8 additions & 8 deletions packages/contentstack-bootstrap/src/bootstrap/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ const envFileHandler = async (
customHost ? customHost : managementAPIHost
}${
!isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : ''
}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\nCONTENTSTACK_MANAGEMENT_TOKEN=''\nCONTENTSTACK_LIVE_EDIT_TAGS=false`;
}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\nCONTENTSTACK_LIVE_EDIT_TAGS=false`;
result = await writeEnvFile(content, filePath);
break;
case 'gatsby':
Expand All @@ -210,9 +210,9 @@ const envFileHandler = async (
environmentVariables.deliveryToken
}',\n${
livePreviewEnabled
? `\npreivew_token=${
? `\n\tpreivew_token:'${
environmentVariables.preview_token || `''`
}\npreview_host=${previewHost}\napp_host=${appHost}\n`
}'\n\tpreview_host:'${previewHost}'\n\tapp_host:'${appHost}'\n`
: '\n'
},\n\t\tenvironment: '${environmentVariables.environment}'${
!isUSRegion && !customHost ? `,\n\t\tregion: '${region.name}'` : ''
Expand All @@ -226,14 +226,14 @@ const envFileHandler = async (
environmentVariables.api_key
}', \n\tdelivery_token: '${environmentVariables.deliveryToken}',\n\t${
livePreviewEnabled
? `\npreview_token=${environmentVariables.preview_token || `''`}\npreview_host=${previewHost
}\napp_host=${appHost}`
? `\npreview_token:'${environmentVariables.preview_token || ''}',\npreview_host:'${previewHost
}',\napp_host:'${appHost}'`
: '\n'
},\n\tenvironment: '${environmentVariables.environment}'${
!isUSRegion && !customHost ? `,\n\tregion: '${region.name}'` : ''
},\n\tapi_host: '${
customHost ? customHost : managementAPIHost
}'\n\tmanagement_token: '',\n\tlive_preview: ${livePreviewEnabled}\n};`;
}',\n\tlive_preview: ${livePreviewEnabled}\n};`;
fileName = `environment${environmentVariables.environment === 'production' ? '.prod.' : '.'}ts`;
filePath = path.join(clonedDirectory, 'src', 'environments', fileName);
result = await writeEnvFile(content, filePath);
Expand All @@ -254,9 +254,9 @@ const envFileHandler = async (
: '\n'
}\nCONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${
!isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : ''
}\nCONTENTSTACK_API_HOST='${
}\nCONTENTSTACK_API_HOST=${
customHost ? customHost : managementAPIHost
}'CONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\n\nCONTENTSTACK_LIVE_EDIT_TAGS=false`;
}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\n\nCONTENTSTACK_LIVE_EDIT_TAGS=false`;
result = await writeEnvFile(content, filePath);
break;
case 'vue-starter':
Expand Down
14 changes: 8 additions & 6 deletions packages/contentstack-bootstrap/test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ describe('Utils', () => {
const region = {
name: 'NA',
cda: 'https://cdn.contentstack.com',
cma: 'https://app.contentstack.com',
cma: 'https://api.contentstack.com',
uiHost: 'https://app.contentstack.com'
};
const managementAPIClient = {
stack: () => {
Expand Down Expand Up @@ -73,12 +74,12 @@ describe('Utils', () => {
let devEnvFile = await getFileContent(path.join(clonedDirectory, '.env.development.local'));
devEnvFile = devEnvFile.replace(/\n/g, ',');
expect(devEnvFile).equal(
'REACT_APP_CONTENTSTACK_API_KEY=mock-api-key,REACT_APP_CONTENTSTACK_DELIVERY_TOKEN=mock-delivery-token,REACT_APP_CONTENTSTACK_PREVIEW_TOKEN=mock_preview_token,REACT_APP_CONTENTSTACK_PREVIEW_HOST=https://rest-preview.contentstack.com,REACT_APP_CONTENTSTACK_ENVIRONMENT=development,SKIP_PREFLIGHT_CHECK=true,REACT_APP_CONTENTSTACK_LIVE_PREVIEW=true',
'REACT_APP_CONTENTSTACK_API_KEY=mock-api-key,REACT_APP_CONTENTSTACK_DELIVERY_TOKEN=mock-delivery-token,REACT_APP_CONTENTSTACK_PREVIEW_TOKEN=mock_preview_token,REACT_APP_CONTENTSTACK_PREVIEW_HOST=rest-preview.contentstack.com,REACT_APP_CONTENTSTACK_APP_HOST=app.contentstack.com,,REACT_APP_CONTENTSTACK_ENVIRONMENT=development,,SKIP_PREFLIGHT_CHECK=true,REACT_APP_CONTENTSTACK_LIVE_PREVIEW=true',
);
let prodEnvFile = await getFileContent(path.join(clonedDirectory, '.env.production.local'));
prodEnvFile = prodEnvFile.replace(/\n/g, ',');
expect(prodEnvFile).equal(
'REACT_APP_CONTENTSTACK_API_KEY=mock-api-key,REACT_APP_CONTENTSTACK_DELIVERY_TOKEN=mock-delivery-token,REACT_APP_CONTENTSTACK_PREVIEW_TOKEN=mock_preview_token,REACT_APP_CONTENTSTACK_PREVIEW_HOST=https://rest-preview.contentstack.com,REACT_APP_CONTENTSTACK_ENVIRONMENT=production,SKIP_PREFLIGHT_CHECK=true,REACT_APP_CONTENTSTACK_LIVE_PREVIEW=true',
'REACT_APP_CONTENTSTACK_API_KEY=mock-api-key,REACT_APP_CONTENTSTACK_DELIVERY_TOKEN=mock-delivery-token,REACT_APP_CONTENTSTACK_PREVIEW_TOKEN=mock_preview_token,REACT_APP_CONTENTSTACK_PREVIEW_HOST=rest-preview.contentstack.com,REACT_APP_CONTENTSTACK_APP_HOST=app.contentstack.com,,REACT_APP_CONTENTSTACK_ENVIRONMENT=production,,SKIP_PREFLIGHT_CHECK=true,REACT_APP_CONTENTSTACK_LIVE_PREVIEW=true',
);
});
it('Create env file for a stack with live preview disabled', async () => {
Expand All @@ -94,6 +95,7 @@ describe('Utils', () => {
name: 'NA',
cda: 'https://cdn.contentstack.com',
cma: 'https://app.contentstack.com',
uiHost: 'https://app.contentstack.com'
};
const managementAPIClient = {
stack: () => {
Expand Down Expand Up @@ -121,12 +123,12 @@ describe('Utils', () => {
let devEnvFile = await getFileContent(path.join(clonedDirectory, '.env.development.local'));
devEnvFile = devEnvFile.replace(/\n/g, ',');
expect(devEnvFile).equal(
'REACT_APP_CONTENTSTACK_API_KEY=mock-api-key,REACT_APP_CONTENTSTACK_DELIVERY_TOKEN=mock-delivery-token,REACT_APP_CONTENTSTACK_ENVIRONMENT=development,SKIP_PREFLIGHT_CHECK=true,REACT_APP_CONTENTSTACK_LIVE_PREVIEW=false'
'REACT_APP_CONTENTSTACK_API_KEY=mock-api-key,REACT_APP_CONTENTSTACK_DELIVERY_TOKEN=mock-delivery-token,,REACT_APP_CONTENTSTACK_ENVIRONMENT=development,,SKIP_PREFLIGHT_CHECK=true,REACT_APP_CONTENTSTACK_LIVE_PREVIEW=false'
);
let prodEnvFile = await getFileContent(path.join(clonedDirectory, '.env.production.local'));
prodEnvFile = prodEnvFile.replace(/\n/g, ',');
expect(prodEnvFile).equal(
'REACT_APP_CONTENTSTACK_API_KEY=mock-api-key,REACT_APP_CONTENTSTACK_DELIVERY_TOKEN=mock-delivery-token,REACT_APP_CONTENTSTACK_ENVIRONMENT=production,SKIP_PREFLIGHT_CHECK=true,REACT_APP_CONTENTSTACK_LIVE_PREVIEW=false'
'REACT_APP_CONTENTSTACK_API_KEY=mock-api-key,REACT_APP_CONTENTSTACK_DELIVERY_TOKEN=mock-delivery-token,,REACT_APP_CONTENTSTACK_ENVIRONMENT=production,,SKIP_PREFLIGHT_CHECK=true,REACT_APP_CONTENTSTACK_LIVE_PREVIEW=false'
);
});
it('Create env with invalid environments, should throw an error', async () => {
Expand All @@ -140,7 +142,7 @@ describe('Utils', () => {
const region = {
name: 'NA',
cda: 'https://app.contentstack.com',
cma: 'https://app.contentstack.com',
cma: 'https://api.contentstack.com',
};
const managementAPIClient = {
stack: () => ({
Expand Down

0 comments on commit 7eba02c

Please sign in to comment.