Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | 1x 1x 1x 1x 1x 15x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | const { expect } = require(`chai`), sinon = require(`sinon`); const CoinpaymentsUtil = require(`../../lib/util`); const CoinpaymentsError = require(`../../lib/error`); let schemaStub; afterEach(function() { if (schemaStub && schemaStub.reset && CoinpaymentsUtil.getSchema.restore) { CoinpaymentsUtil.getSchema.restore(); } }); it(`Should return true hasOne`, function() { const payload = { a: 1 }; expect(CoinpaymentsUtil.hasOne(`a`, payload)).to.be.equal(true); }); it(`Should return false hasOne`, function() { const payload = { a: 1 }; expect(CoinpaymentsUtil.hasOne(`b`, payload)).to.be.equal(false); }); it(`Should return true xor`, function() { const payload = { a: 1, b: 2, c: 3 }; expect(CoinpaymentsUtil.xor([`a`, `d`, `e`], payload)).to.be.equal(true); }); it(`Should return false xor has 2`, function() { const payload = { a: 1, b: 2, c: 3 }; expect(CoinpaymentsUtil.xor([`a`, `b`, `e`], payload)).to.be.equal(false); }); it(`Should return false xor has none`, function() { const payload = { a: 1, b: 2, c: 3 }; expect(CoinpaymentsUtil.xor([`x`, `z`, `e`], payload)).to.be.equal(false); }); it(`Should return true validateMassWithDrawal`, function() { const payload = { 'wd[wd1][amount]': 1, 'wd[wd1][currency]': `BTC`, 'wd[wd1][address]': `SomeBitcoinAddress` }; expect(CoinpaymentsUtil.validateMassWithDrawal(payload)).to.be.equal(true); }); it(`Should return false validateMassWithDrawal`, function() { const payload = { 'wd[wd1][xxx]': 1, 'wd[wd1][currency]': `BTC`, 'wd[wd1][address]': `SomeBitcoinAddress` }; expect(CoinpaymentsUtil.validateMassWithDrawal(payload)).to.be.equal(false); }); it(`Should throw error on empty cmd`, function() { const err = CoinpaymentsUtil.assertPayload({}); expect(err).to.be.instanceOf(CoinpaymentsError); }); it(`Should throw error on invalid cmd`, function() { const err = CoinpaymentsUtil.assertPayload({ cmd: `unknown` }); expect(err).to.be.instanceOf(CoinpaymentsError); }); it(`Should return no error assertPayload has`, function() { const rules = [`a`, `b`, `c`]; const cmd = `test_cmd`; schemaStub = sinon .stub(CoinpaymentsUtil, `getSchema`) .withArgs(cmd) .returns(rules); const res = CoinpaymentsUtil.assertPayload({ cmd, a: 1, b: 1, c: 1 }); expect(res.isError).to.be.equal(false); }); it(`Should return error assertPayload has`, function() { const rules = [`a`, `b`, `c`]; const cmd = `test_cmd`; schemaStub = sinon .stub(CoinpaymentsUtil, `getSchema`) .withArgs(cmd) .returns(rules); const res = CoinpaymentsUtil.assertPayload({ cmd, x: 1, b: 1, c: 1 }); expect(res.isError).to.be.equal(true); }); it(`Should return no error assertPayload xor`, function() { const rules = [`a|b`, `c`]; const cmd = `test_cmd`; schemaStub = sinon .stub(CoinpaymentsUtil, `getSchema`) .withArgs(cmd) .returns(rules); const res_1 = CoinpaymentsUtil.assertPayload({ cmd: `test_cmd`, a: 1, c: 1 }); const res_2 = CoinpaymentsUtil.assertPayload({ cmd: `test_cmd`, b: 1, c: 1 }); expect(res_1.isError).to.be.equal(false); expect(res_2.isError).to.be.equal(false); }); it(`Should return error assertPayload xor both`, function() { const rules = [`a|b`, `c`]; const cmd = `test_cmd`; schemaStub = sinon .stub(CoinpaymentsUtil, `getSchema`) .withArgs(cmd) .returns(rules); const res = CoinpaymentsUtil.assertPayload({ cmd: `test_cmd`, a: 1, b: 1, c: 1 }); expect(res.isError).to.be.equal(true); }); it(`Should return error assertPayload xor none`, function() { const rules = [`a|b`, `c`]; const cmd = `test_cmd`; schemaStub = sinon .stub(CoinpaymentsUtil, `getSchema`) .withArgs(cmd) .returns(rules); const res = CoinpaymentsUtil.assertPayload({ cmd: `test_cmd`, c: 1 }); expect(res.isError).to.be.equal(true); }); it(`Should return error assertPayload create_mass_withdrawal`, function() { const cmd = `create_mass_withdrawal`; const payload = { unknown: `xxx` }; const result = CoinpaymentsUtil.assertPayload({ cmd, ...payload }); expect(result.isError).equal(true); }); |