emissions-api-sdk 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -26
- package/dist/Constants.js +6 -23
- package/dist/api/Calculation.js +0 -63
- package/dist/api/EconomicActivity.js +40 -0
- package/dist/api/Factor.js +0 -82
- package/dist/api/Fugitive.js +0 -63
- package/dist/api/Location.js +0 -61
- package/dist/api/Metadata.js +155 -0
- package/dist/api/Mobile.js +0 -64
- package/dist/api/RealEstate.js +40 -0
- package/dist/api/Stationary.js +0 -63
- package/dist/api/TransportationAndDistribution.js +0 -63
- package/dist/coverage/clover.xml +144 -199
- package/dist/coverage/coverage-final.json +14 -11
- package/dist/coverage/lcov-report/index.html +20 -20
- package/dist/coverage/lcov-report/src/Client.ts.html +28 -28
- package/dist/coverage/lcov-report/src/Constants.ts.html +31 -88
- package/dist/coverage/lcov-report/src/api/Calculation.ts.html +7 -217
- package/dist/coverage/lcov-report/src/api/EconomicActivity.ts.html +220 -0
- package/dist/coverage/lcov-report/src/api/Factor.ts.html +6 -285
- package/dist/coverage/lcov-report/src/api/FactorSets.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Fugitive.ts.html +7 -223
- package/dist/coverage/lcov-report/src/api/Location.ts.html +6 -222
- package/dist/coverage/lcov-report/src/api/Metadata.ts.html +604 -0
- package/dist/coverage/lcov-report/src/api/Mobile.ts.html +6 -231
- package/dist/coverage/lcov-report/src/api/RealEstate.ts.html +217 -0
- package/dist/coverage/lcov-report/src/api/Stationary.ts.html +6 -225
- package/dist/coverage/lcov-report/src/api/TransportationAndDistribution.ts.html +7 -223
- package/dist/coverage/lcov-report/src/api/Usage.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/index.html +72 -27
- package/dist/coverage/lcov-report/src/index.html +7 -7
- package/dist/coverage/lcov-report/src/request.ts.html +5 -5
- package/dist/coverage/lcov-report/src/utils.ts.html +6 -6
- package/dist/coverage/lcov-report/test/index.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/CommonRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/FactorRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/GenericCalculationRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/LocationRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/SearchRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/index.html +1 -1
- package/dist/coverage/lcov-report/test/testUtils.ts.html +1 -1
- package/dist/coverage/lcov.info +241 -294
- package/dist/index.js +4 -1
- package/dist/types/Constants.d.ts +5 -22
- package/dist/types/api/Calculation.d.ts +0 -41
- package/dist/types/api/EconomicActivity.d.ts +29 -0
- package/dist/types/api/Factor.d.ts +0 -52
- package/dist/types/api/Fugitive.d.ts +0 -41
- package/dist/types/api/Location.d.ts +0 -39
- package/dist/types/api/Metadata.d.ts +99 -0
- package/dist/types/api/Mobile.d.ts +0 -42
- package/dist/types/api/RealEstate.d.ts +29 -0
- package/dist/types/api/Stationary.d.ts +0 -41
- package/dist/types/api/TransportationAndDistribution.d.ts +0 -41
- package/dist/types/index.d.ts +3 -0
- package/dist/types/interfaces/response/FactorResponse.d.ts +0 -4
- package/docs/_sources/index.rst.txt +8 -6
- package/docs/_sources/reference.rst.txt +17 -37
- package/docs/_static/basic.css +8 -0
- package/docs/_static/pygments.css +146 -164
- package/docs/_static/searchtools.js +5 -8
- package/docs/_static/styles/furo.css +1 -1
- package/docs/_static/styles/furo.css.map +1 -1
- package/docs/authentication.html +28 -19
- package/docs/client.html +28 -19
- package/docs/genindex.html +56 -71
- package/docs/getting_started.html +28 -19
- package/docs/index.html +31 -20
- package/docs/objects.inv +0 -0
- package/docs/reference.html +151 -357
- package/docs/sdk.html +28 -19
- package/docs/search.html +28 -19
- package/docs/searchindex.js +1 -1
- package/docs/troubleshooting.html +28 -19
- package/package.json +7 -2
- package/sphinx-build/source/index.rst +8 -6
- package/sphinx-build/source/reference.rst +17 -37
- package/src/Constants.ts +6 -25
- package/src/api/Calculation.ts +1 -72
- package/src/api/EconomicActivity.ts +45 -0
- package/src/api/Factor.ts +1 -94
- package/src/api/Fugitive.ts +1 -74
- package/src/api/Location.ts +1 -73
- package/src/api/Metadata.ts +174 -0
- package/src/api/Mobile.ts +1 -76
- package/src/api/RealEstate.ts +45 -0
- package/src/api/Stationary.ts +1 -74
- package/src/api/TransportationAndDistribution.ts +1 -74
- package/src/index.ts +3 -0
- package/src/interfaces/response/FactorResponse.ts +0 -7
- package/test/apiTest.test.ts +19 -162
- package/test/metadata.test.ts +224 -0
- package/test/request.test.ts +0 -1
package/test/apiTest.test.ts
CHANGED
|
@@ -5,6 +5,8 @@ import * as mobileApi from "../src/api/Mobile";
|
|
|
5
5
|
import * as stationaryApi from "../src/api/Stationary";
|
|
6
6
|
import * as GenericCalculation from "../src/api/Calculation";
|
|
7
7
|
import * as TransportationDistributionApi from "../src/api/TransportationAndDistribution";
|
|
8
|
+
import * as economicActivityApi from "../src/api/EconomicActivity";
|
|
9
|
+
import * as realEstateApi from "../src/api/RealEstate";
|
|
8
10
|
import * as UsageApi from "../src/api/Usage";
|
|
9
11
|
import * as Factors from "../src/api/Factor";
|
|
10
12
|
import * as FactorSets from "../src/api/FactorSets";
|
|
@@ -19,29 +21,9 @@ import {
|
|
|
19
21
|
FACTOR_API_PATH,
|
|
20
22
|
FACTOR_SET_API_PATH,
|
|
21
23
|
SEARCH_API_PATH,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
STATIONARY_API_TYPES,
|
|
26
|
-
CALCULATION_TYPES,
|
|
27
|
-
FACTOR_API_TYPES,
|
|
28
|
-
TRANSPORTATION_AND_DISTRIBUTION_API_TYPES,
|
|
29
|
-
LOCATION_API_AREA,
|
|
30
|
-
FUGITIVE_API_AREA,
|
|
31
|
-
MOBILE_API_AREA,
|
|
32
|
-
STATIONARY_API_AREA,
|
|
33
|
-
GENERAL_API_AREA,
|
|
34
|
-
FACTOR_API_AREA,
|
|
35
|
-
TRANSPORTATION_AND_DISTRIBUTION_API_AREA,
|
|
36
|
-
LOCATION_API_UNITS,
|
|
37
|
-
SEARCH_API_AREA,
|
|
38
|
-
FUGITIVE_API_UNITS,
|
|
39
|
-
MOBILE_API_UNITS,
|
|
40
|
-
STATIONARY_API_UNITS,
|
|
41
|
-
GENERAL_API_UNITS,
|
|
42
|
-
FACTOR_API_UNITS,
|
|
43
|
-
TRANSPORTATION_AND_DISTRIBUTION_API_UNITS,
|
|
44
|
-
USAGE_API
|
|
24
|
+
USAGE_API,
|
|
25
|
+
ECONOMIC_ACTIVITY_API_PATH,
|
|
26
|
+
REAL_ESTATE_API_PATH,
|
|
45
27
|
} from "../src/Constants";
|
|
46
28
|
import locationPayload from "./mocks/LocationRequest";
|
|
47
29
|
import commonpayload from "./mocks/CommonRequest";
|
|
@@ -112,6 +94,20 @@ const testCases: ApiTestCase[] = [
|
|
|
112
94
|
payload: GenericCalculationPayload,
|
|
113
95
|
method: "POST",
|
|
114
96
|
},
|
|
97
|
+
{
|
|
98
|
+
name: "Economic activity API",
|
|
99
|
+
func: economicActivityApi.calculate,
|
|
100
|
+
path: ECONOMIC_ACTIVITY_API_PATH,
|
|
101
|
+
payload: commonpayload,
|
|
102
|
+
method: "POST",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: "Real estate API",
|
|
106
|
+
func: realEstateApi.calculate,
|
|
107
|
+
path: REAL_ESTATE_API_PATH,
|
|
108
|
+
payload: commonpayload,
|
|
109
|
+
method: "POST",
|
|
110
|
+
},
|
|
115
111
|
{
|
|
116
112
|
name: "FactorSet API",
|
|
117
113
|
func: FactorSets.get,
|
|
@@ -125,145 +121,6 @@ const testCases: ApiTestCase[] = [
|
|
|
125
121
|
payload: SearchPayload,
|
|
126
122
|
method: "POST",
|
|
127
123
|
},
|
|
128
|
-
{
|
|
129
|
-
name: "Location API - getTypes",
|
|
130
|
-
func: locationApi.getTypes,
|
|
131
|
-
path: LOCATION_TYPES,
|
|
132
|
-
method: "GET",
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
name: "Fugitive API - getTypes",
|
|
136
|
-
func: fugitiveApi.getTypes,
|
|
137
|
-
path: FUGITIVE_API_TYPES,
|
|
138
|
-
method: "GET",
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
name: "Mobile API - getTypes",
|
|
142
|
-
func: mobileApi.getTypes,
|
|
143
|
-
path: MOBILE_API_TYPES,
|
|
144
|
-
method: "GET",
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
name: "Stationary API - getTypes",
|
|
148
|
-
func: stationaryApi.getTypes,
|
|
149
|
-
path: STATIONARY_API_TYPES,
|
|
150
|
-
method: "GET",
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
name: "GenericCalculation API - getTypes",
|
|
154
|
-
func: GenericCalculation.getTypes,
|
|
155
|
-
path: CALCULATION_TYPES,
|
|
156
|
-
method: "GET",
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
name: "Factor API - getTypes",
|
|
160
|
-
func: Factors.getTypes,
|
|
161
|
-
path: FACTOR_API_TYPES,
|
|
162
|
-
method: "GET",
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
name: "Transportation and Distribution API - getTypes",
|
|
166
|
-
func: TransportationDistributionApi.getTypes,
|
|
167
|
-
path: TRANSPORTATION_AND_DISTRIBUTION_API_TYPES,
|
|
168
|
-
method: "GET",
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
name: "Location API - getArea",
|
|
172
|
-
func: locationApi.getArea,
|
|
173
|
-
path: LOCATION_API_AREA,
|
|
174
|
-
method: "GET",
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
name: "Fugitive API - getArea",
|
|
178
|
-
func: fugitiveApi.getArea,
|
|
179
|
-
path: FUGITIVE_API_AREA,
|
|
180
|
-
method: "GET",
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
name: "Mobile API - getArea",
|
|
184
|
-
func: mobileApi.getArea,
|
|
185
|
-
path: MOBILE_API_AREA,
|
|
186
|
-
method: "GET",
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
name: "Stationary API - getArea",
|
|
190
|
-
func: stationaryApi.getArea,
|
|
191
|
-
path: STATIONARY_API_AREA,
|
|
192
|
-
method: "GET",
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
name: "GenericCalculation API - getArea",
|
|
196
|
-
func: GenericCalculation.getArea,
|
|
197
|
-
path: GENERAL_API_AREA,
|
|
198
|
-
method: "GET",
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
name: "Factor API - getArea",
|
|
202
|
-
func: Factors.getArea,
|
|
203
|
-
path: FACTOR_API_AREA,
|
|
204
|
-
method: "GET",
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
name: "Factor SEARCH API - getArea",
|
|
208
|
-
func: Factors.getSearchArea,
|
|
209
|
-
path: SEARCH_API_AREA,
|
|
210
|
-
method: "GET",
|
|
211
|
-
},
|
|
212
|
-
{
|
|
213
|
-
name: "Transportation and Distribution API - getArea",
|
|
214
|
-
func: TransportationDistributionApi.getArea,
|
|
215
|
-
path: TRANSPORTATION_AND_DISTRIBUTION_API_AREA,
|
|
216
|
-
method: "GET",
|
|
217
|
-
},
|
|
218
|
-
{
|
|
219
|
-
name: "Location API - getUnits",
|
|
220
|
-
func: locationApi.getUnits,
|
|
221
|
-
path: LOCATION_API_UNITS,
|
|
222
|
-
queryParams: { type: "electricity" },
|
|
223
|
-
method: "GET",
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
name: "Fugitive API - getUnits",
|
|
227
|
-
func: fugitiveApi.getUnits,
|
|
228
|
-
path: FUGITIVE_API_UNITS,
|
|
229
|
-
queryParams: { type: "Natural Gas - Scope 3:AAA" },
|
|
230
|
-
method: "GET",
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
name: "Mobile API - getUnits",
|
|
234
|
-
func: mobileApi.getUnits,
|
|
235
|
-
path: MOBILE_API_UNITS,
|
|
236
|
-
queryParams: { type: "Cars:B20:(NE)" },
|
|
237
|
-
method: "GET",
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
name: "Stationary API - getUnits",
|
|
241
|
-
func: stationaryApi.getUnits,
|
|
242
|
-
path: STATIONARY_API_UNITS,
|
|
243
|
-
queryParams: { type: "Jet Kerosene" },
|
|
244
|
-
method: "GET",
|
|
245
|
-
},
|
|
246
|
-
{
|
|
247
|
-
name: "GenericCalculation API - getUnits",
|
|
248
|
-
func: GenericCalculation.getUnits,
|
|
249
|
-
path: GENERAL_API_UNITS,
|
|
250
|
-
queryParams: { type: "Natural Gas - Scope 3:AAA" },
|
|
251
|
-
method: "GET",
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
name: "Factor API - getUnits",
|
|
255
|
-
func: Factors.getUnits,
|
|
256
|
-
path: FACTOR_API_UNITS,
|
|
257
|
-
queryParams: { type: "HFC-263fb" },
|
|
258
|
-
method: "GET",
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
name: "Transportation and Distribution API - getUnits",
|
|
262
|
-
func: TransportationDistributionApi.getUnits,
|
|
263
|
-
path: TRANSPORTATION_AND_DISTRIBUTION_API_UNITS,
|
|
264
|
-
queryParams: { type: "Business Travel - Cars:Diesel - Small" },
|
|
265
|
-
method: "GET",
|
|
266
|
-
},
|
|
267
124
|
{
|
|
268
125
|
name: "Usage API - getUsage with history false",
|
|
269
126
|
func: UsageApi.getUsage,
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import * as MetadataApi from "../src/api/Metadata";
|
|
2
|
+
import { Client } from "../src/Client";
|
|
3
|
+
import {
|
|
4
|
+
METADATA_AREA_ENDPOINT,
|
|
5
|
+
METADATA_TYPES_ENDPOINT,
|
|
6
|
+
METADATA_UNITS_ENDPOINT,
|
|
7
|
+
} from "../src/Constants";
|
|
8
|
+
import * as requestModule from "../src/request";
|
|
9
|
+
|
|
10
|
+
type MetadataTestCase = {
|
|
11
|
+
name: string;
|
|
12
|
+
func: (arg?: string) => Promise<any>;
|
|
13
|
+
path: string;
|
|
14
|
+
endpoint?: string;
|
|
15
|
+
type?: string;
|
|
16
|
+
queryParams?: Record<string, string>;
|
|
17
|
+
requestBody?: Record<string, string>;
|
|
18
|
+
method: "GET" | "POST";
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const mockResp = "mock-success-response";
|
|
22
|
+
|
|
23
|
+
const testCases: MetadataTestCase[] = [
|
|
24
|
+
// GET Types Tests
|
|
25
|
+
{
|
|
26
|
+
name: "Metadata API - getTypes (default)",
|
|
27
|
+
func: MetadataApi.getTypes,
|
|
28
|
+
path: METADATA_TYPES_ENDPOINT,
|
|
29
|
+
method: "GET",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "Metadata API - getTypes with endpoint",
|
|
33
|
+
func: MetadataApi.getTypes,
|
|
34
|
+
path: METADATA_TYPES_ENDPOINT,
|
|
35
|
+
endpoint: "location",
|
|
36
|
+
queryParams: { endpoint: "location" },
|
|
37
|
+
method: "GET",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "Metadata API - getTypes with stationary endpoint",
|
|
41
|
+
func: MetadataApi.getTypes,
|
|
42
|
+
path: METADATA_TYPES_ENDPOINT,
|
|
43
|
+
endpoint: "stationary",
|
|
44
|
+
queryParams: { endpoint: "stationary" },
|
|
45
|
+
method: "GET",
|
|
46
|
+
},
|
|
47
|
+
// POST Types Tests
|
|
48
|
+
{
|
|
49
|
+
name: "Metadata API - postTypes (default)",
|
|
50
|
+
func: MetadataApi.postTypes,
|
|
51
|
+
path: METADATA_TYPES_ENDPOINT,
|
|
52
|
+
requestBody: {},
|
|
53
|
+
method: "POST",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "Metadata API - postTypes with endpoint",
|
|
57
|
+
func: MetadataApi.postTypes,
|
|
58
|
+
path: METADATA_TYPES_ENDPOINT,
|
|
59
|
+
endpoint: "mobile",
|
|
60
|
+
requestBody: { endpoint: "mobile" },
|
|
61
|
+
method: "POST",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "Metadata API - postTypes with fugitive endpoint",
|
|
65
|
+
func: MetadataApi.postTypes,
|
|
66
|
+
path: METADATA_TYPES_ENDPOINT,
|
|
67
|
+
endpoint: "fugitive",
|
|
68
|
+
requestBody: { endpoint: "fugitive" },
|
|
69
|
+
method: "POST",
|
|
70
|
+
},
|
|
71
|
+
// GET Area Tests
|
|
72
|
+
{
|
|
73
|
+
name: "Metadata API - getArea (default)",
|
|
74
|
+
func: MetadataApi.getArea,
|
|
75
|
+
path: METADATA_AREA_ENDPOINT,
|
|
76
|
+
method: "GET",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "Metadata API - getArea with endpoint",
|
|
80
|
+
func: MetadataApi.getArea,
|
|
81
|
+
path: METADATA_AREA_ENDPOINT,
|
|
82
|
+
endpoint: "calculation",
|
|
83
|
+
queryParams: { endpoint: "calculation" },
|
|
84
|
+
method: "GET",
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "Metadata API - getArea with transportation endpoint",
|
|
88
|
+
func: MetadataApi.getArea,
|
|
89
|
+
path: METADATA_AREA_ENDPOINT,
|
|
90
|
+
endpoint: "transportation-and-distribution",
|
|
91
|
+
queryParams: { endpoint: "transportation-and-distribution" },
|
|
92
|
+
method: "GET",
|
|
93
|
+
},
|
|
94
|
+
// POST Area Tests
|
|
95
|
+
{
|
|
96
|
+
name: "Metadata API - postArea (default)",
|
|
97
|
+
func: MetadataApi.postArea,
|
|
98
|
+
path: METADATA_AREA_ENDPOINT,
|
|
99
|
+
requestBody: {},
|
|
100
|
+
method: "POST",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: "Metadata API - postArea with endpoint",
|
|
104
|
+
func: MetadataApi.postArea,
|
|
105
|
+
path: METADATA_AREA_ENDPOINT,
|
|
106
|
+
endpoint: "real-estate",
|
|
107
|
+
requestBody: { endpoint: "real-estate" },
|
|
108
|
+
method: "POST",
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: "Metadata API - postArea with economic-activity endpoint",
|
|
112
|
+
func: MetadataApi.postArea,
|
|
113
|
+
path: METADATA_AREA_ENDPOINT,
|
|
114
|
+
endpoint: "economic-activity",
|
|
115
|
+
requestBody: { endpoint: "economic-activity" },
|
|
116
|
+
method: "POST",
|
|
117
|
+
},
|
|
118
|
+
// GET Units Tests
|
|
119
|
+
{
|
|
120
|
+
name: "Metadata API - getUnits (default)",
|
|
121
|
+
func: MetadataApi.getUnits,
|
|
122
|
+
path: METADATA_UNITS_ENDPOINT,
|
|
123
|
+
method: "GET",
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: "Metadata API - getUnits with type",
|
|
127
|
+
func: MetadataApi.getUnits,
|
|
128
|
+
path: METADATA_UNITS_ENDPOINT,
|
|
129
|
+
type: "Natural Gas",
|
|
130
|
+
queryParams: { type: "Natural Gas" },
|
|
131
|
+
method: "GET",
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: "Metadata API - getUnits with type with subtype",
|
|
135
|
+
func: MetadataApi.getUnits,
|
|
136
|
+
path: METADATA_UNITS_ENDPOINT,
|
|
137
|
+
type: "Natural Gas - Scope 3:AAA",
|
|
138
|
+
queryParams: { type: "Natural Gas - Scope 3:AAA" },
|
|
139
|
+
method: "GET",
|
|
140
|
+
},
|
|
141
|
+
// POST Units Tests
|
|
142
|
+
{
|
|
143
|
+
name: "Metadata API - postUnits (default)",
|
|
144
|
+
func: MetadataApi.postUnits,
|
|
145
|
+
path: METADATA_UNITS_ENDPOINT,
|
|
146
|
+
requestBody: {},
|
|
147
|
+
method: "POST",
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
name: "Metadata API - postUnits with type",
|
|
151
|
+
func: MetadataApi.postUnits,
|
|
152
|
+
path: METADATA_UNITS_ENDPOINT,
|
|
153
|
+
type: "electricity",
|
|
154
|
+
requestBody: { type: "electricity" },
|
|
155
|
+
method: "POST",
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: "Metadata API - postUnits with complex type",
|
|
159
|
+
func: MetadataApi.postUnits,
|
|
160
|
+
path: METADATA_UNITS_ENDPOINT,
|
|
161
|
+
type: "Business Travel - Cars:Diesel - Small",
|
|
162
|
+
requestBody: { type: "Business Travel - Cars:Diesel - Small" },
|
|
163
|
+
method: "POST",
|
|
164
|
+
},
|
|
165
|
+
];
|
|
166
|
+
|
|
167
|
+
describe("Metadata API Tests", () => {
|
|
168
|
+
let spy: jest.SpyInstance;
|
|
169
|
+
let tokenSpy: jest.SpyInstance;
|
|
170
|
+
|
|
171
|
+
beforeEach(() => {
|
|
172
|
+
jest.clearAllMocks();
|
|
173
|
+
tokenSpy = jest
|
|
174
|
+
.spyOn(Client as any, "requestToken")
|
|
175
|
+
.mockResolvedValue(
|
|
176
|
+
"eyJpzGciOiJIUzI1NlIsInR5cCI6IkplVCJ9." +
|
|
177
|
+
Buffer.from(
|
|
178
|
+
JSON.stringify({ exp: Math.floor(Date.now() / 1000) + 3600 })
|
|
179
|
+
).toString("base64") +
|
|
180
|
+
".signature"
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
Client.getClient({
|
|
184
|
+
apiKey: "mock-api-key",
|
|
185
|
+
clientId: "mock-client-id",
|
|
186
|
+
orgId: "mock-org-id",
|
|
187
|
+
});
|
|
188
|
+
spy = jest
|
|
189
|
+
.spyOn(requestModule, "makeApiRequest")
|
|
190
|
+
.mockResolvedValue(mockResp);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
afterEach(() => {
|
|
194
|
+
tokenSpy.mockRestore();
|
|
195
|
+
spy.mockRestore();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
describe.each(testCases)(
|
|
199
|
+
"$name",
|
|
200
|
+
({ func, path, endpoint, type, queryParams, requestBody, method }) => {
|
|
201
|
+
it("Should call makeApiRequest with correct parameters", async () => {
|
|
202
|
+
// For units tests, pass type; for types/area tests, pass endpoint
|
|
203
|
+
const result = await func(endpoint ?? type);
|
|
204
|
+
|
|
205
|
+
const clientDomain = Client.getInstance().getDomain();
|
|
206
|
+
const expectedUrl = `${clientDomain}${path}`;
|
|
207
|
+
|
|
208
|
+
const expectedRequest: any = {
|
|
209
|
+
method,
|
|
210
|
+
url: expectedUrl,
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
if (method === "POST") {
|
|
214
|
+
expectedRequest.data = requestBody;
|
|
215
|
+
} else if (method === "GET" && queryParams) {
|
|
216
|
+
expectedRequest.params = queryParams;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
expect(spy).toHaveBeenCalledWith(expectedRequest);
|
|
220
|
+
expect(result).toBe(mockResp);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
);
|
|
224
|
+
});
|
package/test/request.test.ts
CHANGED
|
@@ -2,7 +2,6 @@ import axios, { Method } from "axios";
|
|
|
2
2
|
import { makeApiRequest } from "../src/request";
|
|
3
3
|
import { Client } from "../src/Client";
|
|
4
4
|
import { RequestConfig } from "../src/interfaces/Config";
|
|
5
|
-
import { get } from "http";
|
|
6
5
|
import { CLIENT_SOURCE_HEADER } from "../src/Constants";
|
|
7
6
|
|
|
8
7
|
jest.mock("axios");
|