-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrequestHelpers.ts
More file actions
33 lines (29 loc) · 920 Bytes
/
requestHelpers.ts
File metadata and controls
33 lines (29 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { MockContextParams } from "../../../../types/internal";
const requestHelpers = (params: MockContextParams) => {
const helpers = {
urlParams: (param: string) => {
return params.urlParams[param]
},
method: () => params.method,
statusCode: () => params.statusCode,
header: (param: string, defaultValue: string = '') => {
// handlebars passes object when no value is passed
// {
// lookupProperty: [Function: lookupProperty],
// name: 'header',
// hash: {},
// data: { root: [Object] },
// loc: { start: [Object], end: [Object] }
// }
if(typeof defaultValue === 'object') {
defaultValue = '';
}
if(typeof param === 'object') {
return defaultValue
}
return params.headers[param?.toLowerCase()] || defaultValue;
},
};
return helpers;
};
export default requestHelpers;