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 7871bb5588..32a8b9d34a 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 019532251b..d53190c9f6 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 1783cdc994..e26acad840 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 7b337a23ec..46a4d5a105 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 cc15b9709e..7a1325b924 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 d8e4a59804..663dbaaafc 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 0cb4267511..611b8ad174 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 f650d011bf..31222ebb09 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 bf18ffa14f..61332659b7 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 5a75ed212b..a53f1dced7 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, }, ];