Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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"
},
Expand All @@ -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": {
Expand Down Expand Up @@ -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"
]
}
}
6 changes: 6 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -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
104 changes: 104 additions & 0 deletions test/test-version.js
Original file line number Diff line number Diff line change
@@ -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)
});

});