diff --git a/src/routes/safe/components/Apps/__tests__/utils.test.ts b/src/routes/safe/components/Apps/__tests__/utils.test.ts new file mode 100644 index 00000000..b2e43f87 --- /dev/null +++ b/src/routes/safe/components/Apps/__tests__/utils.test.ts @@ -0,0 +1,48 @@ +import { isAppManifestValid } from '../utils' +import { SafeApp, SAFE_APP_FETCH_STATUS } from '../types.d' + +describe('SafeApp manifest', () => { + it('It should return true given a manifest with mandatory values supplied', async () => { + const manifest = { + name: 'test', + description: 'a test', + error: false, + } + + const result = isAppManifestValid(manifest as SafeApp) + expect(result).toBe(true) + }) + + it('It should return false given a manifest without name', async () => { + const manifest = { + name: '', + description: 'a test', + error: false, + } + + const result = isAppManifestValid(manifest as SafeApp) + expect(result).toBe(false) + }) + + it('It should return false given a manifest without description', async () => { + const manifest = { + name: 'test', + description: '', + error: false, + } + + const result = isAppManifestValid(manifest as SafeApp) + expect(result).toBe(false) + }) + + it('It should return false given a manifest with error', async () => { + const manifest = { + name: 'test', + description: 'a test', + error: true, + } + + const result = isAppManifestValid(manifest as SafeApp) + expect(result).toBe(false) + }) +}) diff --git a/src/routes/safe/components/Apps/utils.ts b/src/routes/safe/components/Apps/utils.ts index f4ce90b7..6964c09d 100644 --- a/src/routes/safe/components/Apps/utils.ts +++ b/src/routes/safe/components/Apps/utils.ts @@ -165,8 +165,6 @@ export const isAppManifestValid = (appInfo: SafeApp): boolean => appInfo.name !== 'unknown' && // `description` exists !!appInfo.description && - // `url` exists - !!appInfo.url && // no `error` (or `error` undefined) !appInfo.error @@ -201,7 +199,7 @@ export const getAppInfoFromUrl = memoize( const appInfo = await axios.get(`${noTrailingSlashUrl}/manifest.json`, { timeout: 5_000 }) // verify imported app fulfil safe requirements - if (!appInfo?.data || isAppManifestValid(appInfo.data)) { + if (!appInfo?.data || !isAppManifestValid(appInfo.data)) { throw Error('The app does not fulfil the structure required.') } @@ -210,9 +208,16 @@ export const getAppInfoFromUrl = memoize( const jsonDataLength = 20 const remainingSpace = originFieldSize - res.url.length - jsonDataLength + const appInfoData = { + name: appInfo.data.name, + iconPath: appInfo.data.iconPath, + description: appInfo.data.description, + providedBy: appInfo.data.providedBy, + } + res = { ...res, - ...appInfo.data, + ...appInfoData, id: JSON.stringify({ url: res.url, name: appInfo.data.name.substring(0, remainingSpace) }), error: false, loadingStatus: SAFE_APP_FETCH_STATUS.SUCCESS,