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