2022-10-11 13:29:23 +00:00
|
|
|
import { requestHeaders } from './apiauth';
|
2023-02-15 01:52:11 +00:00
|
|
|
import { API, Entity, SearchResult, Token } from './types';
|
2022-10-11 13:29:23 +00:00
|
|
|
|
|
|
|
export function searchSomething(
|
2023-02-15 01:52:11 +00:00
|
|
|
token: Token,
|
2022-10-11 13:29:23 +00:00
|
|
|
searchPath: string,
|
|
|
|
method: string,
|
|
|
|
mapResult: (body: any) => SearchResult,
|
2023-02-15 01:52:11 +00:00
|
|
|
orgId?: string,
|
2022-10-11 13:29:23 +00:00
|
|
|
): Cypress.Chainable<SearchResult> {
|
|
|
|
return cy
|
|
|
|
.request({
|
|
|
|
method: method,
|
|
|
|
url: searchPath,
|
2023-02-15 01:52:11 +00:00
|
|
|
headers: requestHeaders(token, orgId),
|
2022-10-11 13:29:23 +00: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],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|