Skip to content

Commit cd4cd38

Browse files
committed
fix tests
1 parent e7685d0 commit cd4cd38

File tree

5 files changed

+237
-178
lines changed

5 files changed

+237
-178
lines changed

src/__mocks__/handlers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const handlers = [
6767

6868
/**
6969
* When `msw` is used in a test, the `mirror` method can be used
70-
* on the Response of a `fetch` to provide prope type information.
70+
* on the Response of a `fetch` to provide proper type information.
7171
*
7272
* @param response The `Response` object from a `fetch` call that `msw` intercepted.
7373
*/

src/__tests__/sdk-options.spec.ts

+33-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { timer } from '../index';
2-
import type { MirroredRequest } from '../__mocks__/handlers';
2+
import { mirror } from '../__mocks__/handlers';
33

44
describe('sdk-options', () => {
55
test('environment', async () => {
@@ -8,44 +8,55 @@ describe('sdk-options', () => {
88
schedule: {
99
type: 'once' as const,
1010
},
11+
resource_server: 'transfer.api.globus.org' as const,
1112
timer_type: 'transfer' as const,
1213
body: {
1314
source_endpoint: 'endpoint-1',
1415
destination_endpoint: 'endpoint-2',
16+
delete_destination_extra: false,
17+
encrypt_data: false,
18+
fail_on_quota_errors: false,
19+
notify_on_failed: false,
20+
notify_on_inactive: false,
21+
notify_on_succeeded: false,
22+
preserve_timestamp: false,
23+
skip_source_errors: false,
24+
store_base_path_info: false,
25+
verify_checksum: false,
1526
DATA_TYPE: 'transfer' as const,
1627
DATA: [],
1728
},
1829
},
1930
};
2031

21-
const withEnvironment = await timer.create(
22-
{
23-
headers: {
24-
Authorization: 'Bearer example',
25-
},
26-
payload,
27-
},
28-
{
29-
environment: 'sandbox',
30-
},
31-
);
32-
3332
const {
3433
req: { headers: withEnvironmentHeaders },
35-
} = (await withEnvironment.json()) as MirroredRequest;
34+
} = await mirror(
35+
await timer.create(
36+
{
37+
headers: {
38+
Authorization: 'Bearer example',
39+
},
40+
payload,
41+
},
42+
{
43+
environment: 'sandbox',
44+
},
45+
),
46+
);
3647

3748
expect(withEnvironmentHeaders['host']).toEqual('sandbox.timer.automate.globus.org');
3849

39-
const withoutEnvironment = await timer.create({
40-
headers: {
41-
Authorization: 'Bearer example',
42-
},
43-
payload,
44-
});
45-
4650
const {
4751
req: { headers: withoutEnvironmentHeaders },
48-
} = (await withoutEnvironment.json()) as MirroredRequest;
52+
} = await mirror(
53+
await timer.create({
54+
headers: {
55+
Authorization: 'Bearer example',
56+
},
57+
payload,
58+
}),
59+
);
4960

5061
expect(withoutEnvironmentHeaders['host']).toEqual('timer.automate.globus.org');
5162
});

src/services/globus-connect-server/__tests__/endpoint.spec.ts

+90-79
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import { endpoint } from '..';
22

3-
import type { MirroredRequest } from '../../../__mocks__/handlers';
3+
import { mirror } from '../../../__mocks__/handlers';
44

55
const GCS_HOST = 'https://fa5e.bd7c.data.globus.org';
66

77
describe('gcs – endpoint', () => {
88
test('get', async () => {
9-
const result = await endpoint.get({
10-
host: GCS_HOST,
11-
endpoint_id: 'ac9cb54b-fc48-4824-b801-1388baf0a909',
12-
});
139
const {
1410
req: { url, method, headers },
15-
} = (await result.json()) as unknown as MirroredRequest;
11+
} = await mirror(
12+
await endpoint.get({
13+
host: GCS_HOST,
14+
endpoint_id: 'ac9cb54b-fc48-4824-b801-1388baf0a909',
15+
}),
16+
);
1617
expect({
1718
url,
1819
method,
@@ -33,21 +34,24 @@ describe('gcs – endpoint', () => {
3334
});
3435

3536
test('update', async () => {
36-
const result = await endpoint.update(
37-
{
38-
host: GCS_HOST,
39-
endpoint_id: 'ac9cb54b-fc48-4824-b801-1388baf0a909',
40-
},
41-
{
42-
payload: {
43-
DATA_TYPE: 'endpoint#1.0.0',
44-
display_name: 'My First Endpoint',
45-
},
46-
},
47-
);
4837
const {
4938
req: { url, method, headers, json },
50-
} = (await result.json()) as unknown as MirroredRequest;
39+
} = await mirror(
40+
await endpoint.update(
41+
{
42+
host: GCS_HOST,
43+
endpoint_id: 'ac9cb54b-fc48-4824-b801-1388baf0a909',
44+
},
45+
{
46+
payload: {
47+
DATA_TYPE: 'endpoint#1.0.0',
48+
display_name: 'My First Endpoint',
49+
network_use: 'normal',
50+
public: true,
51+
},
52+
},
53+
),
54+
);
5155
expect({
5256
url,
5357
method,
@@ -59,14 +63,16 @@ describe('gcs – endpoint', () => {
5963
"accept": "*/*",
6064
"accept-encoding": "gzip,deflate",
6165
"connection": "close",
62-
"content-length": "65",
66+
"content-length": "102",
6367
"content-type": "application/json",
6468
"host": "fa5e.bd7c.data.globus.org",
6569
"user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)",
6670
},
6771
"json": {
6872
"DATA_TYPE": "endpoint#1.0.0",
6973
"display_name": "My First Endpoint",
74+
"network_use": "normal",
75+
"public": true,
7076
},
7177
"method": "PUT",
7278
"url": "https://fa5e.bd7c.data.globus.org/api/endpoint",
@@ -75,20 +81,21 @@ describe('gcs – endpoint', () => {
7581
});
7682

7783
test('patch', async () => {
78-
const result = await endpoint.patch(
79-
{
80-
host: GCS_HOST,
81-
endpoint_id: 'ac9cb54b-fc48-4824-b801-1388baf0a909',
82-
},
83-
{
84-
payload: {
85-
public: true,
86-
},
87-
},
88-
);
8984
const {
9085
req: { url, method, headers, json },
91-
} = (await result.json()) as unknown as MirroredRequest;
86+
} = await mirror(
87+
await endpoint.patch(
88+
{
89+
host: GCS_HOST,
90+
endpoint_id: 'ac9cb54b-fc48-4824-b801-1388baf0a909',
91+
},
92+
{
93+
payload: {
94+
public: true,
95+
},
96+
},
97+
),
98+
);
9299
expect({
93100
url,
94101
method,
@@ -115,21 +122,22 @@ describe('gcs – endpoint', () => {
115122
});
116123

117124
test('updateSubscriptionId', async () => {
118-
const result = await endpoint.updateSubscriptionId(
119-
{
120-
host: GCS_HOST,
121-
endpoint_id: 'ac9cb54b-fc48-4824-b801-1388baf0a909',
122-
},
123-
{
124-
payload: {
125-
DATA_TYPE: 'endpoint_subscription#1.0.0',
126-
subscription_id: 'example-subscription-id',
127-
},
128-
},
129-
);
130125
const {
131126
req: { url, method, headers, json },
132-
} = (await result.json()) as unknown as MirroredRequest;
127+
} = await mirror(
128+
await endpoint.updateSubscriptionId(
129+
{
130+
host: GCS_HOST,
131+
endpoint_id: 'ac9cb54b-fc48-4824-b801-1388baf0a909',
132+
},
133+
{
134+
payload: {
135+
DATA_TYPE: 'endpoint_subscription#1.0.0',
136+
subscription_id: 'example-subscription-id',
137+
},
138+
},
139+
),
140+
);
133141
expect({
134142
url,
135143
method,
@@ -157,21 +165,22 @@ describe('gcs – endpoint', () => {
157165
});
158166

159167
test('updateOwnerString', async () => {
160-
const result = await endpoint.updateOwnerString(
161-
{
162-
host: GCS_HOST,
163-
endpoint_id: 'ac9cb54b-fc48-4824-b801-1388baf0a909',
164-
},
165-
{
166-
payload: {
167-
DATA_TYPE: 'owner_string#1.0.0',
168-
identity_id: 'example-identity-id',
169-
},
170-
},
171-
);
172168
const {
173169
req: { url, method, headers, json },
174-
} = (await result.json()) as unknown as MirroredRequest;
170+
} = await mirror(
171+
await endpoint.updateOwnerString(
172+
{
173+
host: GCS_HOST,
174+
endpoint_id: 'ac9cb54b-fc48-4824-b801-1388baf0a909',
175+
},
176+
{
177+
payload: {
178+
DATA_TYPE: 'owner_string#1.0.0',
179+
identity_id: 'example-identity-id',
180+
},
181+
},
182+
),
183+
);
175184
expect({
176185
url,
177186
method,
@@ -199,21 +208,22 @@ describe('gcs – endpoint', () => {
199208
});
200209

201210
test('updateOwner', async () => {
202-
const result = await endpoint.updateOwner(
203-
{
204-
host: GCS_HOST,
205-
endpoint_id: 'ac9cb54b-fc48-4824-b801-1388baf0a909',
206-
},
207-
{
208-
payload: {
209-
DATA_TYPE: 'endpoint_owner#1.0.0',
210-
identity_id: 'example-identity-id',
211-
},
212-
},
213-
);
214211
const {
215212
req: { url, method, headers, json },
216-
} = (await result.json()) as unknown as MirroredRequest;
213+
} = await mirror(
214+
await endpoint.updateOwner(
215+
{
216+
host: GCS_HOST,
217+
endpoint_id: 'ac9cb54b-fc48-4824-b801-1388baf0a909',
218+
},
219+
{
220+
payload: {
221+
DATA_TYPE: 'endpoint_owner#1.0.0',
222+
identity_id: 'example-identity-id',
223+
},
224+
},
225+
),
226+
);
217227
expect({
218228
url,
219229
method,
@@ -241,16 +251,17 @@ describe('gcs – endpoint', () => {
241251
});
242252

243253
test('resetOwnerString', async () => {
244-
const result = await endpoint.resetOwnerString(
245-
{
246-
host: GCS_HOST,
247-
endpoint_id: 'ac9cb54b-fc48-4824-b801-1388baf0a909',
248-
},
249-
{},
250-
);
251254
const {
252255
req: { url, method, headers },
253-
} = (await result.json()) as unknown as MirroredRequest;
256+
} = await mirror(
257+
await endpoint.resetOwnerString(
258+
{
259+
host: GCS_HOST,
260+
endpoint_id: 'ac9cb54b-fc48-4824-b801-1388baf0a909',
261+
},
262+
{},
263+
),
264+
);
254265
expect({
255266
url,
256267
method,

0 commit comments

Comments
 (0)