Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: sync console-preview with next/main (#12178)
Browse files Browse the repository at this point in the history
HuiSF authored Oct 3, 2023
2 parents 11cf989 + 4dbf4db commit b5a42af
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
@@ -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,
},
},
};
});
@@ -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"'
);
});

@@ -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"'
);
});

@@ -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"'
);
});

@@ -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"'
);
});

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

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

@@ -1061,7 +1068,7 @@ describe('AWSAppSyncRealTimeProvider', () => {
provider
.subscribe({
appSyncGraphqlEndpoint: 'ws://localhost:8080',
authenticationType: { type: 'custom' },
authenticationType: 'none',
additionalHeaders: {
Authorization: '',
},
36 changes: 17 additions & 19 deletions packages/api-graphql/__tests__/utils/expects.ts
Original file line number Diff line number Diff line change
@@ -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(
@@ -23,8 +23,8 @@ export function expectMutation(
input: expect.objectContaining(item),
}),
}),
})
);
}),
});
}

/**
@@ -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),
}),
})
);
}),
});
}

/**
@@ -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),
}),
})
);
}),
});
}

/**
@@ -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)`
Loading

0 comments on commit b5a42af

Please sign in to comment.