fintalk-pkg 2.3.20 → 2.3.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ name: Publish Package to npmjs
2
+ on:
3
+ push:
4
+ branches:
5
+ - master
6
+ jobs:
7
+ build:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/checkout@v3
11
+ - uses: actions/setup-node@v3
12
+ with:
13
+ node-version: '16.x'
14
+ registry-url: 'https://registry.npmjs.org'
15
+ - run: npm ci
16
+ - run: npm publish
17
+ env:
18
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fintalk-pkg",
3
- "version": "2.3.20",
3
+ "version": "2.3.21",
4
4
  "description": "Common code between projects",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,11 +9,11 @@
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "git+https://thiagoananias@bitbucket.org/thiagoananias/botpkg.git"
12
+ "url": "git+https://https://github.com/fintalk-ai/fintalk-pkg"
13
13
  },
14
14
  "author": "",
15
15
  "license": "ISC",
16
- "homepage": "https://bitbucket.org/thiagoananias/botpkg#readme",
16
+ "homepage": "https://github.com/fintalk-ai/fintalk-pkg",
17
17
  "devDependencies": {
18
18
  "chai": "^4.2.0",
19
19
  "eslint": "^5.10.0",
@@ -26,11 +26,5 @@
26
26
  "dependencies": {
27
27
  "dynamoose": "~2.3.0",
28
28
  "fintalk-logger": "~1.1.3"
29
- },
30
- "pre-commit": {
31
- "run": [
32
- "eslint",
33
- "test"
34
- ]
35
29
  }
36
30
  }
