diff --git a/package.json b/package.json index c84456d..0b20a58 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wickrio-broadcast-bot", - "version": "5.78.1", + "version": "5.78.2", "description": "WickrIO Broadcast Bot", "main": "./build/broadcast-bot.js", "author": "Paul Cushman", @@ -29,10 +29,12 @@ "@babel/plugin-proposal-class-properties": "^7.10.4", "@babel/plugin-transform-modules-commonjs": "^7.10.4", "@babel/plugin-transform-runtime": "^7.10.4", + "@istanbuljs/nyc-config-babel": "^3.0.0", "@typescript-eslint/eslint-plugin": "^3.6.0", "@typescript-eslint/parser": "^3.6.0", "axios": "^0.21.1", "babel-jest": "^26.1.0", + "babel-plugin-istanbul": "^6.0.0", "babel-preset-airbnb": "^5.0.0", "eslint": "^7.4.0", "eslint-config-airbnb-base": "^14.2.0", @@ -47,7 +49,9 @@ "husky": "^4.2.5", "jest": "^26.1.0", "lint-staged": "^10.2.11", + "mocha": "^5.1.1", "nodemon": "^2.0.4", + "nyc": "^15.1.0", "pino-pretty": "^3.5.0", "prettier": "2.0.5" }, @@ -58,7 +62,7 @@ "lint": "eslint src/**/*.js --fix --color", "prettier": "prettier --write ./src", "stop": "pm2 delete processes.json", - "test": "jest --coverage", + "test": "nyc mocha test", "watch:test": "jest --watch" }, "husky": { @@ -170,5 +174,19 @@ "messaging", "api" ], - "database": true + "database": true, + "nyc": { + "all": true, + "exclude": [ + "test/*.js", + "scratchpad/*.js", + ".npm/**/*.js", + ".git", + "wickrio-bot-web", + "node_modules", + "public", + "src", + "temp" + ] + } } diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..fab1f3a --- /dev/null +++ b/test.sh @@ -0,0 +1,6 @@ +#!/bin/bash +if [ -f "/usr/local/nvm/nvm.sh" ]; then + . /usr/local/nvm/nvm.sh + nvm use 12.20.2 +fi +npm test diff --git a/test/test-version.js b/test/test-version.js new file mode 100644 index 0000000..2272ac5 --- /dev/null +++ b/test/test-version.js @@ -0,0 +1,104 @@ +//const expect = require('chai').expect; +//const sinon = require('sinon'); + +const assert = require('assert') +const util = require('util') +const WickrIOBotAPI = require('wickrio-bot-api') +const Version = require('../build/commands/version'); + +const tokens = '{"WICKRIO_BOT_NAME" : { "value" : "test", "encrypted" : false }}' +console.log("tokens: " + util.inspect(tokens, {depth: null})) +process.env.tokens = tokens +console.log("process.env.tokens: " + util.inspect(process.env.tokens, {depth: null})) + +describe('version validation', () => { + /*================================================================================*/ + it('shouldExecute false if /version is not the command', async () => { + + const bot = new WickrIOBotAPI.WickrIOBot() + const status = await bot.startForTesting('clientName') + + const messageObject = { + message_id:"1234", + message: "/help", + sender: "testuser@wickr.com", + users: [ "user1@wickr.com", "user2@wickr.com" ], + vgroupid: "3423423423423423423" + } + const rawMessage = JSON.stringify(messageObject) + console.log('rawMessage=' + rawMessage) + + const msgSvc = bot.messageService({ + rawMessage, + testOnly: true + }) + console.log('messageService=' + JSON.stringify(msgSvc)) + + const ver = new Version({ + messageService: msgSvc, + }) + + assert.equal(ver.shouldExecute(), false) + }); + + /*================================================================================*/ + it('shouldExecute true if /version is the command', async () => { + + const bot = new WickrIOBotAPI.WickrIOBot() + const status = await bot.startForTesting('clientName') + + const messageObject = { + message_id:"1234", + message: "/version", + sender: "testuser@wickr.com", + users: [ "user1@wickr.com", "user2@wickr.com" ], + vgroupid: "3423423423423423423" + } + const rawMessage = JSON.stringify(messageObject) + console.log('rawMessage=' + rawMessage) + + const msgSvc = bot.messageService({ + rawMessage, + testOnly: true + }) + console.log('messageService=' + JSON.stringify(msgSvc)) + + const ver = new Version({ + messageService: msgSvc, + }) + + assert.equal(ver.shouldExecute(), true) + }); + + /*================================================================================*/ + it('execute() returns a reply', async () => { + + const bot = new WickrIOBotAPI.WickrIOBot() + const status = await bot.startForTesting('clientName') + + const messageObject = { + message_id:"1234", + message: "/version", + sender: "testuser@wickr.com", + users: [ "user1@wickr.com", "user2@wickr.com" ], + vgroupid: "3423423423423423423" + } + const rawMessage = JSON.stringify(messageObject) + console.log('rawMessage=' + rawMessage) + + const msgSvc = bot.messageService({ + rawMessage, + testOnly: true + }) + console.log('messageService=' + JSON.stringify(msgSvc)) + + const ver = new Version({ + messageService: msgSvc, + }) + + const replyvalue = ver.execute() + assert.ok(replyvalue.reply) + }); + +}); +