-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws-deploy-test.ts
59 lines (44 loc) · 2.16 KB
/
aws-deploy-test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import HttpServerMock = require("http-server-mock");
import expect from "../helpers/expect";
import * as awsMock from "../helpers/aws-mocks";
import runWithEnv from "../helpers/tool-runner-helpers";
const server = new HttpServerMock();
const run = (...args: string[]) => runWithEnv(server.proxyEnv, ...args);
describe("Dev-Bot tool AWS deploy", function () {
this.timeout(5000);
let iam: awsMock.IamMock;
let lambda: awsMock.LambdaMock;
let events: awsMock.CloudWatchEventsMock;
beforeEach(async () => {
await server.start();
iam = new awsMock.IamMock(server);
lambda = new awsMock.LambdaMock(server);
events = new awsMock.CloudWatchEventsMock(server);
});
afterEach(async () => {
await server.stop();
});
it("pushes a new bot to lambda, if the bot doesn't exist", async () => {
iam.onGetRole("autogenerated-dev-bot-role").findRole();
lambda.onGetFunction("testbot").dontFindFunction();
lambda.onCreateFunction("testbot").succeedWithArn("arn:new-bot");
events.onListRuleNamesByTarget("arn:new-bot").findNoRuleNames();
events.onPutRule("dev-bot-trigger-testbot", {
ScheduleExpression: "rate(1 minute)"
}).succeedWithArn("arn:new-role");
lambda.onAddPermission("arn:new-bot", "lambda:InvokeFunction", "events.amazonaws.com").succeed();
events.onPutTargets("dev-bot-trigger-testbot", {Arn: "arn:new-bot"}).succeed();
let output = await run("aws-deploy", "testbot");
expect(output).to.include("Deploying testbot to AWS");
expect(output).to.match(/\nDone.\n$/);
});
it("updates lambda with the new code, if the bot already exits", async () => {
iam.onGetRole("autogenerated-dev-bot-role").findRole();
lambda.onGetFunction("testbot").findFunction("arn:updated-bot");
lambda.onUpdateFunctionCode("testbot").succeed();
events.onListRuleNamesByTarget("arn:updated-bot").findRuleNames(["dev-bot-trigger"]);
let output = await run("aws-deploy", "testbot");
expect(output).to.include("Deploying testbot to AWS");
expect(output).to.match(/\nDone.\n$/);
});
});