-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhost-mock.ts
103 lines (97 loc) · 3.35 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
/**
* 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/host/mock-definitions'
import { HttpResponse, RequestOptions } from '@talentsoft-opensource/integration-widget-contract'
import { ExpenseStatus } from '../app/expense-status';
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,
/**
* 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: "mysec",
/**
* If proxyMode == true, when a direct connect request is made this login will be used
*/
login: "mylogin",
/**
* If proxyMode == false, this method is called instead of sending a request
*/
requestExternalResource: (options: RequestOptions) => {
let data: any[];
if (options.url.indexOf('enlarged') == -1) {
data = [
{
id: 'ToDo',
y: 12,
z: 2458
},
{
id: 'InProgress',
y: 5,
z: 3874
},
{
id: 'ToValidate',
y: 7,
z: 2375
},
{
id: 'Validated',
y: 18,
z: 129
},
];
} else {
data = [
{
object: 'Formation React JS',
type: 'Frais de déplacements',
state: ExpenseStatus.Validated,
amount: '0,00 €'
},
{
object: 'Workshop',
type: 'Frais de déplacements',
state: ExpenseStatus.Pending,
amount: '13,20 €'
},
{
object: 'Tickets resto',
type: 'Tickets resto',
state: ExpenseStatus.WaitingForValidation,
amount: '4,50 €'
},
{
object: 'Rdv client avant vente',
type: 'Frais de déplacements',
state: ExpenseStatus.WaitingForValidation,
amount: '47,00 €'
}
];
}
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: {
foo: "bar"
},
}