Files
directus/tests/blackbox/utils/prepare-request.ts
Pascal Jufer 1ec1f98431 Bye-bye, Jest (#19886)
* Bye-bye, Jest

* Clean-up non-null assertions for PORT

* Test all vendors

* Consistent file names

* Try with MSSQL 2022

* Revert "Try with MSSQL 2022"

This reverts commit da807c6ec8.

* Try to run on Windows for better MSSQL perf

* Worth a try (hopefully runs MSSQL faster this way)

* Start docker services via bash

* Quick attempt with local installation of MSSQL

* Test with MSSQL 2019

* Back to ubuntu-latest for other tests

* Add typecheck cmd

* Revert "Test all vendors"

This reverts commit d6fbdd76c9.

* Use TS for Vitest config file

* Simplify vendors typecasting

---------

Co-authored-by: ian <licitdev@gmail.com>
2023-10-04 14:53:36 -04:00

27 lines
677 B
TypeScript

import { getUrl } from '@common/config';
import type { Vendor } from '@common/get-dbs-to-test';
import request from 'supertest';
export type AllowedRequestMethods = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'search';
export type RequestOptions = {
path: string;
method: AllowedRequestMethods;
token: string;
body?: any;
};
export const PrepareRequest = (vendor: Vendor, requestOptions: RequestOptions) => {
const req = request(getUrl(vendor))[requestOptions.method](requestOptions.path);
if (requestOptions.token) {
req.set('Authorization', `Bearer ${requestOptions.token}`);
}
if (requestOptions.body) {
req.send(requestOptions.body);
}
return req;
};