{"size": 1345, "ext": "js", "max_stars_repo_path": "tests/integrations/accountbalance.test.js", "max_stars_repo_name": "dyce79/mpesa-node-library", "max_stars_repo_stars_event_min_datetime": "2018-02-21T03:01:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-16T18:56:00.000Z", "max_issues_repo_path": "tests/integrations/accountbalance.test.js", "max_issues_repo_name": "dyce79/mpesa-node-library", "max_issues_repo_issues_event_min_datetime": "2018-02-21T13:17:07.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-25T10:19:28.000Z", "max_forks_repo_path": "tests/integrations/accountbalance.test.js", "max_forks_repo_name": "dyce79/mpesa-node-library", "max_forks_repo_forks_event_min_datetime": "2018-02-21T03:02:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-02T22:59:25.000Z"}
{"max_stars_count": 133, "max_issues_count": 14, "max_forks_count": 118, "avg_line_length": 38.4285714286, "max_line_length": 124, "alphanum_fraction": 0.6624535316}
const expect = require('expect.js')
const got = require('got')
const emitter = require('.././helpers/callbacksemitter')
const testInstance = require('.././helpers/instance')
describe('Account Callbacks', function () {
  /**
     * Simulates timeouts coz lol, apparently there is no such way in Daraja
     */
  it('simulates a timeout', function (done) {
    this.timeout(15000)
    const URL = global.NGROK_URL
    emitter.once('accountBalanceTimeout', function (payload) {
      expect(payload.simulation).to.be(true)
      expect(payload.success).to.be(true)
      done()
    })
    got.post(URL + '/accountbalance/timeout', { data: 'test' }).then(r => r).catch(e => {
      throw new Error('Something went wrong. Message: ' + e.message)
    })
  })
  it('gets an account balance callback from Daraja', function (done) {
    this.timeout(15000)
    const URL = global.NGROK_URL
    const { shortCode } = testInstance.configs
    this.retries(3)
    testInstance.accountBalance(shortCode, 4, URL + '/accountbalance/timeout', URL + '/accountbalance/success').catch(e => {
      throw new Error('Something went wrong. Message: ' + e.message)
    })
    emitter.once('accountBalanceCallback', function (payload) {
      expect(payload['Result']['ResultDesc']).to.match(/The service request is processed successfully/)
      done()
    })
  })
})
