-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
52 lines (44 loc) · 2.03 KB
/
test.js
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
require('dotenv').config();
const expect = require('chai').expect;
const { send, getCredit } = require('./index');
const uid = process.env.uid;
const password = process.env.password;
const mobile = process.env.mobile;
const sendUrl = process.env.sendUrl || 'https://biz3.every8d.com.tw/prepaid/API21/HTTP/sendSMS.ashx';
const creditUrl = process.env.creditUrl || 'https://biz3.every8d.com.tw/prepaid/API21/HTTP/getCredit.ashx';
describe('send sms', function() {
this.timeout(5000);
it('all empty params', async function() {
const result = await send(sendUrl, '', '', '', '', '', '');
expect(result.error).to.equal('return format error: -300,帳號密碼不得為空');
});
it('empty mobile', async function() {
const result = await send(sendUrl, uid, password, '', '', '', '');
expect(result.error).to.equal('return format error: -27,電話號碼不得為空');
});
it('wrong password', async function() {
const result = await send(sendUrl, uid, '1234', '', 'test message from mocha', mobile, '');
expect(result.error).to.equal('return format error: -101,密碼錯誤');
});
it('complete message', async function() {
const result = await send(sendUrl, uid, password, '', 'test message from mocha', mobile, '');
expect(result.error).to.equal(null);
});
});
describe('get credit', function() {
this.timeout(5000);
it('all empty params', async function() {
const result = await getCredit(creditUrl, '', '');
expect(result.error).to.equal('return format error: -300,帳號密碼不得為空');
});
it('wrong password', async function() {
const result = await getCredit(creditUrl, uid, '1234');
expect(result.error).to.equal('return format error: -101,密碼錯誤');
});
it('complete message', async function() {
const result = await getCredit(creditUrl, uid, password);
console.log(result);
expect(result.error).to.equal(null);
expect(Number(result.credit)).to.be.a('number');
});
});