fix(apps.service): updating an app config was throwing an error if domain was unchanged

This commit is contained in:
Nicolas Meienberger 2022-09-08 08:41:19 +02:00
parent d196b8ff10
commit bbdee4a42b
3 changed files with 13 additions and 1 deletions

View file

@ -110,6 +110,7 @@ const AppDetails: React.FC<IProps> = ({ app, info }) => {
description: 'App config updated successfully. Restart the app to apply the changes.',
position: 'top',
status: 'success',
isClosable: true,
});
updateSettingsDisclosure.onClose();
} catch (error) {
@ -126,6 +127,7 @@ const AppDetails: React.FC<IProps> = ({ app, info }) => {
description: 'App updated successfully',
position: 'top',
status: 'success',
isClosable: true,
});
} catch (error) {
handleError(error);

View file

@ -383,6 +383,15 @@ describe('Update app config', () => {
await AppsService.updateAppConfig(app2.appInfo.id, { TEST_FIELD: 'test' }, true, 'test.com');
await expect(AppsService.updateAppConfig(app3.appInfo.id, { TEST_FIELD: 'test' }, true, 'test.com')).rejects.toThrowError(`Domain test.com already in use by app ${app2.appInfo.id}`);
});
it('Should not throw if updating with same domain', async () => {
const app2 = await createApp({ exposable: true, installed: true });
// @ts-ignore
fs.__createMockFiles(Object.assign(app2.MockFiles));
await AppsService.updateAppConfig(app2.appInfo.id, { TEST_FIELD: 'test' }, true, 'test.com');
await AppsService.updateAppConfig(app2.appInfo.id, { TEST_FIELD: 'test' }, true, 'test.com');
});
});
describe('Get app config', () => {

View file

@ -5,6 +5,7 @@ import { AppInfo, AppStatusEnum, ListAppsResonse } from './apps.types';
import App from './app.entity';
import logger from '../../config/logger/logger';
import config from '../../config';
import { Not } from 'typeorm';
const sortApps = (a: AppInfo, b: AppInfo) => a.name.localeCompare(b.name);
@ -153,7 +154,7 @@ const updateAppConfig = async (id: string, form: Record<string, string>, exposed
}
if (exposed) {
const appsWithSameDomain = await App.find({ where: { domain, exposed: true } });
const appsWithSameDomain = await App.find({ where: { domain, exposed: true, id: Not(id) } });
if (appsWithSameDomain.length > 0) {
throw new Error(`Domain ${domain} already in use by app ${appsWithSameDomain[0].id}`);
}