Skip to content

Commit

Permalink
Merge branch 'next/main' into console-preview
Browse files Browse the repository at this point in the history
  • Loading branch information
HuiSF committed Oct 3, 2023
2 parents 11cf989 + a26f692 commit 4dbf4db
Show file tree
Hide file tree
Showing 104 changed files with 2,239 additions and 1,905 deletions.
51 changes: 29 additions & 22 deletions packages/api-graphql/__tests__/AWSAppSyncRealTimeProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,26 @@ jest.mock('@aws-amplify/core/internals/aws-client-utils', () => {
// Mock all calls to signRequest
jest.mock('@aws-amplify/core', () => {
const original = jest.requireActual('@aws-amplify/core');
const session = {
tokens: {
accessToken: {
toString: () => 'test',
},
},
credentials: {
accessKeyId: 'test',
secretAccessKey: 'test',
},
};
return {
...original,
fetchAuthSession: (_request, _options) => {
return Promise.resolve({
tokens: {
accessToken: {
toString: () => 'test',
},
},
credentials: {
accessKeyId: 'test',
secretAccessKey: 'test',
},
});
return Promise.resolve(session);
},
Amplify: {
Auth: {
fetchAuthSession: async () => session,
},
},
};
});
Expand Down Expand Up @@ -969,15 +975,16 @@ describe('AWSAppSyncRealTimeProvider', () => {
provider
.subscribe({
appSyncGraphqlEndpoint: 'ws://localhost:8080',
authenticationType: { type: 'apiKey', apiKey: 'test' },
authenticationType: 'apiKey',
apiKey: 'test',
})
.subscribe({ error: () => {} });

await fakeWebSocketInterface?.readyForUse;

expect(loggerSpy).toBeCalledWith(
'DEBUG',
'Authenticating with {"type":"apiKey","apiKey":"test"}'
'Authenticating with "apiKey"'
);
});

Expand All @@ -987,15 +994,15 @@ describe('AWSAppSyncRealTimeProvider', () => {
provider
.subscribe({
appSyncGraphqlEndpoint: 'ws://localhost:8080',
authenticationType: { type: 'iam' },
authenticationType: 'iam',
})
.subscribe({ error: () => {} });

await fakeWebSocketInterface?.readyForUse;

expect(loggerSpy).toBeCalledWith(
'DEBUG',
'Authenticating with {"type":"iam"}'
'Authenticating with "iam"'
);
});

Expand All @@ -1005,15 +1012,15 @@ describe('AWSAppSyncRealTimeProvider', () => {
provider
.subscribe({
appSyncGraphqlEndpoint: 'ws://localhost:8080',
authenticationType: { type: 'jwt', token: 'id' },
authenticationType: 'oidc',
})
.subscribe({ error: () => {} });

await fakeWebSocketInterface?.readyForUse;

expect(loggerSpy).toBeCalledWith(
'DEBUG',
'Authenticating with {"type":"jwt","token":"id"}'
'Authenticating with "oidc"'
);
});

Expand All @@ -1023,14 +1030,14 @@ describe('AWSAppSyncRealTimeProvider', () => {
provider
.subscribe({
appSyncGraphqlEndpoint: 'ws://localhost:8080',
authenticationType: { type: 'jwt', token: 'id' },
authenticationType: 'oidc',
})
.subscribe({ error: () => {} });

await fakeWebSocketInterface?.readyForUse;
expect(loggerSpy).toBeCalledWith(
'DEBUG',
'Authenticating with {"type":"jwt","token":"id"}'
'Authenticating with "oidc"'
);
});

Expand All @@ -1040,7 +1047,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
provider
.subscribe({
appSyncGraphqlEndpoint: 'ws://localhost:8080',
authenticationType: { type: 'custom' },
authenticationType: 'none',
additionalHeaders: {
Authorization: 'test',
},
Expand All @@ -1051,7 +1058,7 @@ describe('AWSAppSyncRealTimeProvider', () => {

expect(loggerSpy).toBeCalledWith(
'DEBUG',
'Authenticating with {"type":"custom"}'
'Authenticating with "none"'
);
});

Expand All @@ -1061,7 +1068,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
provider
.subscribe({
appSyncGraphqlEndpoint: 'ws://localhost:8080',
authenticationType: { type: 'custom' },
authenticationType: 'none',
additionalHeaders: {
Authorization: '',
},
Expand Down
36 changes: 17 additions & 19 deletions packages/api-graphql/__tests__/utils/expects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export function expectMutation(
opName: string,
item: Record<string, any>
) {
expect(spy).toHaveBeenCalledWith(
'https://localhost/graphql',
expect.objectContaining({
expect(spy).toHaveBeenCalledWith({
url: new URL('https://localhost/graphql'),
options: expect.objectContaining({
headers: expect.objectContaining({ 'X-Api-Key': 'FAKE-KEY' }),
body: expect.objectContaining({
query: expect.stringContaining(
Expand All @@ -23,8 +23,8 @@ export function expectMutation(
input: expect.objectContaining(item),
}),
}),
})
);
}),
});
}

/**
Expand All @@ -40,16 +40,16 @@ export function expectGet(
opName: string,
item: Record<string, any>
) {
expect(spy).toHaveBeenCalledWith(
'https://localhost/graphql',
expect.objectContaining({
expect(spy).toHaveBeenCalledWith({
url: new URL('https://localhost/graphql'),
options: expect.objectContaining({
headers: expect.objectContaining({ 'X-Api-Key': 'FAKE-KEY' }),
body: expect.objectContaining({
query: expect.stringContaining(`${opName}(id: $id)`),
variables: expect.objectContaining(item),
}),
})
);
}),
});
}

/**
Expand All @@ -65,18 +65,18 @@ export function expectList(
opName: string,
item: Record<string, any>
) {
expect(spy).toHaveBeenCalledWith(
'https://localhost/graphql',
expect.objectContaining({
expect(spy).toHaveBeenCalledWith({
url: new URL('https://localhost/graphql'),
options: expect.objectContaining({
headers: expect.objectContaining({ 'X-Api-Key': 'FAKE-KEY' }),
body: expect.objectContaining({
query: expect.stringContaining(
`${opName}(filter: $filter, limit: $limit, nextToken: $nextToken)`
),
variables: expect.objectContaining(item),
}),
})
);
}),
});
}

/**
Expand All @@ -94,10 +94,8 @@ export function expectSub(
) {
expect(spy).toHaveBeenCalledWith(
expect.objectContaining({
authenticationType: {
apiKey: 'FAKE-KEY',
type: 'apiKey',
},
authenticationType: 'apiKey',
apiKey: 'FAKE-KEY',
appSyncGraphqlEndpoint: 'https://localhost/graphql',
query: expect.stringContaining(
`${opName}(filter: $filter, owner: $owner)`
Expand Down
Loading

0 comments on commit 4dbf4db

Please sign in to comment.