From b417603eca9a2d98e2313d59513d2d77d321691b Mon Sep 17 00:00:00 2001 From: Oleg Shuralev Date: Fri, 5 Mar 2021 17:09:17 +0300 Subject: [PATCH] [ISSUE-200] Update FE to support new version of api --- .../__snapshots__/Details.spec.tsx.snap | 6 ++++ .../Schemas/Details/__test__/fixtures.ts | 5 +++- .../__snapshots__/ListItem.spec.tsx.snap | 1 + .../Schemas/List/__test__/fixtures.ts | 5 +++- .../src/components/Schemas/New/New.tsx | 11 +++++--- .../src/redux/actions/__test__/fixtures.ts | 4 ++- .../src/redux/actions/__test__/thunks.spec.ts | 28 ++++++++----------- .../src/redux/actions/thunks.ts | 3 -- .../__snapshots__/reducer.spec.ts.snap | 6 ++++ .../reducers/schemas/__test__/fixtures.ts | 12 +++++++- 10 files changed, 54 insertions(+), 27 deletions(-) diff --git a/kafka-ui-react-app/src/components/Schemas/Details/__test__/__snapshots__/Details.spec.tsx.snap b/kafka-ui-react-app/src/components/Schemas/Details/__test__/__snapshots__/Details.spec.tsx.snap index 7871bb5588c508a0016943770cfdbbfb676b4961..32a8b9d34a5bfeea5cf2e5ab1d5f45b43e86fec9 100644 --- a/kafka-ui-react-app/src/components/Schemas/Details/__test__/__snapshots__/Details.spec.tsx.snap +++ b/kafka-ui-react-app/src/components/Schemas/Details/__test__/__snapshots__/Details.spec.tsx.snap @@ -75,6 +75,7 @@ exports[`Details View Initial state matches snapshot 1`] = ` "compatibilityLevel": "BACKWARD", "id": 1, "schema": "{\\"type\\":\\"record\\",\\"name\\":\\"MyRecord1\\",\\"namespace\\":\\"com.mycompany\\",\\"fields\\":[{\\"name\\":\\"id\\",\\"type\\":\\"long\\"}]}", + "schemaType": "JSON", "subject": "test", "version": "1", } @@ -181,6 +182,7 @@ exports[`Details View when page with schema versions is loading matches snapshot "compatibilityLevel": "BACKWARD", "id": 1, "schema": "{\\"type\\":\\"record\\",\\"name\\":\\"MyRecord1\\",\\"namespace\\":\\"com.mycompany\\",\\"fields\\":[{\\"name\\":\\"id\\",\\"type\\":\\"long\\"}]}", + "schemaType": "JSON", "subject": "test", "version": "1", } @@ -266,6 +268,7 @@ exports[`Details View when page with schema versions loaded when schema has vers "compatibilityLevel": "BACKWARD", "id": 1, "schema": "{\\"type\\":\\"record\\",\\"name\\":\\"MyRecord1\\",\\"namespace\\":\\"com.mycompany\\",\\"fields\\":[{\\"name\\":\\"id\\",\\"type\\":\\"long\\"}]}", + "schemaType": "JSON", "subject": "test", "version": "1", } @@ -299,6 +302,7 @@ exports[`Details View when page with schema versions loaded when schema has vers "compatibilityLevel": "BACKWARD", "id": 1, "schema": "{\\"type\\":\\"record\\",\\"name\\":\\"MyRecord1\\",\\"namespace\\":\\"com.mycompany\\",\\"fields\\":[{\\"name\\":\\"id\\",\\"type\\":\\"long\\"}]}", + "schemaType": "JSON", "subject": "test", "version": "1", } @@ -311,6 +315,7 @@ exports[`Details View when page with schema versions loaded when schema has vers "compatibilityLevel": "BACKWARD", "id": 2, "schema": "{\\"type\\":\\"record\\",\\"name\\":\\"MyRecord2\\",\\"namespace\\":\\"com.mycompany\\",\\"fields\\":[{\\"name\\":\\"id\\",\\"type\\":\\"long\\"}]}", + "schemaType": "JSON", "subject": "test", "version": "2", } @@ -397,6 +402,7 @@ exports[`Details View when page with schema versions loaded when versions are em "compatibilityLevel": "BACKWARD", "id": 1, "schema": "{\\"type\\":\\"record\\",\\"name\\":\\"MyRecord1\\",\\"namespace\\":\\"com.mycompany\\",\\"fields\\":[{\\"name\\":\\"id\\",\\"type\\":\\"long\\"}]}", + "schemaType": "JSON", "subject": "test", "version": "1", } diff --git a/kafka-ui-react-app/src/components/Schemas/Details/__test__/fixtures.ts b/kafka-ui-react-app/src/components/Schemas/Details/__test__/fixtures.ts index 019532251b83120b78f0b57869b6a7d0857038f4..d53190c9f637d3b14ea784fe45c9877563a206c1 100644 --- a/kafka-ui-react-app/src/components/Schemas/Details/__test__/fixtures.ts +++ b/kafka-ui-react-app/src/components/Schemas/Details/__test__/fixtures.ts @@ -1,4 +1,4 @@ -import { SchemaSubject } from 'generated-sources'; +import { SchemaSubject, SchemaType } from 'generated-sources'; export const schema: SchemaSubject = { subject: 'test', @@ -7,6 +7,7 @@ export const schema: SchemaSubject = { schema: '{"type":"record","name":"MyRecord1","namespace":"com.mycompany","fields":[{"name":"id","type":"long"}]}', compatibilityLevel: 'BACKWARD', + schemaType: SchemaType.JSON, }; export const versions: SchemaSubject[] = [ @@ -17,6 +18,7 @@ export const versions: SchemaSubject[] = [ schema: '{"type":"record","name":"MyRecord1","namespace":"com.mycompany","fields":[{"name":"id","type":"long"}]}', compatibilityLevel: 'BACKWARD', + schemaType: SchemaType.JSON, }, { subject: 'test', @@ -25,5 +27,6 @@ export const versions: SchemaSubject[] = [ schema: '{"type":"record","name":"MyRecord2","namespace":"com.mycompany","fields":[{"name":"id","type":"long"}]}', compatibilityLevel: 'BACKWARD', + schemaType: SchemaType.JSON, }, ]; diff --git a/kafka-ui-react-app/src/components/Schemas/List/__test__/__snapshots__/ListItem.spec.tsx.snap b/kafka-ui-react-app/src/components/Schemas/List/__test__/__snapshots__/ListItem.spec.tsx.snap index 1783cdc9943356691a22ae3e83810e1101d84fd8..e26acad840820e63065edf177da43f746d3f7e0d 100644 --- a/kafka-ui-react-app/src/components/Schemas/List/__test__/__snapshots__/ListItem.spec.tsx.snap +++ b/kafka-ui-react-app/src/components/Schemas/List/__test__/__snapshots__/ListItem.spec.tsx.snap @@ -32,6 +32,7 @@ exports[`ListItem matches snapshot 1`] = ` "compatibilityLevel": "BACKWARD", "id": 1, "schema": "{\\"type\\":\\"record\\",\\"name\\":\\"MyRecord1\\",\\"namespace\\":\\"com.mycompany\\",\\"fields\\":[{\\"name\\":\\"id\\",\\"type\\":\\"long\\"}]}", + "schemaType": "JSON", "subject": "test", "version": "1", } diff --git a/kafka-ui-react-app/src/components/Schemas/List/__test__/fixtures.ts b/kafka-ui-react-app/src/components/Schemas/List/__test__/fixtures.ts index 7b337a23ec95f74f8d11776050d0ff6b01009b07..46a4d5a10561440650a199b3672a541533325181 100644 --- a/kafka-ui-react-app/src/components/Schemas/List/__test__/fixtures.ts +++ b/kafka-ui-react-app/src/components/Schemas/List/__test__/fixtures.ts @@ -1,4 +1,4 @@ -import { SchemaSubject } from 'generated-sources'; +import { SchemaSubject, SchemaType } from 'generated-sources'; export const schemas: SchemaSubject[] = [ { @@ -8,6 +8,7 @@ export const schemas: SchemaSubject[] = [ schema: '{"type":"record","name":"MyRecord1","namespace":"com.mycompany","fields":[{"name":"id","type":"long"}]}', compatibilityLevel: 'BACKWARD', + schemaType: SchemaType.JSON, }, { subject: 'test2', @@ -16,6 +17,7 @@ export const schemas: SchemaSubject[] = [ schema: '{"type":"record","name":"MyRecord2","namespace":"com.mycompany","fields":[{"name":"id","type":"long"}]}', compatibilityLevel: 'BACKWARD', + schemaType: SchemaType.JSON, }, { subject: 'test3', @@ -24,5 +26,6 @@ export const schemas: SchemaSubject[] = [ schema: '{"type":"record","name":"MyRecord3","namespace":"com.mycompany","fields":[{"name":"id","type":"long"}]}', compatibilityLevel: 'BACKWARD', + schemaType: SchemaType.JSON, }, ]; diff --git a/kafka-ui-react-app/src/components/Schemas/New/New.tsx b/kafka-ui-react-app/src/components/Schemas/New/New.tsx index cc15b9709e6745cf596aff4c558a988b728d960e..7a1325b9242c85ac571e5e532b0aa13fa32994f3 100644 --- a/kafka-ui-react-app/src/components/Schemas/New/New.tsx +++ b/kafka-ui-react-app/src/components/Schemas/New/New.tsx @@ -1,17 +1,16 @@ import React from 'react'; -import { ClusterName, SchemaName, NewSchemaSubjectRaw } from 'redux/interfaces'; +import { ClusterName, NewSchemaSubjectRaw } from 'redux/interfaces'; import { useForm } from 'react-hook-form'; import { ErrorMessage } from '@hookform/error-message'; import Breadcrumb from 'components/common/Breadcrumb/Breadcrumb'; import { clusterSchemaPath, clusterSchemasPath } from 'lib/paths'; -import { NewSchemaSubject } from 'generated-sources'; +import { NewSchemaSubject, SchemaType } from 'generated-sources'; import { SCHEMA_NAME_VALIDATION_PATTERN } from 'lib/constants'; import { useHistory, useParams } from 'react-router'; export interface NewProps { createSchema: ( clusterName: ClusterName, - subject: SchemaName, newSchemaSubject: NewSchemaSubject ) => void; } @@ -29,7 +28,11 @@ const New: React.FC = ({ createSchema }) => { const onSubmit = React.useCallback( async ({ subject, schema }: NewSchemaSubjectRaw) => { try { - await createSchema(clusterName, subject, { schema }); + await createSchema(clusterName, { + subject, + schema, + schemaType: SchemaType.AVRO, + }); history.push(clusterSchemaPath(clusterName, subject)); } catch (e) { // Show Error diff --git a/kafka-ui-react-app/src/redux/actions/__test__/fixtures.ts b/kafka-ui-react-app/src/redux/actions/__test__/fixtures.ts index d8e4a598043bca1e9bc36572e639974ab7834b76..663dbaaafc5f431bb4acdc77414cd9ebeeb84788 100644 --- a/kafka-ui-react-app/src/redux/actions/__test__/fixtures.ts +++ b/kafka-ui-react-app/src/redux/actions/__test__/fixtures.ts @@ -1,4 +1,4 @@ -import { ClusterStats, NewSchemaSubject } from 'generated-sources'; +import { ClusterStats, NewSchemaSubject, SchemaType } from 'generated-sources'; export const clusterStats: ClusterStats = { brokerCount: 1, @@ -13,6 +13,8 @@ export const clusterStats: ClusterStats = { }; export const schemaPayload: NewSchemaSubject = { + subject: 'NewSchema', schema: '{"type":"record","name":"MyRecord1","namespace":"com.mycompany","fields":[{"name":"id","type":"long"}]}', + schemaType: SchemaType.JSON, }; diff --git a/kafka-ui-react-app/src/redux/actions/__test__/thunks.spec.ts b/kafka-ui-react-app/src/redux/actions/__test__/thunks.spec.ts index 0cb4267511a03b496f50e7936a96dbb9933c0d74..611b8ad174e2620560d80f5def43f8cb1cd5ef79 100644 --- a/kafka-ui-react-app/src/redux/actions/__test__/thunks.spec.ts +++ b/kafka-ui-react-app/src/redux/actions/__test__/thunks.spec.ts @@ -108,11 +108,11 @@ describe('Thunks', () => { describe('createSchema', () => { it('creates POST_SCHEMA__SUCCESS when posting new schema', async () => { - fetchMock.postOnce(`/api/clusters/${clusterName}/schemas/${subject}`, { + fetchMock.postOnce(`/api/clusters/${clusterName}/schemas`, { body: schemaFixtures.schemaVersionsPayload[0], }); await store.dispatch( - thunks.createSchema(clusterName, subject, fixtures.schemaPayload) + thunks.createSchema(clusterName, fixtures.schemaPayload) ); expect(store.getActions()).toEqual([ actions.createSchemaAction.request(), @@ -122,19 +122,15 @@ describe('Thunks', () => { ]); }); - // it('creates POST_SCHEMA__FAILURE when posting new schema', async () => { - // fetchMock.postOnce( - // `/api/clusters/${clusterName}/schemas/${subject}`, - // 404 - // ); - // await store.dispatch( - // thunks.createSchema(clusterName, subject, fixtures.schemaPayload) - // ); - // expect(store.getActions()).toEqual([ - // actions.createSchemaAction.request(), - // actions.createSchemaAction.failure(), - // ]); - // expect(store.getActions()).toThrow(); - // }); + it('creates POST_SCHEMA__FAILURE when posting new schema', async () => { + fetchMock.postOnce(`/api/clusters/${clusterName}/schemas`, 404); + await store.dispatch( + thunks.createSchema(clusterName, fixtures.schemaPayload) + ); + expect(store.getActions()).toEqual([ + actions.createSchemaAction.request(), + actions.createSchemaAction.failure(), + ]); + }); }); }); diff --git a/kafka-ui-react-app/src/redux/actions/thunks.ts b/kafka-ui-react-app/src/redux/actions/thunks.ts index f650d011bfbecff10d5322f7637208d227928d4d..31222ebb09236659a362f09bdf0faba39c7d698a 100644 --- a/kafka-ui-react-app/src/redux/actions/thunks.ts +++ b/kafka-ui-react-app/src/redux/actions/thunks.ts @@ -285,19 +285,16 @@ export const fetchSchemaVersions = ( export const createSchema = ( clusterName: ClusterName, - subject: SchemaName, newSchemaSubject: NewSchemaSubject ): PromiseThunkResult => async (dispatch) => { dispatch(actions.createSchemaAction.request()); try { const schema: SchemaSubject = await apiClient.createNewSchema({ clusterName, - subject, newSchemaSubject, }); dispatch(actions.createSchemaAction.success(schema)); } catch (e) { dispatch(actions.createSchemaAction.failure()); - throw e; } }; diff --git a/kafka-ui-react-app/src/redux/reducers/schemas/__test__/__snapshots__/reducer.spec.ts.snap b/kafka-ui-react-app/src/redux/reducers/schemas/__test__/__snapshots__/reducer.spec.ts.snap index bf18ffa14fe392579ea4ecc2b34447a2b4b09596..61332659b76e2f065e60a35b57947a9045160c63 100644 --- a/kafka-ui-react-app/src/redux/reducers/schemas/__test__/__snapshots__/reducer.spec.ts.snap +++ b/kafka-ui-react-app/src/redux/reducers/schemas/__test__/__snapshots__/reducer.spec.ts.snap @@ -12,6 +12,7 @@ Object { "compatibilityLevel": "BACKWARD", "id": 2, "schema": "{\\"type\\":\\"record\\",\\"name\\":\\"MyRecord2\\",\\"namespace\\":\\"com.mycompany\\",\\"fields\\":[{\\"name\\":\\"id\\",\\"type\\":\\"long\\"}]}", + "schemaType": "JSON", "subject": "test", "version": "2", }, @@ -19,6 +20,7 @@ Object { "compatibilityLevel": "BACKWARD", "id": 4, "schema": "{\\"type\\":\\"record\\",\\"name\\":\\"MyRecord4\\",\\"namespace\\":\\"com.mycompany\\",\\"fields\\":[{\\"name\\":\\"id\\",\\"type\\":\\"long\\"}]}", + "schemaType": "JSON", "subject": "test2", "version": "3", }, @@ -26,6 +28,7 @@ Object { "compatibilityLevel": "BACKWARD", "id": 5, "schema": "{\\"type\\":\\"record\\",\\"name\\":\\"MyRecord\\",\\"namespace\\":\\"com.mycompany\\",\\"fields\\":[{\\"name\\":\\"id\\",\\"type\\":\\"long\\"}]}", + "schemaType": "JSON", "subject": "test3", "version": "1", }, @@ -43,6 +46,7 @@ Object { "compatibilityLevel": "BACKWARD", "id": 1, "schema": "{\\"type\\":\\"record\\",\\"name\\":\\"MyRecord1\\",\\"namespace\\":\\"com.mycompany\\",\\"fields\\":[{\\"name\\":\\"id\\",\\"type\\":\\"long\\"}]}", + "schemaType": "JSON", "subject": "test", "version": "1", }, @@ -50,6 +54,7 @@ Object { "compatibilityLevel": "BACKWARD", "id": 2, "schema": "{\\"type\\":\\"record\\",\\"name\\":\\"MyRecord2\\",\\"namespace\\":\\"com.mycompany\\",\\"fields\\":[{\\"name\\":\\"id\\",\\"type\\":\\"long\\"}]}", + "schemaType": "JSON", "subject": "test", "version": "2", }, @@ -67,6 +72,7 @@ Object { "compatibilityLevel": "BACKWARD", "id": 1, "schema": "{\\"type\\":\\"record\\",\\"name\\":\\"MyRecord1\\",\\"namespace\\":\\"com.mycompany\\",\\"fields\\":[{\\"name\\":\\"id\\",\\"type\\":\\"long\\"}]}", + "schemaType": "JSON", "subject": "test", "version": "1", }, diff --git a/kafka-ui-react-app/src/redux/reducers/schemas/__test__/fixtures.ts b/kafka-ui-react-app/src/redux/reducers/schemas/__test__/fixtures.ts index 5a75ed212bec3d01aab7f0d9ed71aa726cb0eaf4..a53f1dced7ad9c0db118ef88f2f3e413d8ed07df 100644 --- a/kafka-ui-react-app/src/redux/reducers/schemas/__test__/fixtures.ts +++ b/kafka-ui-react-app/src/redux/reducers/schemas/__test__/fixtures.ts @@ -1,5 +1,5 @@ import { SchemasState } from 'redux/interfaces'; -import { SchemaSubject } from 'generated-sources'; +import { SchemaSubject, SchemaType } from 'generated-sources'; export const initialState: SchemasState = { byName: {}, @@ -15,6 +15,7 @@ export const clusterSchemasPayload: SchemaSubject[] = [ schema: '{"type":"record","name":"MyRecord4","namespace":"com.mycompany","fields":[{"name":"id","type":"long"}]}', compatibilityLevel: 'BACKWARD', + schemaType: SchemaType.JSON, }, { subject: 'test3', @@ -23,6 +24,7 @@ export const clusterSchemasPayload: SchemaSubject[] = [ schema: '{"type":"record","name":"MyRecord","namespace":"com.mycompany","fields":[{"name":"id","type":"long"}]}', compatibilityLevel: 'BACKWARD', + schemaType: SchemaType.JSON, }, { subject: 'test', @@ -31,6 +33,7 @@ export const clusterSchemasPayload: SchemaSubject[] = [ schema: '{"type":"record","name":"MyRecord2","namespace":"com.mycompany","fields":[{"name":"id","type":"long"}]}', compatibilityLevel: 'BACKWARD', + schemaType: SchemaType.JSON, }, ]; @@ -42,6 +45,7 @@ export const schemaVersionsPayload: SchemaSubject[] = [ schema: '{"type":"record","name":"MyRecord1","namespace":"com.mycompany","fields":[{"name":"id","type":"long"}]}', compatibilityLevel: 'BACKWARD', + schemaType: SchemaType.JSON, }, { subject: 'test', @@ -50,6 +54,7 @@ export const schemaVersionsPayload: SchemaSubject[] = [ schema: '{"type":"record","name":"MyRecord2","namespace":"com.mycompany","fields":[{"name":"id","type":"long"}]}', compatibilityLevel: 'BACKWARD', + schemaType: SchemaType.JSON, }, ]; @@ -60,6 +65,7 @@ export const newSchemaPayload: SchemaSubject = { schema: '{"type":"record","name":"MyRecord4","namespace":"com.mycompany","fields":[{"name":"id","type":"long"}]}', compatibilityLevel: 'BACKWARD', + schemaType: SchemaType.JSON, }; export const clusterSchemasPayloadWithNewSchema: SchemaSubject[] = [ @@ -70,6 +76,7 @@ export const clusterSchemasPayloadWithNewSchema: SchemaSubject[] = [ schema: '{"type":"record","name":"MyRecord4","namespace":"com.mycompany","fields":[{"name":"id","type":"long"}]}', compatibilityLevel: 'BACKWARD', + schemaType: SchemaType.JSON, }, { subject: 'test3', @@ -78,6 +85,7 @@ export const clusterSchemasPayloadWithNewSchema: SchemaSubject[] = [ schema: '{"type":"record","name":"MyRecord","namespace":"com.mycompany","fields":[{"name":"id","type":"long"}]}', compatibilityLevel: 'BACKWARD', + schemaType: SchemaType.JSON, }, { subject: 'test', @@ -86,6 +94,7 @@ export const clusterSchemasPayloadWithNewSchema: SchemaSubject[] = [ schema: '{"type":"record","name":"MyRecord2","namespace":"com.mycompany","fields":[{"name":"id","type":"long"}]}', compatibilityLevel: 'BACKWARD', + schemaType: SchemaType.JSON, }, { subject: 'test4', @@ -94,5 +103,6 @@ export const clusterSchemasPayloadWithNewSchema: SchemaSubject[] = [ schema: '{"type":"record","name":"MyRecord4","namespace":"com.mycompany","fields":[{"name":"id","type":"long"}]}', compatibilityLevel: 'BACKWARD', + schemaType: SchemaType.JSON, }, ];