@@ -1,68 +0,0 @@
1
- "use strict";
2
-
3
- require("dotenv").config();
4
-
5
- const expect = require("chai").expect;
6
- const mocha = require("mocha");
7
- const _sinon = require("sinon");
8
- const BaseController = require("../base/BaseController");
9
-
10
- process.env.TEST = true;
11
-
12
- mocha.describe("Base Controller tests", function() {
13
-
14
- var sinon;
15
-
16
- let mockEvent = {"headers":{"Host":"localhost:3000","Connection":"keep-alive","Cache-Control":"max-age=0","Upgrade-Insecure-Requests":"1","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36","Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","Accept-Encoding":"gzip, deflate, br","Accept-Language":"en-US,en;q=0.9,pt;q=0.8"},"multiValueHeaders":{"Host":["localhost:3000"],"Connection":["keep-alive"],"Cache-Control":["max-age=0"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"],"Accept-Encoding":["gzip, deflate, br"],"Accept-Language":["en-US,en;q=0.9,pt;q=0.8"]},"path":"/hello","pathParameters":null,"requestContext":{"accountId":"offlineContext_accountId","resourceId":"offlineContext_resourceId","apiId":"offlineContext_apiId","stage":"dev","requestId":"offlineContext_requestId_9677288948126226","identity":{"cognitoIdentityPoolId":"offlineContext_cognitoIdentityPoolId","accountId":"offlineContext_accountId","cognitoIdentityId":"offlineContext_cognitoIdentityId","caller":"offlineContext_caller","apiKey":"offlineContext_apiKey","sourceIp":"127.0.0.1","cognitoAuthenticationType":"offlineContext_cognitoAuthenticationType","cognitoAuthenticationProvider":"offlineContext_cognitoAuthenticationProvider","userArn":"offlineContext_userArn","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36","user":"offlineContext_user"},"authorizer":{"principalId":"offlineContext_authorizer_principalId"},"protocol":"HTTP/1.1","resourcePath":"/hello","httpMethod":"GET"},"resource":"/hello","httpMethod":"GET","queryStringParameters":null,"multiValueQueryStringParameters":null,"stageVariables":null,"body":null,"isOffline":true};
17
- let mockContext = {"functionName":"bot-tef-dev-hello","functionVersion":"offline_functionVersion_for_bot-tef-dev-hello","invokedFunctionArn":"offline_invokedFunctionArn_for_bot-tef-dev-hello","awsRequestId":"offline_awsRequestId_016889162478487707","logGroupName":"offline_logGroupName_for_bot-tef-dev-hello","logStreamName":"offline_logStreamName_for_bot-tef-dev-hello","identity":{},"clientContext":{}};
18
-
19
- mocha.beforeEach(function () {
20
- sinon = _sinon.createSandbox();
21
- });
22
-
23
- mocha.afterEach(function () {
24
- // Restore all the things made through the sandbox
25
- sinon.restore();
26
- });
27
-
28
- mocha.it("Test coldstart with database connection", (done) => {
29
- //let connectStub = sinon.stub(flow, "connectDB").returns(null);
30
- let controller = new BaseController(mockEvent, mockContext, null, true, true);
31
-
32
- expect(controller.http).to.be.equal(true);
33
- expect(controller.coldStart).to.be.equal(true);
34
- //expect(connectStub.callCount).to.be.equal(1);
35
-
36
- done();
37
- });
38
-
39
- //WHEN IT NOT A COLDSTART THE DATABASE DOES NOT NEED TO CONNECT
40
- mocha.it("Test coldstart with no database connection", (done) => {
41
-
42
- mockEvent.processId= "1";
43
-
44
- //let connectStub = sinon.stub(flow, "connectDB").returns(null);
45
- sinon.stub(BaseController.prototype, "getColdStart").returns(false);
46
- let controller = new BaseController(mockEvent, mockContext, null, false, true);
47
-
48
- expect(controller.http).to.be.equal(false);
49
- expect(controller.coldStart).to.be.equal(false);
50
- //expect(connectStub.callCount).to.be.equal(0);
51
-
52
- done();
53
- });
54
-
55
- mocha.it("Test coldstart with no database connection", (done) => {
56
-
57
- mockEvent.source = "serverless-plugin-warmup";
58
-
59
- //let connectStub = sinon.stub(flow, "connectDB").returns(null);
60
- let controller = new BaseController(mockEvent, mockContext, function a() {}, false, true);
61
-
62
- expect(controller.statusCode).to.be.equal(200);
63
- //expect(connectStub.callCount).to.be.equal(0);
64
-
65
- done();
66
- });
67
-
68
- });
package/test/flow-test.js DELETED
@@ -1,113 +0,0 @@
1
- "use strict";
2
-
3
- require("dotenv").config();
4
-
5
- const expect = require("chai").expect;
6
- const mocha = require("mocha");
7
- const flow = require("../base/FlowControl");
8
- const logger = require("../base/Logger");
9
- const _sinon = require("sinon");
10
-
11
- process.env.TEST = true;
12
-
13
- mocha.describe("Flow Function tests", function() {
14
-
15
- var sinon;
16
-
17
- mocha.beforeEach(function () {
18
- sinon = _sinon.createSandbox();
19
- });
20
-
21
- mocha.afterEach(function () {
22
- // Restore all the things made through the sandbox
23
- sinon.restore();
24
- });
25
-
26
- mocha.it("Test success method", (done) => {
27
- expect(flow.success("Hello!")).to.be.deep.equal({"statusCode": 200,"body": "Hello!"});
28
- expect(flow.success({ message : "Hello!"}).body).to.be.equal("{\"message\":\"Hello!\"}");
29
- expect(flow.success({ message : "Hello!"}).statusCode).to.be.equal(200);
30
- done();
31
- });
32
-
33
- mocha.it("Test flow error method", (done) => {
34
- expect(flow.error({ error : "Hello!"}).statusCode).to.be.equal(502);
35
- done();
36
- });
37
-
38
- mocha.it("Test custom status code", (done) => {
39
- expect(flow.customStatusCode(505, { error : "Hello!"}, null).statusCode).to.be.equal(505);
40
- done();
41
- });
42
-
43
- mocha.it("Test call log", (done) => {
44
-
45
- let logSpy = sinon.spy(logger, "log");
46
-
47
- flow.setController({"context":{"functionName":"bot-tef-dev-hello","functionVersion":"offline_functionVersion_for_bot-tef-dev-hello","invokedFunctionArn":"offline_invokedFunctionArn_for_bot-tef-dev-hello","awsRequestId":"offline_awsRequestId_7318111093035298","logGroupName":"offline_logGroupName_for_bot-tef-dev-hello","logStreamName":"offline_logStreamName_for_bot-tef-dev-hello","identity":{},"clientContext":{}},"event":{"headers":{"Host":"localhost:3000","Connection":"keep-alive","Upgrade-Insecure-Requests":"1","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36","Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","Accept-Encoding":"gzip, deflate, br","Accept-Language":"en-US,en;q=0.9,pt;q=0.8"},"multiValueHeaders":{"Host":["localhost:3000"],"Connection":["keep-alive"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"],"Accept-Encoding":["gzip, deflate, br"],"Accept-Language":["en-US,en;q=0.9,pt;q=0.8"]},"path":"/hello","pathParameters":null,"requestContext":{"accountId":"offlineContext_accountId","resourceId":"offlineContext_resourceId","apiId":"offlineContext_apiId","stage":"dev","requestId":"offlineContext_requestId_17034407254485173","identity":{"cognitoIdentityPoolId":"offlineContext_cognitoIdentityPoolId","accountId":"offlineContext_accountId","cognitoIdentityId":"offlineContext_cognitoIdentityId","caller":"offlineContext_caller","apiKey":"offlineContext_apiKey","sourceIp":"127.0.0.1","cognitoAuthenticationType":"offlineContext_cognitoAuthenticationType","cognitoAuthenticationProvider":"offlineContext_cognitoAuthenticationProvider","userArn":"offlineContext_userArn","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36","user":"offlineContext_user"},"authorizer":{"principalId":"offlineContext_authorizer_principalId"},"protocol":"HTTP/1.1","resourcePath":"/hello","httpMethod":"GET"},"resource":"/hello","httpMethod":"GET","queryStringParameters": {testParameter: "oi"},"multiValueQueryStringParameters":null,"stageVariables":null,"body":null,"isOffline":true},"http":true,"start": new Date("2018-12-14T13:12:17.165Z"),"coldStart":true,"processId":"e16d62e0-ffa1-11e8-9e57-5b424b3574e1"});
48
- flow.logLambda(200, "success!!");
49
-
50
- var log = logSpy.args[0][0];
51
- log = JSON.parse(log);
52
- delete log.duration;
53
- log.date = new Date(log.date);
54
-
55
- expect(log).to.be.deep.equal({
56
- coldStart: true,
57
- body: {},
58
- httpLog:true,
59
- date: new Date("2018-12-14T13:12:17.165Z"),
60
- method:"GET",
61
- statusCode:200,
62
- path:"/hello",
63
- resBody:{},
64
- resLength: 9,
65
- query: {testParameter: "oi"},
66
- header: {"Host":"localhost:3000","Connection":"keep-alive","Upgrade-Insecure-Requests":"1","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36","Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","Accept-Encoding":"gzip, deflate, br","Accept-Language":"en-US,en;q=0.9,pt;q=0.8"},
67
- userAgent:"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
68
- consumerIp:"127.0.0.1",
69
- sendToDataLake: true
70
- });
71
-
72
- done();
73
-
74
- });
75
-
76
- mocha.it("Test flow html method", (done) => {
77
- expect(flow.html("HTML").statusCode).to.be.equal(200);
78
- done();
79
- });
80
-
81
- mocha.it("Test call log Simple no HTTP", (done) => {
82
-
83
- let logSpy = sinon.spy(logger, "log");
84
-
85
- flow.setController({ event: { }, "start": new Date("2018-12-14T13:12:17.165Z"),"coldStart":true,"processId":"e16d62e0-ffa1-11e8-9e57-5b424b3574e1"});
86
- flow.logLambda(200, "success!!");
87
-
88
- var log = logSpy.args[0][0];
89
- log = JSON.parse(log);
90
- delete log.duration;
91
- log.date = new Date(log.date);
92
-
93
- expect(log).to.be.deep.equal({
94
- coldStart: true,
95
- date: new Date("2018-12-14T13:12:17.165Z"),
96
- method:"",
97
- statusCode:200,
98
- path:"",
99
- body: {},
100
- resBody: { },
101
- header: { },
102
- resLength: 9,
103
- query: { },
104
- userAgent:"",
105
- consumerIp:"",
106
- sendToDataLake: true
107
- });
108
-
109
- done();
110
-
111
- });
112
-
113
- });
@@ -1,123 +0,0 @@
1
- "use strict";
2
-
3
- require("dotenv").config();
4
-
5
- const expect = require("chai").expect;
6
- const mocha = require("mocha");
7
- const logger = require("../base/Logger");
8
- const _sinon = require("sinon");
9
-
10
- mocha.describe("Logger Function tests", function() {
11
-
12
- var sinon;
13
-
14
- mocha.beforeEach(function () {
15
- sinon = _sinon.createSandbox();
16
- });
17
-
18
- mocha.afterEach(function () {
19
- // Restore all the things made through the sandbox
20
- sinon.restore();
21
- });
22
-
23
- mocha.it("Verify if debug and test mode are valid", (done) => {
24
-
25
- process.env.TEST = undefined;
26
- process.env.DEBUG = undefined;
27
- expect(logger.verifyIfDebugModeIsEnable()).to.be.equal(false);
28
-
29
- process.env.TEST = true;
30
- process.env.DEBUG = undefined;
31
- expect(logger.verifyIfDebugModeIsEnable()).to.be.equal(false);
32
-
33
- process.env.TEST = true;
34
- process.env.DEBUG = true;
35
- expect(logger.verifyIfDebugModeIsEnable()).to.be.equal(false);
36
-
37
- process.env.TEST = false;
38
- process.env.DEBUG = undefined;
39
- expect(logger.verifyIfDebugModeIsEnable()).to.be.equal(false);
40
-
41
- process.env.TEST = undefined;
42
- process.env.DEBUG = false;
43
- expect(logger.verifyIfDebugModeIsEnable()).to.be.equal(false);
44
-
45
- process.env.TEST = false;
46
- process.env.DEBUG = false;
47
- expect(logger.verifyIfDebugModeIsEnable()).to.be.equal(false);
48
-
49
- process.env.TEST = false;
50
- process.env.DEBUG = true;
51
- expect(logger.verifyIfDebugModeIsEnable()).to.be.equal(true);
52
-
53
- process.env.TEST = undefined;
54
- process.env.DEBUG = true;
55
- expect(logger.verifyIfDebugModeIsEnable()).to.be.equal(true);
56
-
57
- done();
58
- });
59
-
60
- mocha.it("Call the log method", (done) => {
61
-
62
- process.env.TEST = undefined;
63
- process.env.DEBUG = true;
64
-
65
- logger.log(" ==> Olá direto!");
66
-
67
- done();
68
-
69
- });
70
-
71
- mocha.it("Call the debug method", (done) => {
72
-
73
- let logSpy = sinon.spy(console, "log");
74
-
75
- process.env.TEST = true;
76
- process.env.DEBUG = false;
77
- logger.debug("Olá 1!");
78
- expect(logSpy.callCount).to.be.equal(0);
79
-
80
- process.env.TEST = false;
81
- process.env.DEBUG = true;
82
- logger.debug(" ==> Olá 2!");
83
- expect(logSpy.callCount).to.be.equal(1);
84
-
85
- done();
86
-
87
- });
88
-
89
- mocha.it("Call the log method and not send it to the data lake", (done) => {
90
-
91
- let logSpy = sinon.spy(console, "log");
92
-
93
- process.env.TEST = false;
94
- process.env.DEBUG = false;
95
-
96
- logger.log("Olá 1!", false);
97
-
98
- expect(logSpy.callCount).to.be.equal(1);
99
- expect(JSON.parse(logSpy.args[0][0]).message).to.be.equal("Olá 1!");
100
- expect(JSON.parse(logSpy.args[0][0]).sendToDataLake).to.be.equal(false);
101
-
102
- done();
103
-
104
- });
105
-
106
- mocha.it("Call the log method and Send It to the data lake", (done) => {
107
-
108
- let logSpy = sinon.spy(console, "log");
109
-
110
- process.env.TEST = false;
111
- process.env.DEBUG = false;
112
-
113
- logger.log("Olá 1!");
114
-
115
- expect(logSpy.callCount).to.be.equal(1);
116
- expect(JSON.parse(logSpy.args[0][0]).message).to.be.equal("Olá 1!");
117
- expect(JSON.parse(logSpy.args[0][0]).sendToDataLake).to.be.equal(true);
118
-
119
- done();
120
-
121
- });
122
-
123
- });
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- require("dotenv").config();
4
-
5
- const mocha = require("mocha");
6
- const _sinon = require("sinon");
7
-
8
- process.env.TEST = true;
9
-
10
- mocha.describe("Mongoose connection test", function() {
11
-
12
- var sinon;
13
-
14
- mocha.beforeEach(function () {
15
- sinon = _sinon.createSandbox();
16
- });
17
-
18
- mocha.afterEach(function () {
19
- // Restore all the things made through the sandbox
20
- sinon.restore();
21
- });
22
- /*
23
- mocha.it("Test connection", (done) => {
24
-
25
- var mongoose = require("mongoose");
26
- mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true });
27
-
28
- var db = mongoose.connection;
29
- // db.on('error', new Error("Sem conexao"));
30
- db.once("open", function() {
31
-
32
- var Customer = require("../model/Customer");
33
- var customer = new Customer({
34
- name : "Ronaldo"
35
- });
36
- customer.save();
37
-
38
- done();
39
- });
40
-
41
- });
42
- */
43
- });