Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(apigatewayv2): support for mock integration type #18129

Merged
merged 6 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
re-implement after fast-forwarding
  • Loading branch information
atchla committed Dec 22, 2021
commit 52b8b61fd56a210b25a95f44e15eb42328a4b802
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
import {
IWebSocketRouteIntegration,
WebSocketRouteIntegration,
WebSocketIntegrationType,
WebSocketRouteIntegrationBindOptions,
WebSocketRouteIntegrationConfig,
WebSocketRouteIntegrationBindOptions,
} from '@aws-cdk/aws-apigatewayv2';

/**
* Mock WebSocket Integration props
* Mock WebSocket Integration
*/
export interface MockWebSocketIntegrationProps {
// TODO: any props?
export class MockWebSocketIntegration extends WebSocketRouteIntegration {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the naming convention we've established, this class should be called WebSocketMockIntegration.


/**
* Prop description
* @param id id of the underlying integration construct
*/
//readonly prop: IFunction
}

/**
* Mock WebSocket Integration
*/
export class MockWebSocketIntegration implements IWebSocketRouteIntegration {
constructor(private props: MockWebSocketIntegrationProps) {}
constructor(id: string) {
super(id);
}

bind(options: WebSocketRouteIntegrationBindOptions): WebSocketRouteIntegrationConfig {
options; this.props;
options;
return {
type: WebSocketIntegrationType.MOCK,
uri: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"RouteSelectionExpression": "$request.body.action"
}
},
"mywsapiconnectRouteWebSocketIntegration127d0ae2db4af590bf857fb7403b7d4d61CE41B6": {
"mywsapidefaultRouteDefaultIntegrationFFCB3BA9": {
"Type": "AWS::ApiGatewayV2::Integration",
"Properties": {
"ApiId": {
Expand All @@ -18,64 +18,35 @@
"IntegrationUri": ""
}
},
"mywsapiconnectRoute45A0ED6A": {
"Type": "AWS::ApiGatewayV2::Route",
"Properties": {
"ApiId": {
"Ref": "mywsapi32E6CE11"
},
"RouteKey": "$connect",
"Target": {
"Fn::Join": [
"",
[
"integrations/",
{
"Ref": "mywsapiconnectRouteWebSocketIntegration127d0ae2db4af590bf857fb7403b7d4d61CE41B6"
}
]
]
}
}
},
"mywsapidisconnectRoute421A8CB9": {
"mywsapidefaultRouteE9382DF8": {
"Type": "AWS::ApiGatewayV2::Route",
"Properties": {
"ApiId": {
"Ref": "mywsapi32E6CE11"
},
"RouteKey": "$disconnect",
"RouteKey": "$default",
"AuthorizationType": "NONE",
"Target": {
"Fn::Join": [
"",
[
"integrations/",
{
"Ref": "mywsapiconnectRouteWebSocketIntegration127d0ae2db4af590bf857fb7403b7d4d61CE41B6"
"Ref": "mywsapidefaultRouteDefaultIntegrationFFCB3BA9"
}
]
]
}
}
},
"mywsapidefaultRouteE9382DF8": {
"Type": "AWS::ApiGatewayV2::Route",
"mywsapisendmessageRouteSendMessageIntegrationD29E12F9": {
"Type": "AWS::ApiGatewayV2::Integration",
"Properties": {
"ApiId": {
"Ref": "mywsapi32E6CE11"
},
"RouteKey": "$default",
"Target": {
"Fn::Join": [
"",
[
"integrations/",
{
"Ref": "mywsapiconnectRouteWebSocketIntegration127d0ae2db4af590bf857fb7403b7d4d61CE41B6"
}
]
]
}
"IntegrationType": "MOCK",
"IntegrationUri": ""
}
},
"mywsapisendmessageRouteAE873328": {
Expand All @@ -85,13 +56,14 @@
"Ref": "mywsapi32E6CE11"
},
"RouteKey": "sendmessage",
"AuthorizationType": "NONE",
"Target": {
"Fn::Join": [
"",
[
"integrations/",
{
"Ref": "mywsapiconnectRouteWebSocketIntegration127d0ae2db4af590bf857fb7403b7d4d61CE41B6"
"Ref": "mywsapisendmessageRouteSendMessageIntegrationD29E12F9"
}
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,21 @@ import { MockWebSocketIntegration } from '../../lib';

/*
* Stack verification steps:
* 1. Connect: 'wscat -c <endpoint-in-the-stack-output>'. Should connect successfully and print event data containing connectionId in cloudwatch
* 2. SendMessage: '> {"action": "sendmessage", "data": "some-data"}'. Should send the message successfully
* 3. Default: '> {"data": "some-data"}'. Should send the message successfully
* 4. Disconnect: disconnect from the wscat. Should disconnect successfully
* 1. Verify manually that the integration has type "MOCK"
*/

const app = new App();
const stack = new Stack(app, 'integ-mock-websocket-integration');

const webSocketApi = new WebSocketApi(stack, 'mywsapi', {
connectRouteOptions: { integration: new MockWebSocketIntegration({ }) },
disconnectRouteOptions: { integration: new MockWebSocketIntegration({ }) },
defaultRouteOptions: { integration: new MockWebSocketIntegration({ }) },
defaultRouteOptions: { integration: new MockWebSocketIntegration('DefaultIntegration') },
});
const stage = new WebSocketStage(stack, 'mystage', {
webSocketApi,
stageName: 'dev',
autoDeploy: true,
});

webSocketApi.addRoute('sendmessage', { integration: new MockWebSocketIntegration({ }) });
webSocketApi.addRoute('sendmessage', { integration: new MockWebSocketIntegration('SendMessageIntegration') });

new CfnOutput(stack, 'ApiEndpoint', { value: stage.url });
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ describe('MockWebSocketIntegration', () => {

// WHEN
new WebSocketApi(stack, 'Api', {
connectRouteOptions: {
integration: new MockWebSocketIntegration({}),
},
defaultRouteOptions: { integration: new MockWebSocketIntegration('DefaultIntegration') },
});

// THEN
Expand Down