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>
35 lines
940 B
TypeScript
35 lines
940 B
TypeScript
export interface RestResponse<T = Record<string, unknown>> {
|
|
status: number;
|
|
body: T & {
|
|
error?: string;
|
|
errors?: string[] | Record<string, unknown>[];
|
|
message?: string;
|
|
};
|
|
}
|
|
|
|
export const assertRestApiSuccessfulResponse = <T = Record<string, unknown>>(
|
|
response: RestResponse<T>,
|
|
expectedStatus = 200,
|
|
) => {
|
|
expect(response.status).toBe(expectedStatus);
|
|
expect(response.body).toBeDefined();
|
|
|
|
if (response.body.error || response.body.errors) {
|
|
throw new Error(
|
|
`Expected successful response but got errors: ${JSON.stringify(response.body)}`,
|
|
);
|
|
}
|
|
};
|
|
|
|
export const assertRestApiErrorResponse = <T = Record<string, unknown>>(
|
|
response: RestResponse<T>,
|
|
expectedStatus = 400,
|
|
expectedErrorMessage?: string,
|
|
) => {
|
|
expect(response.status).toBe(expectedStatus);
|
|
|
|
if (expectedErrorMessage && response.body.message) {
|
|
expect(response.body.message).toContain(expectedErrorMessage);
|
|
}
|
|
};
|