From 8a791f37aa18985a0660ccd0f7181d6874da65fa Mon Sep 17 00:00:00 2001 From: ChengLei Shao Date: Sun, 13 Feb 2022 10:36:25 +0800 Subject: [PATCH] fix: ui schema storage (#188) * fix: test * chore: root schema x-index * fix: getJsonSchema & getProperties empty response --- .../src/__tests__/action.test.ts | 16 ++++++++++++++++ .../plugin-ui-schema-storage/src/repository.ts | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/packages/plugin-ui-schema-storage/src/__tests__/action.test.ts b/packages/plugin-ui-schema-storage/src/__tests__/action.test.ts index 26a22a98f..d74ab68ea 100644 --- a/packages/plugin-ui-schema-storage/src/__tests__/action.test.ts +++ b/packages/plugin-ui-schema-storage/src/__tests__/action.test.ts @@ -86,6 +86,22 @@ describe('action test', () => { expect(data.properties.b.properties.c['x-uid']).toEqual('n3'); }); + test('getJsonSchema when uid not exists', async () => { + const response = await app.agent().resource('ui_schemas').getJsonSchema({ + resourceIndex: 'not-exists', + }); + + expect(response.statusCode).toEqual(200); + }); + + test('get properties when uid not exists', async () => { + const response = await app.agent().resource('ui_schemas').getProperties({ + resourceIndex: 'not-exists', + }); + + expect(response.statusCode).toEqual(200); + }); + test('remove', async () => { await app .agent() diff --git a/packages/plugin-ui-schema-storage/src/repository.ts b/packages/plugin-ui-schema-storage/src/repository.ts index e313bc813..b236336d5 100644 --- a/packages/plugin-ui-schema-storage/src/repository.ts +++ b/packages/plugin-ui-schema-storage/src/repository.ts @@ -89,6 +89,10 @@ export class UiSchemaRepository extends Repository { }, }); + if (nodes[0].length == 0) { + return {}; + } + const schema = this.nodesToSchema(nodes[0], uid); return lodash.pick(schema, ['type', 'properties']); } @@ -117,6 +121,10 @@ export class UiSchemaRepository extends Repository { transaction: options?.transaction, }); + if (nodes[0].length == 0) { + return {}; + } + const schema = this.nodesToSchema(nodes[0], uid); return schema; }