Skip to content

Commit 6c7cdcf

Browse files
authored
Merge branch 'main' into temp/release-merge-1729882564
2 parents f2248ad + c19b2f3 commit 6c7cdcf

File tree

25 files changed

+2470
-1212
lines changed

25 files changed

+2470
-1212
lines changed

packages/api-graphql/__tests__/AWSAppSyncRealTimeProvider.test.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import { ConnectionState as CS } from '../src/types/PubSub';
1313

1414
import { AWSAppSyncRealTimeProvider } from '../src/Providers/AWSAppSyncRealTimeProvider';
15+
import { isCustomDomain } from '../src/Providers/AWSWebSocketProvider/appsyncUrl';
1516

1617
// Mock all calls to signRequest
1718
jest.mock('@aws-amplify/core/internals/aws-client-utils', () => {
@@ -20,7 +21,7 @@ jest.mock('@aws-amplify/core/internals/aws-client-utils', () => {
2021
);
2122
return {
2223
...original,
23-
signRequest: (_request, _options) => {
24+
signRequest: (_request: any, _options: any) => {
2425
return {
2526
method: 'test',
2627
headers: { test: 'test' },
@@ -46,7 +47,7 @@ jest.mock('@aws-amplify/core', () => {
4647
};
4748
return {
4849
...original,
49-
fetchAuthSession: (_request, _options) => {
50+
fetchAuthSession: (_request: any, _options: any) => {
5051
return Promise.resolve(session);
5152
},
5253
Amplify: {
@@ -66,24 +67,19 @@ jest.mock('@aws-amplify/core', () => {
6667
describe('AWSAppSyncRealTimeProvider', () => {
6768
describe('isCustomDomain()', () => {
6869
test('Custom domain returns `true`', () => {
69-
const provider = new AWSAppSyncRealTimeProvider();
70-
const result = (provider as any).isCustomDomain(
71-
'https://unit-test.testurl.com/graphql',
72-
);
70+
const result = isCustomDomain('https://unit-test.testurl.com/graphql');
7371
expect(result).toBe(true);
7472
});
7573

7674
test('Non-custom domain returns `false`', () => {
77-
const provider = new AWSAppSyncRealTimeProvider();
78-
const result = (provider as any).isCustomDomain(
75+
const result = isCustomDomain(
7976
'https://12345678901234567890123456.appsync-api.us-west-2.amazonaws.com/graphql',
8077
);
8178
expect(result).toBe(false);
8279
});
8380

8481
test('Non-custom domain in the amazonaws.com.cn subdomain space returns `false`', () => {
85-
const provider = new AWSAppSyncRealTimeProvider();
86-
const result = (provider as any).isCustomDomain(
82+
const result = isCustomDomain(
8783
'https://12345678901234567890123456.appsync-api.cn-north-1.amazonaws.com.cn/graphql',
8884
);
8985
expect(result).toBe(false);
@@ -136,10 +132,12 @@ describe('AWSAppSyncRealTimeProvider', () => {
136132
// Saving this spy and resetting it by hand causes badness
137133
// Saving it causes new websockets to be reachable across past tests that have not fully closed
138134
// Resetting it proactively causes those same past tests to be dealing with null while they reach a settled state
139-
jest.spyOn(provider, 'getNewWebSocket').mockImplementation(() => {
140-
fakeWebSocketInterface.newWebSocket();
141-
return fakeWebSocketInterface.webSocket as WebSocket;
142-
});
135+
jest
136+
.spyOn(provider as any, '_getNewWebSocket')
137+
.mockImplementation(() => {
138+
fakeWebSocketInterface.newWebSocket();
139+
return fakeWebSocketInterface.webSocket as WebSocket;
140+
});
143141

144142
// Reduce retry delay for tests to 100ms
145143
Object.defineProperty(constants, 'MAX_DELAY_MS', {
@@ -228,7 +226,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
228226
expect.assertions(1);
229227

230228
const newSocketSpy = jest
231-
.spyOn(provider, 'getNewWebSocket')
229+
.spyOn(provider as any, '_getNewWebSocket')
232230
.mockImplementation(() => {
233231
fakeWebSocketInterface.newWebSocket();
234232
return fakeWebSocketInterface.webSocket as WebSocket;
@@ -254,7 +252,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
254252
expect.assertions(1);
255253

256254
const newSocketSpy = jest
257-
.spyOn(provider, 'getNewWebSocket')
255+
.spyOn(provider as any, '_getNewWebSocket')
258256
.mockImplementation(() => {
259257
fakeWebSocketInterface.newWebSocket();
260258
return fakeWebSocketInterface.webSocket as WebSocket;
@@ -280,7 +278,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
280278
expect.assertions(1);
281279

282280
const newSocketSpy = jest
283-
.spyOn(provider, 'getNewWebSocket')
281+
.spyOn(provider as any, '_getNewWebSocket')
284282
.mockImplementation(() => {
285283
fakeWebSocketInterface.newWebSocket();
286284
return fakeWebSocketInterface.webSocket as WebSocket;
@@ -307,7 +305,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
307305
expect.assertions(1);
308306

309307
const newSocketSpy = jest
310-
.spyOn(provider, 'getNewWebSocket')
308+
.spyOn(provider as any, '_getNewWebSocket')
311309
.mockImplementation(() => {
312310
fakeWebSocketInterface.newWebSocket();
313311
return fakeWebSocketInterface.webSocket;
@@ -349,7 +347,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
349347
expect.assertions(1);
350348

351349
const newSocketSpy = jest
352-
.spyOn(provider, 'getNewWebSocket')
350+
.spyOn(provider as any, '_getNewWebSocket')
353351
.mockImplementation(() => {
354352
fakeWebSocketInterface.newWebSocket();
355353
return fakeWebSocketInterface.webSocket;
@@ -545,7 +543,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
545543
await fakeWebSocketInterface?.standardConnectionHandshake();
546544

547545
await fakeWebSocketInterface?.sendDataMessage({
548-
type: MESSAGE_TYPES.GQL_DATA,
546+
type: MESSAGE_TYPES.DATA,
549547
payload: { data: {} },
550548
});
551549

@@ -571,7 +569,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
571569
connectionTimeoutMs: 100,
572570
});
573571
await fakeWebSocketInterface?.sendDataMessage({
574-
type: MESSAGE_TYPES.GQL_DATA,
572+
type: MESSAGE_TYPES.DATA,
575573
payload: { data: {} },
576574
});
577575

@@ -597,7 +595,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
597595
connectionTimeoutMs: 100,
598596
});
599597
await fakeWebSocketInterface?.sendDataMessage({
600-
type: MESSAGE_TYPES.GQL_DATA,
598+
type: MESSAGE_TYPES.DATA,
601599
payload: { data: {} },
602600
});
603601
expect(mockNext).toHaveBeenCalled();
@@ -677,7 +675,9 @@ describe('AWSAppSyncRealTimeProvider', () => {
677675
}),
678676
);
679677

680-
expect(socketCloseSpy).toHaveBeenNthCalledWith(1, 3001);
678+
await delay(1);
679+
680+
expect(socketCloseSpy).toHaveBeenCalledWith(3001);
681681
});
682682

683683
test('subscription observer error is triggered when a connection is formed', async () => {
@@ -931,7 +931,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
931931

932932
await fakeWebSocketInterface?.standardConnectionHandshake();
933933
await fakeWebSocketInterface?.sendDataMessage({
934-
type: MESSAGE_TYPES.GQL_DATA,
934+
type: MESSAGE_TYPES.DATA,
935935
payload: { data: {} },
936936
});
937937
await subscription.unsubscribe();
@@ -1181,7 +1181,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
11811181
});
11821182

11831183
test('authenticating with AWS_LAMBDA/custom w/ custom header function that accepts request options', async () => {
1184-
expect.assertions(2);
1184+
expect.assertions(3);
11851185

11861186
provider
11871187
.subscribe({

packages/api-graphql/__tests__/GraphQLAPI.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { Amplify as AmplifyCore } from '@aws-amplify/core';
55
import * as typedQueries from './fixtures/with-types/queries';
66
import * as typedSubscriptions from './fixtures/with-types/subscriptions';
77
import { expectGet } from './utils/expects';
8-
import { InternalGraphQLAPIClass } from '../src/internals/InternalGraphQLAPI';
98
import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
109
import { INTERNAL_USER_AGENT_OVERRIDE } from '@aws-amplify/data-schema/runtime';
10+
import * as graphqlAuth from '../src/internals/graphqlAuth';
1111

1212
import {
1313
__amplify,
@@ -1489,10 +1489,7 @@ describe('API test', () => {
14891489
},
14901490
};
14911491

1492-
const spy = jest.spyOn(
1493-
InternalGraphQLAPIClass.prototype as any,
1494-
'_headerBasedAuth',
1495-
);
1492+
const spy = jest.spyOn(graphqlAuth, 'headerBasedAuth');
14961493

14971494
const spy2 = jest
14981495
.spyOn((raw.GraphQLAPI as any)._api, 'post')
@@ -1515,6 +1512,7 @@ describe('API test', () => {
15151512
getConfig: expect.any(Function),
15161513
}),
15171514
'iam',
1515+
'FAKE-KEY',
15181516
{},
15191517
);
15201518
});
@@ -1579,7 +1577,7 @@ describe('API test', () => {
15791577
const spyon_appsync_realtime = jest
15801578
.spyOn(
15811579
AWSAppSyncRealTimeProvider.prototype as any,
1582-
'_initializeRetryableHandshake',
1580+
'_establishRetryableConnection',
15831581
)
15841582
.mockImplementation(
15851583
jest.fn(() => {

0 commit comments

Comments
 (0)