emissions-api-sdk 1.0.12 → 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 +42 -2
- 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 +19 -0
- package/dist/api/PhysicalActivity.js +87 -0
- package/dist/api/RealEstate.js +23 -0
- package/dist/api/TypeRecommender.js +19 -2
- package/dist/coverage/clover.xml +149 -87
- package/dist/coverage/coverage-final.json +14 -8
- 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 +59 -2
- 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 +55 -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 +1 -1
- package/dist/coverage/lcov-report/test/mocks/index.html +63 -3
- package/dist/coverage/lcov-report/test/testUtils.ts.html +1 -1
- package/dist/coverage/lcov.info +249 -122
- 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 +19 -0
- 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 +19 -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 +40 -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/basic.css +8 -0
- package/docs/_static/doctools.js +5 -6
- package/docs/_static/language_data.js +186 -7
- package/docs/_static/pygments.css +146 -164
- package/docs/_static/searchtools.js +60 -121
- package/docs/_static/sphinx_highlight.js +31 -36
- package/docs/_static/styles/furo.css +1 -1
- package/docs/_static/styles/furo.css.map +1 -1
- package/docs/authentication.html +61 -26
- package/docs/client.html +33 -22
- package/docs/genindex.html +52 -23
- package/docs/getting_started.html +745 -103
- package/docs/index.html +65 -21
- package/docs/reference.html +484 -66
- package/docs/sdk.html +32 -21
- package/docs/search.html +32 -21
- package/docs/searchindex.js +1 -1
- package/docs/troubleshooting.html +105 -38
- 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 +19 -0
- package/src/api/PhysicalActivity.ts +92 -0
- package/src/api/RealEstate.ts +23 -0
- package/src/api/TypeRecommender.ts +19 -2
- package/src/index.ts +7 -1
- package/src/interfaces/Api.ts +22 -6
- package/src/interfaces/common.ts +46 -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
|
@@ -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;
|