-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhost-mock.ts
143 lines (135 loc) · 4.83 KB
/
host-mock.ts
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* This file contains the callbacks that you can modify to test the display of your widget
*/
import { HostMock } from '@talentsoft-opensource/widget-display-tool/src/contracts/host-mock-contract'
import { HttpResponse, RequestOptions } from '@talentsoft-opensource/integration-widget-contract'
import { Status } from '../app/components/Search/Status';
import * as en from '../resources/en-gb.json';
import * as fr from '../resources/fr-fr.json';
import * as def from '../resources/default.json';
export const hostmock: HostMock = {
/**
* This flag controls the requestExternalResource behavior:
* - proxyMode: true => makes a real http request
* - proxyMode: false => calls the mocked version defined in this file
*/
proxyMode: false,
/**
* This setting controls the type of security headers
* used to authenticate a request:
* - securityMode: directconnect => (deprecated) adds the login and a token with the direct connect format
* - securityMode: jwtsharedsecret => adds a token in the jwt format
*/
securityMode: "jwtsharedsecret",
/**
* If proxyMode == true, when a direct connect request is made this secretkey will be used.
* It should be identical to the one configured in the remote service that will be accessed.
*/
secretKey: "5ysec",
/**
* If proxyMode == true, when a direct connect request is made this login will be used
*/
login: "mylogin",
getPreloadedResources: (language: string) => {
switch (language) {
case 'en-gb':
return en['labels'];
break;
case 'fr-fr':
return fr['labels'];
break;
default:
return def['labels'];
}
},
/**
* If proxyMode == false, this method is called instead of sending a request
*/
requestExternalResource: (options: RequestOptions) => {
const data = [
{
name: "My expense report",
amount: 100,
date: "12/12/2018",
description: "my expense for food",
status: Status.Validated
},
{
name: "My expense report 2",
amount: 20,
date: "02/02/2018",
description: "my expense for food 2",
status: Status.Validated
},
{
name: "My expense report 3",
amount: 30,
date: "03/03/2018",
description: "my expense for food during event",
status: Status.InProgress
},
{
name: "My expense report 4",
amount: 444,
date: "04/04/2019",
description: "my expense for driver in Paris",
status: Status.InProgress
},
{
name: "My expense report 4",
amount: 444,
date: "04/04/2019",
description: "my expense for driver in Paris",
status: Status.InProgress
},
{
name: "My expense report 4",
amount: 444,
date: "04/04/2019",
description: "my expense for driver in Paris",
status: Status.Canceled
},
{
name: "My expense report 4",
amount: 444,
date: "04/04/2019",
description: "my expense for driver in Paris",
status: Status.Canceled
},
{
name: "My expense report 4",
amount: 444,
date: "04/04/2019",
description: "my expense for driver in Paris",
status: Status.Canceled
},
];
return new Promise<HttpResponse>((resolve, reject) => {
const response: HttpResponse = {
body: JSON.stringify(data),
status: 200,
headers: {}
};
resolve(response);
});
},
/**
* This object is passed to the *params* prop in the widget.
* It may contain any property you need for the widget.
* In production, those properties are defined for each
* client but you may provide default values.
*/
configuration: {
domain:"https://www.exemple.com",
apikey:"AZERTY",
securitymode: "",
secretkey: ""
},
/**
* This function is called to generate the autoconnect url when using
* openUrlinNewTab or openUrlinCurrentTab
*/
getAutoConnectUrl(url: string): string {
return url;
}
}