resolves #14190 added refreshCoreViews() call after object creation to immediately update core views state, ensuring new objects appear in the navigation drawer without requiring a refresh --------- Co-authored-by: Charles Bochet <charles@twenty.com> Co-authored-by: prastoin <paul@twenty.com>
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
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);
|
|
}
|
|
};
|
|
|
|
export const assertRestApiErrorNotFoundResponse = (
|
|
response: RestResponse<{ statusCode: number; messages: [] }>,
|
|
expectedStatus = 404,
|
|
expectedErrorMessage?: string,
|
|
) => {
|
|
expect(response.status).toBe(expectedStatus);
|
|
expect(response.body.statusCode).toBe(expectedStatus);
|
|
|
|
if (expectedErrorMessage && response.body.message) {
|
|
expect(response.body.message).toContain(expectedErrorMessage);
|
|
}
|
|
};
|