1 | const expect = require( "chai" ).expect;
|
2 | const assert = require( "chai" ).assert;
|
3 | const sinon = require( "sinon" );
|
4 | const fs = require( "fs" );
|
5 |
|
6 | const runLambda = require( "../lib/run-lambda" );
|
7 |
|
8 | describe( "colly run-lambda", () => {
|
9 |
|
10 | it( "should fetch the correct event file", () => {
|
11 |
|
12 | process.env.COLLY__PROJECT_DIR = `./test`;
|
13 | process.env.COLLY__LAMBDA_EVENT_FILE = "fixtures/run-lambda/basicMessage.json";
|
14 |
|
15 | const expectedEvent = {
|
16 | "message": "Hello there"
|
17 | }
|
18 |
|
19 | expect( runLambda.getLambdaEventFile() ).to.deep.equal( expectedEvent );
|
20 |
|
21 | } );
|
22 |
|
23 | it( "should fetch the correct context file", ( done )=> {
|
24 |
|
25 | process.env.COLLY__PROJECT_DIR = `${process.cwd()}/test`;
|
26 | process.env.COLLY__LAMBDA_CONTEXT_FILE = "fixtures/run-lambda/basicContext.js";
|
27 |
|
28 | expect( runLambda.getLambdaContextFile().done() ).to.deep.equal( "contents of done function" );
|
29 | done();
|
30 |
|
31 | });
|
32 |
|
33 | it( "should work out whether to run the local or deployed version of the lambda", () => {
|
34 |
|
35 | process.env.COLLY__RUN_LAMBDA_LOCAL = "true";
|
36 | assert.isTrue( runLambda.runningLocally() );
|
37 |
|
38 | process.env.COLLY__RUN_LAMBDA_LOCAL = "false";
|
39 | assert.isNotTrue( runLambda.runningLocally() );
|
40 |
|
41 | } );
|
42 |
|
43 | it( "should run the lambda", ( done ) => {
|
44 |
|
45 | process.env.ENV = "live";
|
46 | process.env.COLLY__LAMBDA_NAME = "myLambda";
|
47 | process.env.COLLY__PROJECT_DIR = `${process.cwd()}/test/fixtures/run-lambda`;
|
48 | process.env.COLLY__LAMBDA_EVENT_FILE = "basicMessage.json";
|
49 |
|
50 | runLambda.runLocally()
|
51 | .then( ( data ) => {
|
52 |
|
53 | expect( data ).to.equal( "Hello there" );
|
54 | done();
|
55 |
|
56 | })
|
57 | .catch( ( err ) => {
|
58 | console.log( err );
|
59 | assert.fail();
|
60 | done();
|
61 | })
|
62 |
|
63 | } );
|
64 |
|
65 | }); |
\ | No newline at end of file |