emissions-api-sdk 1.0.11 → 1.0.13
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 +157 -0
- package/dist/Constants.js +4 -1
- package/dist/api/AuditLog.js +99 -0
- package/dist/api/EconomicActivity.js +24 -0
- package/dist/api/Factor.js +72 -1
- package/dist/api/PhysicalActivity.js +87 -0
- package/dist/api/RealEstate.js +23 -0
- package/dist/api/TypeRecommender.js +67 -2
- package/dist/coverage/clover.xml +154 -89
- package/dist/coverage/coverage-final.json +15 -9
- package/dist/coverage/lcov-report/index.html +21 -21
- package/dist/coverage/lcov-report/src/Client.ts.html +32 -32
- package/dist/coverage/lcov-report/src/Constants.ts.html +36 -27
- package/dist/coverage/lcov-report/src/api/AuditLog.ts.html +388 -0
- package/dist/coverage/lcov-report/src/api/Calculation.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/EconomicActivity.ts.html +77 -5
- package/dist/coverage/lcov-report/src/api/Factor.ts.html +216 -3
- package/dist/coverage/lcov-report/src/api/FactorSets.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Fugitive.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Location.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Metadata.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Mobile.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/PhysicalActivity.ts.html +361 -0
- package/dist/coverage/lcov-report/src/api/RealEstate.ts.html +74 -5
- package/dist/coverage/lcov-report/src/api/Stationary.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/TransportationAndDistribution.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/TypeRecommender.ts.html +199 -4
- package/dist/coverage/lcov-report/src/api/Usage.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/index.html +36 -6
- 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/AttributionRequest.ts.html +151 -0
- package/dist/coverage/lcov-report/test/mocks/CommonRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/EconomicActivityAttributionRequest.ts.html +148 -0
- 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/PhysicalActivityEVICRequest.ts.html +148 -0
- package/dist/coverage/lcov-report/test/mocks/PhysicalActivityRequest.ts.html +151 -0
- package/dist/coverage/lcov-report/test/mocks/SearchRequest.ts.html +148 -4
- package/dist/coverage/lcov-report/test/mocks/index.html +64 -4
- package/dist/coverage/lcov-report/test/testUtils.ts.html +1 -1
- package/dist/coverage/lcov.info +254 -124
- package/dist/index.js +3 -1
- package/dist/interfaces/response/AuditLogResponse.js +2 -0
- package/dist/types/Constants.d.ts +3 -0
- package/dist/types/api/AuditLog.d.ts +37 -0
- package/dist/types/api/EconomicActivity.d.ts +24 -0
- package/dist/types/api/Factor.d.ts +72 -1
- package/dist/types/api/PhysicalActivity.d.ts +76 -0
- package/dist/types/api/RealEstate.d.ts +23 -0
- package/dist/types/api/TypeRecommender.d.ts +67 -2
- package/dist/types/index.d.ts +4 -0
- package/dist/types/interfaces/Api.d.ts +17 -1
- package/dist/types/interfaces/common.d.ts +48 -0
- package/dist/types/interfaces/response/AuditLogResponse.d.ts +40 -0
- package/dist/types/interfaces/response/TypeRecommenderResponse.d.ts +1 -0
- package/docs/_sources/authentication.rst.txt +26 -4
- package/docs/_sources/getting_started.rst.txt +538 -74
- package/docs/_sources/index.rst.txt +11 -0
- package/docs/_sources/reference.rst.txt +26 -0
- package/docs/_sources/troubleshooting.rst.txt +77 -12
- package/docs/_static/base-stemmer.js +476 -0
- package/docs/_static/english-stemmer.js +1066 -0
- package/docs/authentication.html +31 -5
- package/docs/client.html +3 -1
- package/docs/genindex.html +22 -2
- package/docs/getting_started.html +715 -82
- package/docs/index.html +35 -0
- package/docs/reference.html +412 -3
- package/docs/sdk.html +2 -0
- package/docs/search.html +2 -0
- package/docs/searchindex.js +1 -1
- package/docs/troubleshooting.html +75 -17
- package/package.json +7 -3
- package/sphinx-build/source/authentication.rst +26 -4
- package/sphinx-build/source/getting_started.rst +538 -74
- package/sphinx-build/source/index.rst +11 -0
- package/sphinx-build/source/reference.rst +26 -0
- package/sphinx-build/source/troubleshooting.rst +77 -12
- package/src/Constants.ts +3 -0
- package/src/api/AuditLog.ts +102 -0
- package/src/api/EconomicActivity.ts +24 -0
- package/src/api/Factor.ts +72 -1
- package/src/api/PhysicalActivity.ts +92 -0
- package/src/api/RealEstate.ts +23 -0
- package/src/api/TypeRecommender.ts +67 -2
- package/src/index.ts +7 -1
- package/src/interfaces/Api.ts +22 -6
- package/src/interfaces/common.ts +58 -0
- package/src/interfaces/response/AuditLogResponse.ts +47 -0
- package/src/interfaces/response/TypeRecommenderResponse.ts +2 -0
- package/test/apiTest.test.ts +59 -3
- package/test/auditLog.test.ts +216 -0
- package/test/mocks/AttributionRequest.ts +23 -0
- package/test/mocks/EconomicActivityAttributionRequest.ts +22 -0
- package/test/mocks/PhysicalActivityEVICRequest.ts +22 -0
- package/test/mocks/PhysicalActivityRequest.ts +23 -0
- package/test/mocks/SearchRequest.ts +48 -0
package/src/interfaces/Api.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Activity, Location , Time, CombinedUnitsActivity, FactorActivity, SearchActivity, Pagination, FactorActivityWithFactorId, CombinedUnitsActivityWithFactorId, ActivityWithFactorId } from "./common";
|
|
1
|
+
import { Activity, Location , Time, CombinedUnitsActivity, FactorActivity, SearchActivity, Pagination, FactorActivityWithFactorId, CombinedUnitsActivityWithFactorId, ActivityWithFactorId, Attribution } from "./common";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Represents activity data associated with a location, with simplified requirements.
|
|
@@ -105,7 +105,7 @@ export interface LocationRequestWithFactorId {
|
|
|
105
105
|
/**
|
|
106
106
|
* Common request parameters for calculations without specifying a factor ID.
|
|
107
107
|
* Used for general-purpose calculations based on location, time, and activity data.
|
|
108
|
-
*
|
|
108
|
+
*
|
|
109
109
|
* @interface CommonRequestWithoutFactorId
|
|
110
110
|
*/
|
|
111
111
|
export interface CommonRequestWithoutFactorId {
|
|
@@ -124,18 +124,23 @@ export interface CommonRequestWithoutFactorId {
|
|
|
124
124
|
* Contains complete activity information including type, value, and unit.
|
|
125
125
|
*/
|
|
126
126
|
activity: Activity;
|
|
127
|
+
/**
|
|
128
|
+
* Optional attribution information for FE calculations.
|
|
129
|
+
* Contains outstanding amount, property value, and currency.
|
|
130
|
+
*/
|
|
131
|
+
attribution?: Attribution;
|
|
127
132
|
/**
|
|
128
133
|
* Whether to include additional details in the response.
|
|
129
134
|
* When true, the API will return more comprehensive information.
|
|
130
135
|
* @default false
|
|
131
136
|
*/
|
|
132
137
|
includeDetails?: boolean;
|
|
133
|
-
}
|
|
138
|
+
}
|
|
134
139
|
|
|
135
140
|
/**
|
|
136
141
|
* Common request parameters for calculations with a specific factor ID.
|
|
137
142
|
* Used when the emission factor is already known and doesn't need to be determined by location.
|
|
138
|
-
*
|
|
143
|
+
*
|
|
139
144
|
* @interface CommonRequestWithFactorId
|
|
140
145
|
*/
|
|
141
146
|
export interface CommonRequestWithFactorId {
|
|
@@ -143,13 +148,18 @@ export interface CommonRequestWithFactorId {
|
|
|
143
148
|
* The activity data for the calculation, including the specific factor ID to use.
|
|
144
149
|
*/
|
|
145
150
|
activity: ActivityWithFactorId;
|
|
151
|
+
/**
|
|
152
|
+
* Optional attribution information for FE calculations.
|
|
153
|
+
* Contains outstanding amount, property value, and currency.
|
|
154
|
+
*/
|
|
155
|
+
attribution?: Attribution;
|
|
146
156
|
/**
|
|
147
157
|
* Whether to include additional details in the response.
|
|
148
158
|
* When true, the API will return more comprehensive information.
|
|
149
159
|
* @default false
|
|
150
160
|
*/
|
|
151
161
|
includeDetails?: boolean;
|
|
152
|
-
}
|
|
162
|
+
}
|
|
153
163
|
|
|
154
164
|
/**
|
|
155
165
|
* Request parameters for generic calculations without specifying a factor ID.
|
|
@@ -264,7 +274,13 @@ export interface SearchRequest {
|
|
|
264
274
|
* Optional pagination parameters for the search results.
|
|
265
275
|
* Used to limit the number of results and implement paging.
|
|
266
276
|
*/
|
|
267
|
-
pagination?: Pagination
|
|
277
|
+
pagination?: Pagination;
|
|
278
|
+
/**
|
|
279
|
+
* Optional reranker toggle for factor and type searches.
|
|
280
|
+
* Defaults to true when omitted. Set to false to use semantic similarity
|
|
281
|
+
* results directly without cross-encoder reranking.
|
|
282
|
+
*/
|
|
283
|
+
enableReranker?: boolean;
|
|
268
284
|
}
|
|
269
285
|
|
|
270
286
|
/**
|
package/src/interfaces/common.ts
CHANGED
|
@@ -155,6 +155,18 @@ export interface SearchActivity {
|
|
|
155
155
|
* The search query string.
|
|
156
156
|
*/
|
|
157
157
|
search: string;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Optional unit (symbol) for search activity.
|
|
161
|
+
*/
|
|
162
|
+
unit?: string;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Optional scope(1,2,3,3.1 to 3.15) for search activity.
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
scope?: string;
|
|
169
|
+
|
|
158
170
|
}
|
|
159
171
|
|
|
160
172
|
/**
|
|
@@ -172,3 +184,49 @@ export interface Pagination {
|
|
|
172
184
|
*/
|
|
173
185
|
size: number
|
|
174
186
|
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Represents attribution information for real estate, physical activity, and economic activity calculations.
|
|
190
|
+
* Supports four scenarios:
|
|
191
|
+
* 1. Property value based (for general real estate)
|
|
192
|
+
* 2. Equity/Debt based (for private companies)
|
|
193
|
+
* 3. EVIC based (Enterprise Value Including Cash for physical activity)
|
|
194
|
+
* 4. Revenue based (for economic activity)
|
|
195
|
+
* @interface Attribution
|
|
196
|
+
*/
|
|
197
|
+
export interface Attribution {
|
|
198
|
+
/**
|
|
199
|
+
* The outstanding amount for the property or activity.
|
|
200
|
+
*/
|
|
201
|
+
outstandingAmount?: number;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* The total property value (used in property value based scenario).
|
|
205
|
+
* Optional - use either propertyValue OR (totalEquity + totalDebt) OR evic OR revenue.
|
|
206
|
+
*/
|
|
207
|
+
propertyValue?: number;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The total equity amount (used in equity/debt based scenario for private companies).
|
|
211
|
+
* Optional - use either propertyValue OR (totalEquity + totalDebt) OR evic OR revenue.
|
|
212
|
+
*/
|
|
213
|
+
totalEquity?: number;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* The total debt amount (used in equity/debt based scenario for private companies).
|
|
217
|
+
* Optional - use either propertyValue OR (totalEquity + totalDebt) OR evic OR revenue.
|
|
218
|
+
*/
|
|
219
|
+
totalDebt?: number;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Enterprise Value Including Cash (EVIC) - used in EVIC based scenario for physical activity calculations.
|
|
223
|
+
* Optional - use either propertyValue OR (totalEquity + totalDebt) OR evic OR revenue.
|
|
224
|
+
*/
|
|
225
|
+
evic?: number;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Total revenue - used in revenue based scenario for economic activity calculations.
|
|
229
|
+
* Optional - use either propertyValue OR (totalEquity + totalDebt) OR evic OR revenue.
|
|
230
|
+
*/
|
|
231
|
+
revenue?: number;
|
|
232
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response interface for audit log configuration.
|
|
3
|
+
* Contains settings for logging requests and responses.
|
|
4
|
+
*
|
|
5
|
+
* @interface AuditLogResponse
|
|
6
|
+
*/
|
|
7
|
+
export interface AuditLogResponse {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Whether to log API requests.
|
|
11
|
+
* When true, all incoming requests will be logged.
|
|
12
|
+
*/
|
|
13
|
+
logRequest: boolean;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Whether to log API responses.
|
|
17
|
+
* When true, all outgoing responses will be logged.
|
|
18
|
+
*/
|
|
19
|
+
logResponse: boolean;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Message providing additional context about the response.
|
|
23
|
+
*/
|
|
24
|
+
message: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Request interface for updating audit log configuration.
|
|
29
|
+
* Used to configure which parts of API interactions should be logged.
|
|
30
|
+
*
|
|
31
|
+
* @interface AuditLogRequest
|
|
32
|
+
*/
|
|
33
|
+
export interface AuditLogRequest {
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Whether to log API requests.
|
|
37
|
+
* When true, all incoming requests will be logged.
|
|
38
|
+
*/
|
|
39
|
+
logRequest: boolean;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Whether to log API responses.
|
|
43
|
+
* When true, all outgoing responses will be logged.
|
|
44
|
+
*/
|
|
45
|
+
logResponse: boolean;
|
|
46
|
+
|
|
47
|
+
}
|
package/test/apiTest.test.ts
CHANGED
|
@@ -7,10 +7,12 @@ import * as GenericCalculation from "../src/api/Calculation";
|
|
|
7
7
|
import * as TransportationDistributionApi from "../src/api/TransportationAndDistribution";
|
|
8
8
|
import * as economicActivityApi from "../src/api/EconomicActivity";
|
|
9
9
|
import * as realEstateApi from "../src/api/RealEstate";
|
|
10
|
+
import * as physicalActivityApi from "../src/api/PhysicalActivity";
|
|
10
11
|
import * as UsageApi from "../src/api/Usage";
|
|
11
12
|
import * as Factors from "../src/api/Factor";
|
|
12
13
|
import * as FactorSets from "../src/api/FactorSets";
|
|
13
14
|
import * as VectorTypeSearch from "../src/api/TypeRecommender";
|
|
15
|
+
import * as AuditLogApi from "../src/api/AuditLog";
|
|
14
16
|
|
|
15
17
|
import {
|
|
16
18
|
LOCATION_API_PATH,
|
|
@@ -25,7 +27,9 @@ import {
|
|
|
25
27
|
USAGE_API,
|
|
26
28
|
ECONOMIC_ACTIVITY_API_PATH,
|
|
27
29
|
REAL_ESTATE_API_PATH,
|
|
30
|
+
PHYSICAL_ACTIVITY_API_PATH,
|
|
28
31
|
TYPE_RECOMMENDER_API_PATH,
|
|
32
|
+
AUDIT_LOG_API_PATH,
|
|
29
33
|
} from "../src/Constants";
|
|
30
34
|
import locationPayload from "./mocks/LocationRequest";
|
|
31
35
|
import commonpayload from "./mocks/CommonRequest";
|
|
@@ -33,6 +37,10 @@ import { Client } from "../src/Client";
|
|
|
33
37
|
import GenericCalculationPayload from "./mocks/GenericCalculationRequest";
|
|
34
38
|
import FactorPayload from "./mocks/FactorRequest";
|
|
35
39
|
import SearchPayload from "./mocks/SearchRequest";
|
|
40
|
+
import physicalActivityPayload from "./mocks/PhysicalActivityRequest";
|
|
41
|
+
import physicalActivityEVICPayload from "./mocks/PhysicalActivityEVICRequest";
|
|
42
|
+
import economicActivityAttributionPayload from "./mocks/EconomicActivityAttributionRequest";
|
|
43
|
+
import attributionPayload from "./mocks/AttributionRequest";
|
|
36
44
|
|
|
37
45
|
type ApiTestCase = {
|
|
38
46
|
name: string;
|
|
@@ -41,7 +49,7 @@ type ApiTestCase = {
|
|
|
41
49
|
payload?: any;
|
|
42
50
|
pathParams?: string | string[];
|
|
43
51
|
queryParams?: Record<string, string> | Record<string, boolean>;
|
|
44
|
-
method: "GET" | "POST";
|
|
52
|
+
method: "GET" | "POST" | "PUT";
|
|
45
53
|
};
|
|
46
54
|
|
|
47
55
|
const mockResp = "mock-success-response";
|
|
@@ -103,6 +111,13 @@ const testCases: ApiTestCase[] = [
|
|
|
103
111
|
payload: commonpayload,
|
|
104
112
|
method: "POST",
|
|
105
113
|
},
|
|
114
|
+
{
|
|
115
|
+
name: "Economic activity API with revenue attribution",
|
|
116
|
+
func: economicActivityApi.calculate,
|
|
117
|
+
path: ECONOMIC_ACTIVITY_API_PATH,
|
|
118
|
+
payload: economicActivityAttributionPayload,
|
|
119
|
+
method: "POST",
|
|
120
|
+
},
|
|
106
121
|
{
|
|
107
122
|
name: "Real estate API",
|
|
108
123
|
func: realEstateApi.calculate,
|
|
@@ -110,6 +125,34 @@ const testCases: ApiTestCase[] = [
|
|
|
110
125
|
payload: commonpayload,
|
|
111
126
|
method: "POST",
|
|
112
127
|
},
|
|
128
|
+
{
|
|
129
|
+
name: "Real estate API with attribution",
|
|
130
|
+
func: realEstateApi.calculate,
|
|
131
|
+
path: REAL_ESTATE_API_PATH,
|
|
132
|
+
payload: attributionPayload,
|
|
133
|
+
method: "POST",
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
name: "Physical activity API",
|
|
137
|
+
func: physicalActivityApi.calculate,
|
|
138
|
+
path: PHYSICAL_ACTIVITY_API_PATH,
|
|
139
|
+
payload: commonpayload,
|
|
140
|
+
method: "POST",
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: "Physical activity API with equity/debt attribution",
|
|
144
|
+
func: physicalActivityApi.calculate,
|
|
145
|
+
path: PHYSICAL_ACTIVITY_API_PATH,
|
|
146
|
+
payload: physicalActivityPayload,
|
|
147
|
+
method: "POST",
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
name: "Physical activity API with EVIC attribution",
|
|
151
|
+
func: physicalActivityApi.calculate,
|
|
152
|
+
path: PHYSICAL_ACTIVITY_API_PATH,
|
|
153
|
+
payload: physicalActivityEVICPayload,
|
|
154
|
+
method: "POST",
|
|
155
|
+
},
|
|
113
156
|
{
|
|
114
157
|
name: "FactorSet API",
|
|
115
158
|
func: FactorSets.get,
|
|
@@ -150,6 +193,19 @@ const testCases: ApiTestCase[] = [
|
|
|
150
193
|
path: TYPE_RECOMMENDER_API_PATH,
|
|
151
194
|
payload: SearchPayload,
|
|
152
195
|
method: "POST",
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
name: "AuditLog API - getAuditLogConfig",
|
|
199
|
+
func: AuditLogApi.getAuditConfig,
|
|
200
|
+
path: AUDIT_LOG_API_PATH,
|
|
201
|
+
method: "GET",
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
name: "AuditLog API - updateAuditLogConfig",
|
|
205
|
+
func: AuditLogApi.updateAuditConfig,
|
|
206
|
+
path: AUDIT_LOG_API_PATH,
|
|
207
|
+
payload: { logRequest: true, logResponse: false },
|
|
208
|
+
method: "PUT",
|
|
153
209
|
}
|
|
154
210
|
];
|
|
155
211
|
|
|
@@ -186,7 +242,7 @@ describe("API Test calculate functions", () => {
|
|
|
186
242
|
({ func, path, payload, pathParams, queryParams, method }) => {
|
|
187
243
|
it("Should call makeApiRequest with API url", async () => {
|
|
188
244
|
let result;
|
|
189
|
-
if (method === "POST") {
|
|
245
|
+
if (method === "POST" || method === "PUT") {
|
|
190
246
|
result = await func(payload);
|
|
191
247
|
} else {
|
|
192
248
|
// For GET requests with queryParams
|
|
@@ -222,7 +278,7 @@ describe("API Test calculate functions", () => {
|
|
|
222
278
|
method,
|
|
223
279
|
url: expectedUrl,
|
|
224
280
|
};
|
|
225
|
-
if (method === "POST") expectedRequest.data = payload;
|
|
281
|
+
if (method === "POST" || method === "PUT") expectedRequest.data = payload;
|
|
226
282
|
if (method === "GET" && queryParams) expectedRequest.params = queryParams;
|
|
227
283
|
expect(spy).toHaveBeenCalledWith(expectedRequest);
|
|
228
284
|
expect(result).toBe(mockResp);
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { getAuditConfig, updateAuditConfig } from '../src/api/AuditLog';
|
|
3
|
+
import { Client } from '../src/Client';
|
|
4
|
+
import * as request from '../src/request';
|
|
5
|
+
|
|
6
|
+
jest.mock('../src/request');
|
|
7
|
+
jest.mock('../src/Client');
|
|
8
|
+
|
|
9
|
+
describe('AuditLog - Error Handling', () => {
|
|
10
|
+
let mockClient: jest.Mocked<Client>;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
jest.clearAllMocks();
|
|
14
|
+
|
|
15
|
+
mockClient = {
|
|
16
|
+
getDomain: jest.fn().mockReturnValue('https://dev.api.ibm.com/ghgemissions/test/'),
|
|
17
|
+
refreshToken: jest.fn().mockResolvedValue(undefined),
|
|
18
|
+
getAuthHeader: jest.fn().mockReturnValue({ Authorization: 'Bearer mock-token' }),
|
|
19
|
+
getClientId: jest.fn().mockReturnValue('test-client-id'),
|
|
20
|
+
getClientSource: jest.fn().mockReturnValue('node-sdk'),
|
|
21
|
+
} as any;
|
|
22
|
+
|
|
23
|
+
(Client.getInstance as jest.Mock).mockReturnValue(mockClient);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should handle 409 Conflict gracefully when configuration is unchanged', async () => {
|
|
27
|
+
const mockError = {
|
|
28
|
+
isAxiosError: true,
|
|
29
|
+
response: {
|
|
30
|
+
status: 409,
|
|
31
|
+
statusText: 'Conflict',
|
|
32
|
+
data: {
|
|
33
|
+
logRequest: true,
|
|
34
|
+
logResponse: false,
|
|
35
|
+
message: 'No change in audit log configuration'
|
|
36
|
+
},
|
|
37
|
+
headers: {},
|
|
38
|
+
config: {}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Mock makeApiRequest to throw a 409 error
|
|
43
|
+
(request.makeApiRequest as jest.Mock).mockRejectedValue(mockError);
|
|
44
|
+
|
|
45
|
+
const payload = { logRequest: true, logResponse: false };
|
|
46
|
+
const result = await updateAuditConfig(payload);
|
|
47
|
+
|
|
48
|
+
expect(result).toEqual({
|
|
49
|
+
logRequest: true,
|
|
50
|
+
logResponse: false,
|
|
51
|
+
message: 'No change in audit log configuration'
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should throw error for non-409 status codes', async () => {
|
|
56
|
+
const mockError = {
|
|
57
|
+
isAxiosError: true,
|
|
58
|
+
response: {
|
|
59
|
+
status: 500,
|
|
60
|
+
statusText: 'Internal Server Error',
|
|
61
|
+
data: { message: 'Server error' },
|
|
62
|
+
headers: {},
|
|
63
|
+
config: {}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
(request.makeApiRequest as jest.Mock).mockRejectedValue(mockError);
|
|
68
|
+
|
|
69
|
+
const payload = { logRequest: true, logResponse: false };
|
|
70
|
+
|
|
71
|
+
await expect(updateAuditConfig(payload)).rejects.toEqual(mockError);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should return updated configuration on successful update', async () => {
|
|
75
|
+
const mockResponse = {
|
|
76
|
+
logRequest: false,
|
|
77
|
+
logResponse: true,
|
|
78
|
+
message: 'Audit log configuration updated successfully'
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
(request.makeApiRequest as jest.Mock).mockResolvedValue(mockResponse);
|
|
82
|
+
|
|
83
|
+
const payload = { logRequest: false, logResponse: true };
|
|
84
|
+
const result = await updateAuditConfig(payload);
|
|
85
|
+
|
|
86
|
+
expect(result).toEqual(mockResponse);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should throw error for non-Axios errors', async () => {
|
|
90
|
+
const mockError = new Error('Network error');
|
|
91
|
+
|
|
92
|
+
(request.makeApiRequest as jest.Mock).mockRejectedValue(mockError);
|
|
93
|
+
|
|
94
|
+
const payload = { logRequest: true, logResponse: false };
|
|
95
|
+
|
|
96
|
+
await expect(updateAuditConfig(payload)).rejects.toThrow('Network error');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should handle 400 Bad Request with error message from API', async () => {
|
|
100
|
+
const mockError = {
|
|
101
|
+
isAxiosError: true,
|
|
102
|
+
response: {
|
|
103
|
+
status: 400,
|
|
104
|
+
statusText: 'Bad Request',
|
|
105
|
+
data: {
|
|
106
|
+
message: 'Invalid payload: logRequest must be a boolean'
|
|
107
|
+
},
|
|
108
|
+
headers: {},
|
|
109
|
+
config: {}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
(request.makeApiRequest as jest.Mock).mockRejectedValue(mockError);
|
|
114
|
+
|
|
115
|
+
const payload = { logRequest: true, logResponse: false };
|
|
116
|
+
|
|
117
|
+
await expect(updateAuditConfig(payload)).rejects.toThrow('Invalid payload: logRequest must be a boolean');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should handle 403 Forbidden with error message from API', async () => {
|
|
121
|
+
const mockError = {
|
|
122
|
+
isAxiosError: true,
|
|
123
|
+
response: {
|
|
124
|
+
status: 403,
|
|
125
|
+
statusText: 'Forbidden',
|
|
126
|
+
data: {
|
|
127
|
+
message: 'User not authorized to make the request. Please contact the organisation administrator.'
|
|
128
|
+
},
|
|
129
|
+
headers: {},
|
|
130
|
+
config: {}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
(request.makeApiRequest as jest.Mock).mockRejectedValue(mockError);
|
|
135
|
+
|
|
136
|
+
const payload = { logRequest: true, logResponse: false };
|
|
137
|
+
|
|
138
|
+
await expect(updateAuditConfig(payload)).rejects.toThrow('User not authorized to make the request. Please contact the organisation administrator.');
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe('AuditLog - getAuditConfig Error Handling', () => {
|
|
143
|
+
let mockClient: jest.Mocked<Client>;
|
|
144
|
+
|
|
145
|
+
beforeEach(() => {
|
|
146
|
+
jest.clearAllMocks();
|
|
147
|
+
|
|
148
|
+
mockClient = {
|
|
149
|
+
getDomain: jest.fn().mockReturnValue('https://dev.api.ibm.com/ghgemissions/test/'),
|
|
150
|
+
refreshToken: jest.fn().mockResolvedValue(undefined),
|
|
151
|
+
getAuthHeader: jest.fn().mockReturnValue({ Authorization: 'Bearer mock-token' }),
|
|
152
|
+
getClientId: jest.fn().mockReturnValue('test-client-id'),
|
|
153
|
+
getClientSource: jest.fn().mockReturnValue('node-sdk'),
|
|
154
|
+
} as any;
|
|
155
|
+
|
|
156
|
+
(Client.getInstance as jest.Mock).mockReturnValue(mockClient);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('should return audit config on successful request', async () => {
|
|
160
|
+
const mockResponse = {
|
|
161
|
+
logRequest: true,
|
|
162
|
+
logResponse: false,
|
|
163
|
+
message: 'Current audit log configuration'
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
(request.makeApiRequest as jest.Mock).mockResolvedValue(mockResponse);
|
|
167
|
+
|
|
168
|
+
const result = await getAuditConfig();
|
|
169
|
+
|
|
170
|
+
expect(result).toEqual(mockResponse);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('should handle 403 Forbidden with error message from API', async () => {
|
|
174
|
+
const mockError = {
|
|
175
|
+
isAxiosError: true,
|
|
176
|
+
response: {
|
|
177
|
+
status: 403,
|
|
178
|
+
statusText: 'Forbidden',
|
|
179
|
+
data: {
|
|
180
|
+
message: 'User not authorized to make the request. Please contact the organisation administrator.'
|
|
181
|
+
},
|
|
182
|
+
headers: {},
|
|
183
|
+
config: {}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
(request.makeApiRequest as jest.Mock).mockRejectedValue(mockError);
|
|
188
|
+
|
|
189
|
+
await expect(getAuditConfig()).rejects.toThrow('User not authorized to make the request. Please contact the organisation administrator.');
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('should throw error for other status codes', async () => {
|
|
193
|
+
const mockError = {
|
|
194
|
+
isAxiosError: true,
|
|
195
|
+
response: {
|
|
196
|
+
status: 500,
|
|
197
|
+
statusText: 'Internal Server Error',
|
|
198
|
+
data: { message: 'Server error' },
|
|
199
|
+
headers: {},
|
|
200
|
+
config: {}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
(request.makeApiRequest as jest.Mock).mockRejectedValue(mockError);
|
|
205
|
+
|
|
206
|
+
await expect(getAuditConfig()).rejects.toEqual(mockError);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('should throw error for non-Axios errors', async () => {
|
|
210
|
+
const mockError = new Error('Network error');
|
|
211
|
+
|
|
212
|
+
(request.makeApiRequest as jest.Mock).mockRejectedValue(mockError);
|
|
213
|
+
|
|
214
|
+
await expect(getAuditConfig()).rejects.toThrow('Network error');
|
|
215
|
+
});
|
|
216
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CommonRequest } from '../../src/interfaces/Api';
|
|
2
|
+
|
|
3
|
+
const attributionPayload: CommonRequest = {
|
|
4
|
+
time: {
|
|
5
|
+
date: '2022-01-01',
|
|
6
|
+
},
|
|
7
|
+
location: {
|
|
8
|
+
country: 'usa',
|
|
9
|
+
stateProvince: 'new york',
|
|
10
|
+
},
|
|
11
|
+
activity: {
|
|
12
|
+
type: 'Commercial Real Estate:Office',
|
|
13
|
+
value: 123456.0,
|
|
14
|
+
unit: 'm2',
|
|
15
|
+
},
|
|
16
|
+
attribution: {
|
|
17
|
+
outstandingAmount: 1000000.0,
|
|
18
|
+
propertyValue: 5000000.0,
|
|
19
|
+
},
|
|
20
|
+
includeDetails: true,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default attributionPayload;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CommonRequest } from '../../src/interfaces/Api';
|
|
2
|
+
|
|
3
|
+
const economicActivityAttributionPayload: CommonRequest = {
|
|
4
|
+
time: {
|
|
5
|
+
date: '2025-01-04',
|
|
6
|
+
},
|
|
7
|
+
location: {
|
|
8
|
+
country: 'usa',
|
|
9
|
+
},
|
|
10
|
+
activity: {
|
|
11
|
+
type: 'accomodation',
|
|
12
|
+
value: 1500.12,
|
|
13
|
+
unit: 'usd',
|
|
14
|
+
},
|
|
15
|
+
attribution: {
|
|
16
|
+
outstandingAmount: 500000.0,
|
|
17
|
+
revenue: 2000000.0,
|
|
18
|
+
},
|
|
19
|
+
includeDetails: true,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default economicActivityAttributionPayload;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CommonRequest } from '../../src/interfaces/Api';
|
|
2
|
+
|
|
3
|
+
const physicalActivityEVICPayload: CommonRequest = {
|
|
4
|
+
time: {
|
|
5
|
+
date: '2025-01-23',
|
|
6
|
+
},
|
|
7
|
+
location: {
|
|
8
|
+
country: 'usa',
|
|
9
|
+
},
|
|
10
|
+
activity: {
|
|
11
|
+
type: 'commercial real estate',
|
|
12
|
+
value: 0.1,
|
|
13
|
+
unit: 'km2',
|
|
14
|
+
},
|
|
15
|
+
attribution: {
|
|
16
|
+
outstandingAmount: 1000000.0,
|
|
17
|
+
evic: 10000000.0,
|
|
18
|
+
},
|
|
19
|
+
includeDetails: true,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default physicalActivityEVICPayload;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CommonRequest } from '../../src/interfaces/Api';
|
|
2
|
+
|
|
3
|
+
const physicalActivityPayload: CommonRequest = {
|
|
4
|
+
time: {
|
|
5
|
+
date: '2025-01-23',
|
|
6
|
+
},
|
|
7
|
+
location: {
|
|
8
|
+
country: 'usa',
|
|
9
|
+
},
|
|
10
|
+
activity: {
|
|
11
|
+
type: 'commercial real estate',
|
|
12
|
+
value: 0.1,
|
|
13
|
+
unit: 'km2',
|
|
14
|
+
},
|
|
15
|
+
attribution: {
|
|
16
|
+
outstandingAmount: 1000000,
|
|
17
|
+
totalEquity: 3000000,
|
|
18
|
+
totalDebt: 2000000,
|
|
19
|
+
},
|
|
20
|
+
includeDetails: true,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default physicalActivityPayload;
|
|
@@ -16,4 +16,52 @@ const SearchPayload: SearchRequest = {
|
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
// Search payload with unit parameter
|
|
20
|
+
export const SearchPayloadWithUnit: SearchRequest = {
|
|
21
|
+
location: {
|
|
22
|
+
"country": "usa"
|
|
23
|
+
},
|
|
24
|
+
time: {
|
|
25
|
+
date: "2025-06-10",
|
|
26
|
+
},
|
|
27
|
+
activity: {
|
|
28
|
+
"search": "electricity",
|
|
29
|
+
"unit": "kWh"
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Search payload with scope parameter
|
|
34
|
+
export const SearchPayloadWithScope: SearchRequest = {
|
|
35
|
+
location: {
|
|
36
|
+
"country": "usa"
|
|
37
|
+
},
|
|
38
|
+
time: {
|
|
39
|
+
date: "2025-06-10",
|
|
40
|
+
},
|
|
41
|
+
activity: {
|
|
42
|
+
"search": "natural gas",
|
|
43
|
+
"scope": "1"
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// Search payload with both unit and scope parameters
|
|
48
|
+
export const SearchPayloadWithBoth: SearchRequest = {
|
|
49
|
+
location: {
|
|
50
|
+
"country": "usa",
|
|
51
|
+
"stateProvince": "california"
|
|
52
|
+
},
|
|
53
|
+
time: {
|
|
54
|
+
date: "2025-06-10",
|
|
55
|
+
},
|
|
56
|
+
activity: {
|
|
57
|
+
"search": "electricity",
|
|
58
|
+
"unit": "MWh",
|
|
59
|
+
"scope": "2"
|
|
60
|
+
},
|
|
61
|
+
pagination:{
|
|
62
|
+
"page": 1,
|
|
63
|
+
"size": 10
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
19
67
|
export default SearchPayload;
|