Skip to content

Commit

Permalink
Merge branch 'main' into temp/release-merge-1729882564
Browse files Browse the repository at this point in the history
  • Loading branch information
ashika112 authored Oct 28, 2024
2 parents f2248ad + c19b2f3 commit 6c7cdcf
Show file tree
Hide file tree
Showing 25 changed files with 2,470 additions and 1,212 deletions.
50 changes: 25 additions & 25 deletions packages/api-graphql/__tests__/AWSAppSyncRealTimeProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { ConnectionState as CS } from '../src/types/PubSub';

import { AWSAppSyncRealTimeProvider } from '../src/Providers/AWSAppSyncRealTimeProvider';
import { isCustomDomain } from '../src/Providers/AWSWebSocketProvider/appsyncUrl';

// Mock all calls to signRequest
jest.mock('@aws-amplify/core/internals/aws-client-utils', () => {
Expand All @@ -20,7 +21,7 @@ jest.mock('@aws-amplify/core/internals/aws-client-utils', () => {
);
return {
...original,
signRequest: (_request, _options) => {
signRequest: (_request: any, _options: any) => {
return {
method: 'test',
headers: { test: 'test' },
Expand All @@ -46,7 +47,7 @@ jest.mock('@aws-amplify/core', () => {
};
return {
...original,
fetchAuthSession: (_request, _options) => {
fetchAuthSession: (_request: any, _options: any) => {
return Promise.resolve(session);
},
Amplify: {
Expand All @@ -66,24 +67,19 @@ jest.mock('@aws-amplify/core', () => {
describe('AWSAppSyncRealTimeProvider', () => {
describe('isCustomDomain()', () => {
test('Custom domain returns `true`', () => {
const provider = new AWSAppSyncRealTimeProvider();
const result = (provider as any).isCustomDomain(
'https://unit-test.testurl.com/graphql',
);
const result = isCustomDomain('https://unit-test.testurl.com/graphql');
expect(result).toBe(true);
});

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

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

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

const newSocketSpy = jest
.spyOn(provider, 'getNewWebSocket')
.spyOn(provider as any, '_getNewWebSocket')
.mockImplementation(() => {
fakeWebSocketInterface.newWebSocket();
return fakeWebSocketInterface.webSocket as WebSocket;
Expand All @@ -254,7 +252,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
expect.assertions(1);

const newSocketSpy = jest
.spyOn(provider, 'getNewWebSocket')
.spyOn(provider as any, '_getNewWebSocket')
.mockImplementation(() => {
fakeWebSocketInterface.newWebSocket();
return fakeWebSocketInterface.webSocket as WebSocket;
Expand All @@ -280,7 +278,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
expect.assertions(1);

const newSocketSpy = jest
.spyOn(provider, 'getNewWebSocket')
.spyOn(provider as any, '_getNewWebSocket')
.mockImplementation(() => {
fakeWebSocketInterface.newWebSocket();
return fakeWebSocketInterface.webSocket as WebSocket;
Expand All @@ -307,7 +305,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
expect.assertions(1);

const newSocketSpy = jest
.spyOn(provider, 'getNewWebSocket')
.spyOn(provider as any, '_getNewWebSocket')
.mockImplementation(() => {
fakeWebSocketInterface.newWebSocket();
return fakeWebSocketInterface.webSocket;
Expand Down Expand Up @@ -349,7 +347,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
expect.assertions(1);

const newSocketSpy = jest
.spyOn(provider, 'getNewWebSocket')
.spyOn(provider as any, '_getNewWebSocket')
.mockImplementation(() => {
fakeWebSocketInterface.newWebSocket();
return fakeWebSocketInterface.webSocket;
Expand Down Expand Up @@ -545,7 +543,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
await fakeWebSocketInterface?.standardConnectionHandshake();

await fakeWebSocketInterface?.sendDataMessage({
type: MESSAGE_TYPES.GQL_DATA,
type: MESSAGE_TYPES.DATA,
payload: { data: {} },
});

Expand All @@ -571,7 +569,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
connectionTimeoutMs: 100,
});
await fakeWebSocketInterface?.sendDataMessage({
type: MESSAGE_TYPES.GQL_DATA,
type: MESSAGE_TYPES.DATA,
payload: { data: {} },
});

Expand All @@ -597,7 +595,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
connectionTimeoutMs: 100,
});
await fakeWebSocketInterface?.sendDataMessage({
type: MESSAGE_TYPES.GQL_DATA,
type: MESSAGE_TYPES.DATA,
payload: { data: {} },
});
expect(mockNext).toHaveBeenCalled();
Expand Down Expand Up @@ -677,7 +675,9 @@ describe('AWSAppSyncRealTimeProvider', () => {
}),
);

expect(socketCloseSpy).toHaveBeenNthCalledWith(1, 3001);
await delay(1);

expect(socketCloseSpy).toHaveBeenCalledWith(3001);
});

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

await fakeWebSocketInterface?.standardConnectionHandshake();
await fakeWebSocketInterface?.sendDataMessage({
type: MESSAGE_TYPES.GQL_DATA,
type: MESSAGE_TYPES.DATA,
payload: { data: {} },
});
await subscription.unsubscribe();
Expand Down Expand Up @@ -1181,7 +1181,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
});

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

provider
.subscribe({
Expand Down
10 changes: 4 additions & 6 deletions packages/api-graphql/__tests__/GraphQLAPI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { Amplify as AmplifyCore } from '@aws-amplify/core';
import * as typedQueries from './fixtures/with-types/queries';
import * as typedSubscriptions from './fixtures/with-types/subscriptions';
import { expectGet } from './utils/expects';
import { InternalGraphQLAPIClass } from '../src/internals/InternalGraphQLAPI';
import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
import { INTERNAL_USER_AGENT_OVERRIDE } from '@aws-amplify/data-schema/runtime';
import * as graphqlAuth from '../src/internals/graphqlAuth';

import {
__amplify,
Expand Down Expand Up @@ -1489,10 +1489,7 @@ describe('API test', () => {
},
};

const spy = jest.spyOn(
InternalGraphQLAPIClass.prototype as any,
'_headerBasedAuth',
);
const spy = jest.spyOn(graphqlAuth, 'headerBasedAuth');

const spy2 = jest
.spyOn((raw.GraphQLAPI as any)._api, 'post')
Expand All @@ -1515,6 +1512,7 @@ describe('API test', () => {
getConfig: expect.any(Function),
}),
'iam',
'FAKE-KEY',
{},
);
});
Expand Down Expand Up @@ -1579,7 +1577,7 @@ describe('API test', () => {
const spyon_appsync_realtime = jest
.spyOn(
AWSAppSyncRealTimeProvider.prototype as any,
'_initializeRetryableHandshake',
'_establishRetryableConnection',
)
.mockImplementation(
jest.fn(() => {
Expand Down
Loading

0 comments on commit 6c7cdcf

Please sign in to comment.