@unito/integration-sdk 0.1.6 → 0.1.7
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.
|
@@ -89,8 +89,8 @@ export class Provider {
|
|
|
89
89
|
throw buildHttpError(response.status, textResult);
|
|
90
90
|
}
|
|
91
91
|
try {
|
|
92
|
-
const
|
|
93
|
-
return { status: response.status, headers: response.headers,
|
|
92
|
+
const body = response.body ? await response.json() : undefined;
|
|
93
|
+
return { status: response.status, headers: response.headers, body };
|
|
94
94
|
}
|
|
95
95
|
catch {
|
|
96
96
|
throw buildHttpError(400, 'Invalid JSON response');
|
|
@@ -41,7 +41,7 @@ describe('Provider', () => {
|
|
|
41
41
|
},
|
|
42
42
|
},
|
|
43
43
|
]);
|
|
44
|
-
assert.deepEqual(actualResponse, { status: 200, headers: response.headers,
|
|
44
|
+
assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
|
|
45
45
|
});
|
|
46
46
|
it('post with url encoded body', async (context) => {
|
|
47
47
|
const response = new Response('{"data": "value"}', {
|
|
@@ -71,7 +71,7 @@ describe('Provider', () => {
|
|
|
71
71
|
},
|
|
72
72
|
},
|
|
73
73
|
]);
|
|
74
|
-
assert.deepEqual(actualResponse, { status: 201, headers: response.headers,
|
|
74
|
+
assert.deepEqual(actualResponse, { status: 201, headers: response.headers, body: { data: 'value' } });
|
|
75
75
|
});
|
|
76
76
|
it('put with json body', async (context) => {
|
|
77
77
|
const response = new Response('{"data": "value"}', {
|
|
@@ -102,7 +102,7 @@ describe('Provider', () => {
|
|
|
102
102
|
},
|
|
103
103
|
},
|
|
104
104
|
]);
|
|
105
|
-
assert.deepEqual(actualResponse, { status: 201, headers: response.headers,
|
|
105
|
+
assert.deepEqual(actualResponse, { status: 201, headers: response.headers, body: { data: 'value' } });
|
|
106
106
|
});
|
|
107
107
|
it('patch with query params', async (context) => {
|
|
108
108
|
const response = new Response('{"data": "value"}', {
|
|
@@ -133,7 +133,7 @@ describe('Provider', () => {
|
|
|
133
133
|
},
|
|
134
134
|
},
|
|
135
135
|
]);
|
|
136
|
-
assert.deepEqual(actualResponse, { status: 201, headers: response.headers,
|
|
136
|
+
assert.deepEqual(actualResponse, { status: 201, headers: response.headers, body: { data: 'value' } });
|
|
137
137
|
});
|
|
138
138
|
it('delete', async (context) => {
|
|
139
139
|
const response = new Response(undefined, {
|
|
@@ -161,7 +161,7 @@ describe('Provider', () => {
|
|
|
161
161
|
},
|
|
162
162
|
},
|
|
163
163
|
]);
|
|
164
|
-
assert.deepEqual(actualResponse, { status: 204, headers: response.headers,
|
|
164
|
+
assert.deepEqual(actualResponse, { status: 204, headers: response.headers, body: undefined });
|
|
165
165
|
});
|
|
166
166
|
it('uses rate limiter if provided', async (context) => {
|
|
167
167
|
const mockRateLimiter = context.mock.fn((_context, request) => Promise.resolve(request()));
|
|
@@ -205,7 +205,7 @@ describe('Provider', () => {
|
|
|
205
205
|
},
|
|
206
206
|
},
|
|
207
207
|
]);
|
|
208
|
-
assert.deepEqual(actualResponse, { status: 204, headers: response.headers,
|
|
208
|
+
assert.deepEqual(actualResponse, { status: 204, headers: response.headers, body: undefined });
|
|
209
209
|
});
|
|
210
210
|
it('throws on invalid json response', async (context) => {
|
|
211
211
|
const response = new Response('{invalidJSON}', {
|
package/package.json
CHANGED
|
@@ -31,7 +31,7 @@ export interface RequestOptions {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export interface Response<T> {
|
|
34
|
-
|
|
34
|
+
body: T;
|
|
35
35
|
status: number;
|
|
36
36
|
headers: Headers;
|
|
37
37
|
}
|
|
@@ -151,8 +151,8 @@ export class Provider {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
try {
|
|
154
|
-
const
|
|
155
|
-
return { status: response.status, headers: response.headers,
|
|
154
|
+
const body: T = response.body ? await response.json() : undefined;
|
|
155
|
+
return { status: response.status, headers: response.headers, body };
|
|
156
156
|
} catch {
|
|
157
157
|
throw buildHttpError(400, 'Invalid JSON response');
|
|
158
158
|
}
|
|
@@ -48,7 +48,7 @@ describe('Provider', () => {
|
|
|
48
48
|
},
|
|
49
49
|
},
|
|
50
50
|
]);
|
|
51
|
-
assert.deepEqual(actualResponse, { status: 200, headers: response.headers,
|
|
51
|
+
assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
it('post with url encoded body', async context => {
|
|
@@ -86,7 +86,7 @@ describe('Provider', () => {
|
|
|
86
86
|
},
|
|
87
87
|
},
|
|
88
88
|
]);
|
|
89
|
-
assert.deepEqual(actualResponse, { status: 201, headers: response.headers,
|
|
89
|
+
assert.deepEqual(actualResponse, { status: 201, headers: response.headers, body: { data: 'value' } });
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
it('put with json body', async context => {
|
|
@@ -125,7 +125,7 @@ describe('Provider', () => {
|
|
|
125
125
|
},
|
|
126
126
|
},
|
|
127
127
|
]);
|
|
128
|
-
assert.deepEqual(actualResponse, { status: 201, headers: response.headers,
|
|
128
|
+
assert.deepEqual(actualResponse, { status: 201, headers: response.headers, body: { data: 'value' } });
|
|
129
129
|
});
|
|
130
130
|
|
|
131
131
|
it('patch with query params', async context => {
|
|
@@ -164,7 +164,7 @@ describe('Provider', () => {
|
|
|
164
164
|
},
|
|
165
165
|
},
|
|
166
166
|
]);
|
|
167
|
-
assert.deepEqual(actualResponse, { status: 201, headers: response.headers,
|
|
167
|
+
assert.deepEqual(actualResponse, { status: 201, headers: response.headers, body: { data: 'value' } });
|
|
168
168
|
});
|
|
169
169
|
|
|
170
170
|
it('delete', async context => {
|
|
@@ -196,7 +196,7 @@ describe('Provider', () => {
|
|
|
196
196
|
},
|
|
197
197
|
},
|
|
198
198
|
]);
|
|
199
|
-
assert.deepEqual(actualResponse, { status: 204, headers: response.headers,
|
|
199
|
+
assert.deepEqual(actualResponse, { status: 204, headers: response.headers, body: undefined });
|
|
200
200
|
});
|
|
201
201
|
|
|
202
202
|
it('uses rate limiter if provided', async context => {
|
|
@@ -247,7 +247,7 @@ describe('Provider', () => {
|
|
|
247
247
|
},
|
|
248
248
|
},
|
|
249
249
|
]);
|
|
250
|
-
assert.deepEqual(actualResponse, { status: 204, headers: response.headers,
|
|
250
|
+
assert.deepEqual(actualResponse, { status: 204, headers: response.headers, body: undefined });
|
|
251
251
|
});
|
|
252
252
|
|
|
253
253
|
it('throws on invalid json response', async context => {
|