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

ADO-25882 - Lex V2 Provisioning Tooling #14

Merged
merged 1 commit into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
37 changes: 26 additions & 11 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-non-null-asserted-optional-chain": "off"
},
"extends": [
"env": {
"browser": true,
"node": true
},
"root": true,
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended"
],
"overrides": [
{
"files": ["**/*.ts", "**/*.tsx"],
"env": { "browser": true, "es6": true, "node": true },
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
]
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"rules": {
"indent": ["error", 2, { "SwitchCase": 1 }],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"comma-dangle": ["error", "always-multiline"],
"@typescript-eslint/no-explicit-any": 0
}
}
]
}
36 changes: 36 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Unit Tests
on:
push:
branches:
- master
pull_request:
branches:
- master
- lex-v2-integration
jobs:
unit-tests:
defaults:
run:
shell: bash
working-directory: ${{ github.workspace }}
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
with:
fetch-depth: 100
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('../yarn.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('../yarn.lock') }}
- name: Yarn Install
run: yarn install
- name: EsLint
run: yarn lint
- name: Run Tests
run: yarn test --color --verbose true --silent
2 changes: 1 addition & 1 deletion __fixtures__/v2/events/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export default {
create,
delete: deleteEvent,
unknown,
update
update,
};
4 changes: 2 additions & 2 deletions __fixtures__/v2/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import botAlias from './bot-alias';
import botLocale from './bot-locale';
import botVersion from './bot-version';
import intent from './intent';
import intentPriority from './intent-priority';
import slot from './slot';
import slotType from './slot-type';
import intentPriority from './intent-priority';

export default {
bot,
Expand All @@ -15,5 +15,5 @@ export default {
intent,
intentPriority,
slot,
slotType
slotType,
};
2 changes: 1 addition & 1 deletion __fixtures__/v2/events/intent-priority/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import update from './update.json';
export default {
create,
unknown,
update
update,
};
2 changes: 1 addition & 1 deletion __fixtures__/v2/events/intent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export default {
create,
delete: deleteEvent,
unknown,
update
update,
};
2 changes: 1 addition & 1 deletion __fixtures__/v2/events/slot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export default {
create,
delete: deleteEvent,
unknown,
update
update,
};
54 changes: 32 additions & 22 deletions __tests__/cdk/custom-resources-base-stack.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import {
countResources,
expect as expectCDK,
countResources
} from '@aws-cdk/assert';
import { Role, ServicePrincipal } from '@aws-cdk/aws-iam';
import { InlineCode, Runtime } from '@aws-cdk/aws-lambda';
import {
Role,
ServicePrincipal,
} from '@aws-cdk/aws-iam';
import {
InlineCode,
Runtime,
} from '@aws-cdk/aws-lambda';
import * as cdk from '@aws-cdk/core';
import { CustomResourceBaseStack } from '../../src/lex-custom-cdk-resources';

import { CustomResourceBaseStack } from '../../src/lex-custom-cdk-resources';

describe('CDK Custom Resources Base Stack', () => {
describe('Can create the default stack', () => {
Expand All @@ -20,34 +26,38 @@ describe('CDK Custom Resources Base Stack', () => {
stack = new cdk.Stack(app, 'SampleCustomResourcesStack', {
env: {
region: 'us-east-1',
account: '1234567890'
}
account: '1234567890',
},
});

nestedStack = new CustomResourceBaseStack(stack, 'SampleBaseStack',
nestedStack = new CustomResourceBaseStack(
stack,
'SampleBaseStack',
{
region: 'us-east-1',
account: '1234567890'
}, {
exportName: "SampleExportName",
role: new Role(stack, 'SampleRole', {
assumedBy: new ServicePrincipal('lambda.amazonaws.com').grantPrincipal
}),
handler: {
handlerName: "handler",
code: new InlineCode(`
account: '1234567890',
},
{
exportName: 'SampleExportName',
role: new Role(stack, 'SampleRole', {
assumedBy: new ServicePrincipal('lambda.amazonaws.com').grantPrincipal,
}),
handler: {
handlerName: 'handler',
code: new InlineCode(`
def handler(event, context):
return event
`),
timeout: 5,
environment: {},
runtime: Runtime.PYTHON_3_8
}
})
timeout: 5,
environment: {},
runtime: Runtime.PYTHON_3_8,
},
},
);
});

it('Succeeds in building custom handler', () => {
expectCDK(nestedStack).to(countResources("AWS::Lambda::Function", 2));
expectCDK(nestedStack).to(countResources('AWS::Lambda::Function', 2));
});
});
});
144 changes: 73 additions & 71 deletions __tests__/cdk/custom-resources-stack.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
expect as expectCDK,
countResources,
countResourcesLike
countResourcesLike,
expect as expectCDK,
} from '@aws-cdk/assert';
import * as cdk from '@aws-cdk/core';
import { CustomResourcesStack } from '../../src/lex-custom-cdk-resources';

import { CustomResourcesStack } from '../../src/lex-custom-cdk-resources';

describe('CDK Custom Resources Stack', () => {
describe('Can create the default stack', () => {
Expand All @@ -17,34 +17,34 @@ describe('CDK Custom Resources Stack', () => {
stack = new CustomResourcesStack(app, 'SampleCustomResourcesStack', {
env: {
region: 'us-east-1',
account: '1234567890'
account: '1234567890',
},
v2: {
bot: {
enabled: true
enabled: true,
},
botAlias: {
enabled: true
enabled: true,
},
botVersion: {
enabled: true
enabled: true,
},
botLocale: {
enabled: true
enabled: true,
},
intent: {
enabled: true
enabled: true,
},
intentPriority: {
enabled: true
enabled: true,
},
slot: {
enabled: true
enabled: true,
},
slotType: {
enabled: true
}
}
enabled: true,
},
},
});
});

Expand All @@ -53,63 +53,65 @@ describe('CDK Custom Resources Stack', () => {
});

it('Stack contains IAM Policy for Lex V2', () => {
expectCDK(stack).to(countResourcesLike('AWS::IAM::Policy', 1, {
PolicyDocument: {
Statement: [
{
Action: [
"lex:BuildBotLocale",
"lex:CreateBot",
"lex:CreateBotAlias",
"lex:CreateBotChannel",
"lex:CreateBotLocale",
"lex:CreateBotVersion",
"lex:CreateIntent",
"lex:CreateResourcePolicy",
"lex:CreateSlot",
"lex:CreateSlotType",
"lex:DeleteBot",
"lex:DeleteBotAlias",
"lex:DeleteBotChannel",
"lex:DeleteBotLocale",
"lex:DeleteBotVersion",
"lex:DeleteIntent",
"lex:DeleteResourcePolicy",
"lex:DeleteSlot",
"lex:DeleteSlotType",
"lex:DescribeBot",
"lex:DescribeBotAlias",
"lex:DescribeBotChannel",
"lex:DescribeBotLocale",
"lex:DescribeBotVersion",
"lex:DescribeIntent",
"lex:DescribeResourcePolicy",
"lex:DescribeSlot",
"lex:DescribeSlotType",
"lex:ListBotAliases",
"lex:ListBotChannels",
"lex:ListBotLocales",
"lex:ListBotVersions",
"lex:ListBots",
"lex:ListIntents",
"lex:ListSlotTypes",
"lex:ListSlots",
"lex:ListTagsForResource",
"lex:TagResource",
"lex:UntagResource",
"lex:UpdateBot",
"lex:UpdateBotAlias",
"lex:UpdateBotLocale",
"lex:UpdateExport",
"lex:UpdateIntent",
"lex:UpdateResourcePolicy",
"lex:UpdateSlot",
"lex:UpdateSlotType",
]
}
]
}
}));
expectCDK(stack).to(
countResourcesLike('AWS::IAM::Policy', 1, {
PolicyDocument: {
Statement: [
{
Action: [
'lex:BuildBotLocale',
'lex:CreateBot',
'lex:CreateBotAlias',
'lex:CreateBotChannel',
'lex:CreateBotLocale',
'lex:CreateBotVersion',
'lex:CreateIntent',
'lex:CreateResourcePolicy',
'lex:CreateSlot',
'lex:CreateSlotType',
'lex:DeleteBot',
'lex:DeleteBotAlias',
'lex:DeleteBotChannel',
'lex:DeleteBotLocale',
'lex:DeleteBotVersion',
'lex:DeleteIntent',
'lex:DeleteResourcePolicy',
'lex:DeleteSlot',
'lex:DeleteSlotType',
'lex:DescribeBot',
'lex:DescribeBotAlias',
'lex:DescribeBotChannel',
'lex:DescribeBotLocale',
'lex:DescribeBotVersion',
'lex:DescribeIntent',
'lex:DescribeResourcePolicy',
'lex:DescribeSlot',
'lex:DescribeSlotType',
'lex:ListBotAliases',
'lex:ListBotChannels',
'lex:ListBotLocales',
'lex:ListBotVersions',
'lex:ListBots',
'lex:ListIntents',
'lex:ListSlotTypes',
'lex:ListSlots',
'lex:ListTagsForResource',
'lex:TagResource',
'lex:UntagResource',
'lex:UpdateBot',
'lex:UpdateBotAlias',
'lex:UpdateBotLocale',
'lex:UpdateExport',
'lex:UpdateIntent',
'lex:UpdateResourcePolicy',
'lex:UpdateSlot',
'lex:UpdateSlotType',
],
},
],
},
}),
);
});

it('Stack contains IAM Role for Lex V2', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/setup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import nock from 'nock';

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export default async () => {
// globally disable HTTP requests in the test suite
nock.disableNetConnect();
Expand Down
Loading