autobounty/test/test_bot.js

56 lines
2.6 KiB
JavaScript
Raw Normal View History

2018-03-19 21:37:38 +00:00
const chai = require('chai')
const expect = require('chai').expect
const assert = require('chai').assert
const should = require('chai').should
2018-01-24 22:37:53 +00:00
const config = require('../config')
2018-01-23 13:39:12 +00:00
const bot = require('../bot')
// status-open-bounty comment from https://github.com/status-im/autobounty/issues/1
2018-03-19 22:02:24 +00:00
const sobComment = 'Current balance: 0.000000 ETH\nTokens: SNT: 2500.00 ANT: 25.00\nContract address: 0x3645fe42b1a744ad98cc032c22472388806f86f9\nNetwork: Mainnet\n To claim this bounty sign up at https://openbounty.status.im and make sure to update your Ethereum address in My Payment Details so that the bounty is correctly allocated.\nTo fund it, send ETH or ERC20/ERC223 tokens to the contract address.'
2018-01-23 13:39:12 +00:00
// Fake requests
2018-03-19 21:40:36 +00:00
const requests = [
2018-03-19 22:02:24 +00:00
{ body: { action: 'created', comment: { body: 'Creating my first comment', user: { login: 'randomUser' } } } },
{ body: { action: 'edited', comment: { body: 'Editing my comment', user: { login: 'RandomUser' } } } },
{ body: { action: 'edited', comment: { body: sobComment, user: { login: 'status-open-bounty' } } } },
{ body: { action: 'created', issue: { labels: ['bounty', 'bounty-s'] }, comment: { body: sobComment, user: { login: 'status-open-bounty' } } } }
2018-03-19 21:37:38 +00:00
]
2018-01-23 13:39:12 +00:00
2018-01-23 15:36:34 +00:00
describe('Bot behavior', function () {
2018-03-19 22:02:24 +00:00
describe('#needsFunding()', function () {
it('should return false because the comment is not from status-open-bounty', function () {
assert.isFalse(bot.needsFunding(requests[0]))
2018-03-19 21:37:38 +00:00
})
2018-03-19 22:02:24 +00:00
it('should return false because a user is editing a comment', function () {
assert.isFalse(bot.needsFunding(requests[1]))
})
it('should return false because status-open-bounty edited a comment', function () {
assert.isFalse(bot.needsFunding(requests[2]))
})
it('should return true, it is all right and we should fund', function () {
assert.isTrue(bot.needsFunding(requests[3]))
})
})
2018-01-23 14:19:05 +00:00
2018-03-19 22:02:24 +00:00
describe('#getAddress', function () {
it('should return the address from a status-open-bounty bot comment', function () {
assert.equal(bot.getAddress(requests[3]), '0x3645fe42b1a744ad98cc032c22472388806f86f9')
2018-03-19 21:37:38 +00:00
})
2018-03-19 22:02:24 +00:00
})
2018-01-23 14:19:05 +00:00
2018-03-19 22:02:24 +00:00
describe('#getAmount', function () {
it('should return the amount for the issue given the price per hour and the bounty label for this issue', (done) => {
bot.getAmount(requests[3])
.then(function (amount) {
const label = 'bounty-s'
const tokenPrice = 0.35
const priceInDollars = config.priceHour * config.bountyLabels[label]
expected_amount = priceInDollars / tokenPrice
assert.equal(amount, expected_amount)
done()
2018-03-19 21:37:38 +00:00
})
2018-03-19 22:02:24 +00:00
.catch(() => { console.log('error'), done() })
2018-03-19 21:37:38 +00:00
})
2018-03-19 22:02:24 +00:00
})
2018-03-19 21:37:38 +00:00
})