[ISSUE-200] Update FE to support new version of api

This commit is contained in:
Oleg Shuralev 2021-03-05 17:09:17 +03:00
parent 7f15bf1c0b
commit b417603eca
No known key found for this signature in database
GPG key ID: 99C6BDC0A1C2E647
10 changed files with 54 additions and 27 deletions

View file

@ -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",
}

View file

@ -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,
},
];

View file

@ -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",
}

View file

@ -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,
},
];

View file

@ -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<NewProps> = ({ 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

View file

@ -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,
};

View file

@ -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(),
]);
});
});
});

View file

@ -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;
}
};

View file

@ -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",
},

View file

@ -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,
},
];