Skip to content

Commit

Permalink
Merge pull request brave#13568 from bsclifton/add-state-run
Browse files Browse the repository at this point in the history
Ensure state gets passed into `run` method
  • Loading branch information
bsclifton authored Mar 22, 2018
2 parents 75ec846 + ba05870 commit 251bb6e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ const onBootStateFile = (state) => {
}

if (client.sync(callback) === true) {
run(random.randomInt({min: ledgerUtil.milliseconds.minute, max: 10 * ledgerUtil.milliseconds.minute}))
run(state, random.randomInt({min: ledgerUtil.milliseconds.minute, max: 10 * ledgerUtil.milliseconds.minute}))
}

module.exports.getBalance(state)
Expand Down Expand Up @@ -2321,7 +2321,7 @@ const run = (state, delayTime) => {
})
}

if (typeof delayTime === 'undefined' || !client) {
if (state == null || typeof delayTime === 'undefined' || !client) {
return
}

Expand Down
50 changes: 50 additions & 0 deletions test/unit/app/browser/api/ledgerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ describe('ledger api unit tests', function () {
// ledger client stubbing
ledgerClient = sinon.stub()
ledgerClientObject = {
ballots: function () {
return 1
},
sync: function (callback) { return false },
getBraveryProperties: function () {
return {
Expand Down Expand Up @@ -2686,4 +2689,51 @@ describe('ledger api unit tests', function () {
assert(fetchPublisherInfoSpy.withArgs('test.com', sinon.match.any, sinon.match.any))
})
})

describe('BSCrun', function () {
let clientBallotsSpy

before(() => {
ledgerApi.setSynopsis({
toJSON: () => {
return {
publishers: {
'clifton.io': {
visits: 1
}
}
}
},
winners: () => {
return []
}
})
ledgerApi.setClient(ledgerClientObject)
clientBallotsSpy = sinon.spy(ledgerClientObject, 'ballots')
})

afterEach(() => {
clientBallotsSpy.reset()
})

after(() => {
clientBallotsSpy.restore()
ledgerApi.setSynopsis(undefined)
})

it('exits if state is undefined', function () {
ledgerApi.run(undefined, 10)
assert.equal(clientBallotsSpy.notCalled, true)
})

it('exits if delayTime is undefined', function () {
ledgerApi.run(defaultAppState)
assert.equal(clientBallotsSpy.notCalled, true)
})

it('gets balance count from client', function () {
ledgerApi.run(defaultAppState, 10)
assert.equal(clientBallotsSpy.calledOnce, true)
})
})
})

0 comments on commit 251bb6e

Please sign in to comment.