All files / test index.ts

91.67% Statements 22/24
100% Branches 0/0
81.82% Functions 9/11
91.67% Lines 22/24
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 511x 1x 1x   1x             1x 1x 1x 1x       1x 1x 1x 1x 1x 1x 1x 1x           1x 1x 1x               1x 1x 1x              
import { expect } from 'chai';
import WechatPay = require('../src/index');
import { readomString } from '../src/util';
 
const wechatPay = new WechatPay({
  appid: '1234567',
  secret: '1234567',
  mch_id: '1234567',
  key: '1234567',
});
 
describe('Test readom string with length', () => {
  it('should return a string which length equal input', () => {
    const str: number = readomString(10).length;
    expect(str).to.equal(10);
  })
});
 
describe('Test class wechatPay', () => {
  describe('Test get user openid method', () => {
    it('should return error or openid response', (done) => {
      wechatPay.getUserOpenId('str').then((res) => {
        const reg = /errcode|openid/ig;
        console.log(res);
        expect(reg.test(JSON.stringify(res))).to.equal(true);
        done();
      }).catch((err) => {
        done(err);
      })
    });
  });
  describe('Test payment method', () => {
    it('should return error or per response', (done) => {
      wechatPay.payment({
        body: '',
        openid: '123123',
        out_trade_no: 1,
        total_fee: 200,
        notify_url: 'http://www.baidu.com',
        spbill_create_ip: '123',
      }).then((res) => {
        console.log(res);
        expect(Array.from(Object.keys(res)).join(',')).to.equal('original_data,wechatpay_data');
        done();
      }).catch((err) => {
        done(err);
      })
    });
  });
});