2022-10-11 15:29:23 +02:00
|
|
|
import { requestHeaders } from './apiauth';
|
2023-02-15 02:52:11 +01:00
|
|
|
import { API, Entity, SearchResult, Token } from './types';
|
2022-10-11 15:29:23 +02:00
|
|
|
|
|
|
|
export function searchSomething(
|
2023-02-15 02:52:11 +01:00
|
|
|
token: Token,
|
2022-10-11 15:29:23 +02:00
|
|
|
searchPath: string,
|
|
|
|
method: string,
|
|
|
|
mapResult: (body: any) => SearchResult,
|
2023-02-15 02:52:11 +01:00
|
|
|
orgId?: string,
|
2022-10-11 15:29:23 +02:00
|
|
|
): Cypress.Chainable<SearchResult> {
|
|
|
|
return cy
|
|
|
|
.request({
|
|
|
|
method: method,
|
|
|
|
url: searchPath,
|
2023-02-15 02:52:11 +01:00
|
|
|
headers: requestHeaders(token, orgId),
|
2022-10-11 15:29:23 +02:00
|
|
|
failOnStatusCode: method == 'POST',
|
|
|
|
})
|
|
|
|
.then((res) => {
|
|
|
|
return mapResult(res.body);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function findFromList(find: (entity: Entity) => boolean, idField: string = 'id'): (body: any) => SearchResult {
|
|
|
|
return (b) => {
|
|
|
|
const entity = b.result?.find(find);
|
|
|
|
return {
|
|
|
|
entity: entity,
|
|
|
|
sequence: parseInt(<string>b.details.processedSequence),
|
|
|
|
id: entity?.[idField],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|