[2/n]: Rest API -> TwentyORM migration POST rest/* (#9986)
# This PR - Addressing #3644 - Migrates the `POST rest/*` endpoint to use TwentyORM directly - Adds integration tests - Refactors common login in the v2 service file - Refactors test utility files
This commit is contained in:
@ -4,15 +4,23 @@ import request from 'supertest';
|
||||
|
||||
export type RestAPIRequestMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
||||
|
||||
export const makeRestAPIRequest = (
|
||||
method: RestAPIRequestMethod,
|
||||
path: string,
|
||||
headers: IncomingHttpHeaders = {},
|
||||
) => {
|
||||
interface RestAPIRequestParams {
|
||||
method: RestAPIRequestMethod;
|
||||
path: string;
|
||||
headers?: IncomingHttpHeaders;
|
||||
body?: any;
|
||||
}
|
||||
|
||||
export const makeRestAPIRequest = ({
|
||||
method,
|
||||
path,
|
||||
headers = {},
|
||||
body,
|
||||
}: RestAPIRequestParams) => {
|
||||
const client = request(`http://localhost:${APP_PORT}`);
|
||||
|
||||
return client[method]('/rest' + path)
|
||||
return client[method](`/rest${path}`)
|
||||
.set('Authorization', `Bearer ${ACCESS_TOKEN}`)
|
||||
.set({ ...headers })
|
||||
.send();
|
||||
.set(headers)
|
||||
.send(body ? JSON.stringify(body) : undefined);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user