Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only set default src when creating app def if a frontend location is specified [EXT-5935] #2279

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,32 @@ describe('createAppDefinition', () => {
assert(loggedMessage.includes(tutorialLink));
assert.deepStrictEqual(cachedEnvVarsMock.args[0][0], { [APP_DEF_ENV_KEY]: 'appId' });
});

it('sets default src if any frontend location is specified', async () => {
const createAppDefinitionStub = stub().resolves({ sys: { id: 'testId' } });
clientMock.getOrganization = stub().resolves({
createAppDefinition: createAppDefinitionStub,
});
clientMock.getOrganizations = stub().resolves({
items: [{ name: 'name', sys: { id: organizationId } }],
});
selectFromListMock.returns({ name: 'name', value: organizationId });

await subject(token, { locations: ['entry-field', 'dialog'] });
assert(createAppDefinitionStub.calledWithMatch({ src: 'http://localhost:3000' }));
});

it('does not set default src if only location is dialog', async () => {
const createAppDefinitionStub = stub().resolves({ sys: { id: 'testId' } });
clientMock.getOrganization = stub().resolves({
createAppDefinition: createAppDefinitionStub,
});
clientMock.getOrganizations = stub().resolves({
items: [{ name: 'name', sys: { id: organizationId } }],
});
selectFromListMock.returns({ name: 'name', value: organizationId });

await subject(token, { locations: ['dialog'] });
assert(createAppDefinitionStub.calledWithMatch({ src: undefined }));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -73,37 +73,39 @@ export async function createAppDefinition(
const organizationId = selectedOrg.value;

const appName = appDefinitionSettings.name || path.basename(process.cwd());
const body = {
name: appName,
src: 'http://localhost:3000',
locations: appDefinitionSettings.locations.map((location) => {
if (location === 'entry-field') {
return {
location,
fieldTypes: appDefinitionSettings.fields || [],
};
}

if (location === 'page') {
const { pageNav, pageNavLinkName, pageNavLinkPath } = appDefinitionSettings;

return {
location,
...(pageNav
? {
navigationItem: {
name: pageNavLinkName,
path: pageNavLinkPath,
},
}
: {}),
};
}
const locations = appDefinitionSettings.locations.map((location) => {
if (location === 'entry-field') {
return {
location,
fieldTypes: appDefinitionSettings.fields || [],
};
}

if (location === 'page') {
const { pageNav, pageNavLinkName, pageNavLinkPath } = appDefinitionSettings;

return {
location,
...(pageNav
? {
navigationItem: {
name: pageNavLinkName,
path: pageNavLinkPath,
},
}
: {}),
};
}),
}

return {
location,
};
})
const hasFrontendLocation = locations.some(({ location }) => location !== 'dialog');
const body = {
name: appName,
src: hasFrontendLocation ? 'http://localhost:3000' : undefined,
locations,
parameters: {
...(appDefinitionSettings.parameters?.instance && {
instance: appDefinitionSettings.parameters.instance,
Expand Down
Loading