Created: - Services - Resolvers - Controllers - Tests for services - Integration tests for GraphQL and Rest Updated the Rest API playground Added new feature flag `IS_CORE_VIEW_ENABLED` Updated `viewFilter` `operand` and `view` `type` to be enums rather than strings and generated migration file. Closes https://github.com/twentyhq/core-team-issues/issues/1259 --------- Co-authored-by: Félix Malfait <felix.malfait@gmail.com> Co-authored-by: Charles Bochet <charles@twenty.com>
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import {
|
|
BaseGraphQLError,
|
|
ErrorCode,
|
|
} from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
|
|
|
|
export interface GraphQLResponse<T extends Record<string, unknown>> {
|
|
status: number;
|
|
body: {
|
|
data?: T;
|
|
errors?: BaseGraphQLError[];
|
|
};
|
|
}
|
|
|
|
export const assertGraphQLSuccessfulResponse = <
|
|
T extends Record<string, unknown>,
|
|
>(
|
|
response: GraphQLResponse<T>,
|
|
expectedData?: Partial<T>,
|
|
) => {
|
|
expect(response.status).toBe(200);
|
|
expect(response.body.data).toBeDefined();
|
|
expect(response.body.errors).toBeUndefined();
|
|
|
|
if (expectedData) {
|
|
expect(response.body.data).toMatchObject(expectedData);
|
|
}
|
|
};
|
|
|
|
export const assertGraphQLErrorResponse = <T extends Record<string, unknown>>(
|
|
response: GraphQLResponse<T>,
|
|
expectedErrorCode: ErrorCode,
|
|
expectedErrorMessage?: string,
|
|
) => {
|
|
expect(response.status).toBe(200);
|
|
expect(response.body.errors).toBeDefined();
|
|
expect(response.body.errors).toHaveLength(1);
|
|
|
|
if (expectedErrorCode && response.body.errors) {
|
|
expect(response.body.errors[0].extensions.code).toBe(expectedErrorCode);
|
|
}
|
|
|
|
if (expectedErrorMessage && response.body.errors) {
|
|
expect(response.body.errors[0].message).toBe(expectedErrorMessage);
|
|
}
|
|
};
|