Common api - Add field create input validation integration testing (#15026)
closes https://github.com/twentyhq/core-team-issues/issues/1624
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
import { createOneOperationFactory } from 'test/integration/graphql/utils/create-one-operation-factory.util';
|
||||
import { makeGraphqlAPIRequestWithApiKey } from 'test/integration/graphql/utils/make-graphql-api-request-with-api-key.util';
|
||||
|
||||
export const expectGqlCreateInputValidationError = async (
|
||||
objectMetadataSingularName: string,
|
||||
input: any,
|
||||
) => {
|
||||
const createManyGraphqlOperation = createOneOperationFactory({
|
||||
objectMetadataSingularName: objectMetadataSingularName,
|
||||
gqlFields: 'id',
|
||||
data: input,
|
||||
});
|
||||
|
||||
const createManyResponse = await makeGraphqlAPIRequestWithApiKey(
|
||||
createManyGraphqlOperation,
|
||||
);
|
||||
|
||||
expect(createManyResponse.body.errors).toBeDefined();
|
||||
expect(createManyResponse.body.errors[0].message).toMatchSnapshot();
|
||||
};
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
import { TEST_OBJECT_GQL_FIELDS } from 'test/integration/graphql/suites/inputs-validation/constants/test-object-gql-fields.constant';
|
||||
import { createOneOperationFactory } from 'test/integration/graphql/utils/create-one-operation-factory.util';
|
||||
import { makeGraphqlAPIRequestWithApiKey } from 'test/integration/graphql/utils/make-graphql-api-request-with-api-key.util';
|
||||
|
||||
import { pascalCase } from 'src/utils/pascal-case';
|
||||
|
||||
export const expectGqlCreateInputValidationSuccess = async (
|
||||
objectMetadataSingularName: string,
|
||||
input: any,
|
||||
validateInput: (record: Record<string, any>) => boolean,
|
||||
) => {
|
||||
const createOneOperation = createOneOperationFactory({
|
||||
objectMetadataSingularName: objectMetadataSingularName,
|
||||
gqlFields: TEST_OBJECT_GQL_FIELDS,
|
||||
data: input,
|
||||
});
|
||||
|
||||
const createOneResponse =
|
||||
await makeGraphqlAPIRequestWithApiKey(createOneOperation);
|
||||
|
||||
expect(createOneResponse.body.errors).toBeUndefined();
|
||||
expect(createOneResponse.body.data).toBeDefined();
|
||||
expect(
|
||||
validateInput(
|
||||
createOneResponse.body.data[
|
||||
`create${pascalCase(objectMetadataSingularName)}`
|
||||
],
|
||||
),
|
||||
).toBe(true);
|
||||
};
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import { makeRestAPIRequest } from 'test/integration/rest/utils/make-rest-api-request.util';
|
||||
|
||||
export const expectRestCreateInputValidationError = async (
|
||||
objectMetadataPluralName: string,
|
||||
input: any,
|
||||
) => {
|
||||
const response = await makeRestAPIRequest({
|
||||
method: 'post',
|
||||
path: `/${objectMetadataPluralName}`,
|
||||
body: input,
|
||||
});
|
||||
|
||||
expect(response.body.error).toBeDefined();
|
||||
expect(JSON.stringify(response.body.messages)).toMatchSnapshot();
|
||||
};
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import { makeRestAPIRequest } from 'test/integration/rest/utils/make-rest-api-request.util';
|
||||
|
||||
import { pascalCase } from 'src/utils/pascal-case';
|
||||
|
||||
export const expectRestCreateInputValidationSuccess = async (
|
||||
objectMetadataPluralName: string,
|
||||
objectMetadataSingularName: string,
|
||||
input: any,
|
||||
validateInput: (record: Record<string, any>) => boolean,
|
||||
) => {
|
||||
const response = await makeRestAPIRequest({
|
||||
method: 'post',
|
||||
path: `/${objectMetadataPluralName}`,
|
||||
body: input,
|
||||
});
|
||||
|
||||
const records =
|
||||
response.body.data[`create${pascalCase(objectMetadataSingularName)}`];
|
||||
|
||||
expect(response.body.error).toBeUndefined();
|
||||
expect(validateInput(records)).toBe(true);
|
||||
};
|
||||
Reference in New Issue
Block a user