mirror of
https://github.com/hay-kot/homebox.git
synced 2025-05-23 05:42:27 +00:00
end-to-end testing setup
This commit is contained in:
parent
b4eb7d8ddc
commit
ad4c8c9ab4
41 changed files with 544 additions and 313 deletions
|
@ -1,31 +1,28 @@
|
|||
export const prefix = '/api/v1';
|
||||
const parts = {
|
||||
host: 'http://localhost.com',
|
||||
prefix: '/api/v1',
|
||||
};
|
||||
|
||||
export type QueryValue =
|
||||
| string
|
||||
| string[]
|
||||
| number
|
||||
| number[]
|
||||
| boolean
|
||||
| null
|
||||
| undefined;
|
||||
|
||||
export function UrlBuilder(
|
||||
rest: string,
|
||||
params: Record<string, QueryValue> = {}
|
||||
): string {
|
||||
// we use a stub base URL to leverage the URL class
|
||||
const url = new URL(prefix + rest, 'http://localhost.com');
|
||||
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
if (Array.isArray(value)) {
|
||||
for (const item of value) {
|
||||
url.searchParams.append(key, String(item));
|
||||
}
|
||||
} else {
|
||||
url.searchParams.append(key, String(value));
|
||||
}
|
||||
}
|
||||
|
||||
// we return the path only, without the base URL
|
||||
return url.toString().replace('http://localhost.com', '');
|
||||
export function OverrideParts(host: string, prefix: string) {
|
||||
parts.host = host;
|
||||
parts.prefix = prefix;
|
||||
}
|
||||
|
||||
export type QueryValue = string | string[] | number | number[] | boolean | null | undefined;
|
||||
|
||||
export function UrlBuilder(rest: string, params: Record<string, QueryValue> = {}): string {
|
||||
const url = new URL(parts.prefix + rest, parts.host);
|
||||
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
if (Array.isArray(value)) {
|
||||
for (const item of value) {
|
||||
url.searchParams.append(key, String(item));
|
||||
}
|
||||
} else {
|
||||
url.searchParams.append(key, String(value));
|
||||
}
|
||||
}
|
||||
|
||||
// we return the path only, without the base URL
|
||||
return url.toString().replace('http://localhost.com', '');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue