Skip to content

Commit

Permalink
2659 cli improvements migrate tests to resource manager architecture …
Browse files Browse the repository at this point in the history
…get tests frontend (#2702)

chore(frontend): updating FE to support GET /tests endpoint changes
  • Loading branch information
xoscar authored and mathnogueira committed Jun 26, 2023
1 parent 347b544 commit 449b37a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 20 deletions.
2 changes: 1 addition & 1 deletion web/src/models/Resource.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function Resource({item, type}: TRawResource): Resource {
if (type === ResourceType.Test) {
return {
type: ResourceType.Test,
item: Test(item as TRawTest),
item: Test.FromRawTest(item as TRawTest),
};
}

Expand Down
6 changes: 5 additions & 1 deletion web/src/models/Test.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import TestSpecs from './TestSpecs.model';
import Summary from './Summary.model';
import Trigger from './Trigger.model';

export type TRawTestResource = TTestSchemas['TestResource'];
export type TRawTestResourceList = TTestSchemas['TestResourceList'];
export type TRawTest = TTestSchemas['Test'];
type Test = Model<
TRawTest,
Expand All @@ -18,7 +20,9 @@ type Test = Model<
}
>;

const Test = ({
const Test = ({spec: rawTest = {}}: TRawTestResource): Test => Test.FromRawTest(rawTest);

Test.FromRawTest = ({
id = '',
name = '',
description = '',
Expand Down
6 changes: 2 additions & 4 deletions web/src/models/Transaction.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ type Transaction = Model<
}
>;

function Transaction({
spec: rawTransaction = {},
}: TRawTransactionResource): Transaction {
function Transaction({spec: rawTransaction = {}}: TRawTransactionResource): Transaction {
return Transaction.FromRawTransaction(rawTransaction);
}

Expand All @@ -35,7 +33,7 @@ Transaction.FromRawTransaction = ({
description,
version,
steps,
fullSteps: fullSteps.map(step => Test(step)),
fullSteps: fullSteps.map(step => Test.FromRawTest(step)),
createdAt,
summary: Summary(summary),
};
Expand Down
2 changes: 1 addition & 1 deletion web/src/models/__mocks__/Test.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const TestMock: IMockFactory<Test, TRawTest> = () => ({
};
},
model(data = {}) {
return Test(this.raw(data));
return Test.FromRawTest(this.raw(data));
},
});

Expand Down
15 changes: 7 additions & 8 deletions web/src/redux/apis/endpoints/Test.endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {HTTP_METHOD} from 'constants/Common.constants';
import {SortBy, SortDirection, TracetestApiTags} from 'constants/Test.constants';
import Test, {TRawTest} from 'models/Test.model';
import Test, {TRawTest, TRawTestResourceList} from 'models/Test.model';
import {PaginationResponse} from 'hooks/usePagination';
import {TTestApiEndpointBuilder} from 'types/Test.types';
import {getTotalCountFromHeaders} from 'utils/Common';

const TestEndpoint = (builder: TTestApiEndpointBuilder) => ({
createTest: builder.mutation<Test, TRawTest>({
Expand All @@ -12,7 +11,7 @@ const TestEndpoint = (builder: TTestApiEndpointBuilder) => ({
method: HTTP_METHOD.POST,
body: newTest,
}),
transformResponse: (rawTest: TRawTest) => Test(rawTest),
transformResponse: (rawTest: TRawTest) => Test.FromRawTest(rawTest),
invalidatesTags: [
{type: TracetestApiTags.TEST, id: 'LIST'},
{type: TracetestApiTags.RESOURCE, id: 'LIST'},
Expand All @@ -37,22 +36,22 @@ const TestEndpoint = (builder: TTestApiEndpointBuilder) => ({
query: ({take = 25, skip = 0, query = '', sortBy = '', sortDirection = ''}) =>
`/tests?take=${take}&skip=${skip}&query=${query}&sortBy=${sortBy}&sortDirection=${sortDirection}`,
providesTags: () => [{type: TracetestApiTags.TEST, id: 'LIST'}],
transformResponse: (rawTestList: TRawTest[], meta) => {
transformResponse: ({items = [], count = 0}: TRawTestResourceList) => {
return {
items: rawTestList.map(rawTest => Test(rawTest)),
total: getTotalCountFromHeaders(meta),
items: items.map(rawTest => Test(rawTest)),
total: count,
};
},
}),
getTestById: builder.query<Test, {testId: string}>({
query: ({testId}) => `/tests/${testId}`,
providesTags: result => [{type: TracetestApiTags.TEST, id: result?.id}],
transformResponse: (rawTest: TRawTest) => Test(rawTest),
transformResponse: (rawTest: TRawTest) => Test.FromRawTest(rawTest),
}),
getTestVersionById: builder.query<Test, {testId: string; version: number}>({
query: ({testId, version}) => `/tests/${testId}/version/${version}`,
providesTags: result => [{type: TracetestApiTags.TEST, id: result?.id}],
transformResponse: (rawTest: TRawTest) => Test(rawTest),
transformResponse: (rawTest: TRawTest) => Test.FromRawTest(rawTest),
keepUnusedDataFor: 10,
}),
deleteTestById: builder.mutation<Test, {testId: string}>({
Expand Down
27 changes: 22 additions & 5 deletions web/src/types/Generated.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,14 +434,13 @@ export interface operations {
responses: {
/** successful operation */
200: {
headers: {
/** Total records count */
"X-Total-Count"?: number;
};
content: {
"application/json": external["tests.yaml"]["components"]["schemas"]["Test"][];
"application/json": external["tests.yaml"]["components"]["schemas"]["TestResourceList"];
"text/yaml": external["tests.yaml"]["components"]["schemas"]["TestResourceList"];
};
};
/** invalid query for test, some data was sent in incorrect format. */
400: unknown;
/** problem with getting tests */
500: unknown;
};
Expand Down Expand Up @@ -1790,6 +1789,19 @@ export interface external {
paths: {};
components: {
schemas: {
TestResourceList: {
count?: number;
items?: external["tests.yaml"]["components"]["schemas"]["TestResource"][];
};
/** @description Represents a test structured into the Resources format. */
TestResource: {
/**
* @description Represents the type of this resource. It should always be set as 'Test'.
* @enum {string}
*/
type?: "Test";
spec?: external["tests.yaml"]["components"]["schemas"]["Test"];
};
Test: {
id?: string;
name?: string;
Expand All @@ -1799,6 +1811,7 @@ export interface external {
/** Format: date-time */
createdAt?: string;
serviceUnderTest?: external["triggers.yaml"]["components"]["schemas"]["Trigger"];
trigger?: external["triggers.yaml"]["components"]["schemas"]["Trigger"];
/** @description specification of assertions that are going to be made */
specs?: external["tests.yaml"]["components"]["schemas"]["TestSpec"][];
/**
Expand Down Expand Up @@ -2057,6 +2070,8 @@ export interface external {
components: {
schemas: {
Trigger: {
/** @enum {string} */
type?: "http" | "grpc" | "traceid";
/** @enum {string} */
triggerType?: "http" | "grpc" | "traceid";
http?: external["http.yaml"]["components"]["schemas"]["HTTPRequest"];
Expand All @@ -2066,6 +2081,8 @@ export interface external {
TriggerResult: {
/** @enum {string} */
triggerType?: "http" | "grpc" | "traceid";
/** @enum {string} */
type?: "http" | "grpc" | "traceid";
triggerResult?: {
http?: external["http.yaml"]["components"]["schemas"]["HTTPResponse"];
grpc?: external["grpc.yaml"]["components"]["schemas"]["GRPCResponse"];
Expand Down

0 comments on commit 449b37a

Please sign in to comment.