-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
153 lines (134 loc) · 4.6 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
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
var expect = require('chai').expect
, crypto = require("crypto")
, Tango = require('./tangocard');
var tangoClient = new Tango({
name: 'TangoTest'
, key: '5xItr3dMDlEWAa9S4s7vYh7kQ01d5SFePPUoZZiK/vMfbo3A5BvJLAmD4tI='
, domain: 'https://sandbox.tangocard.com'
});
var customer = randomString()
, accountIdentifier = randomString()
, cardToken = null;
describe('Tango client', function() {
it('should initialize', function() {
expect(tangoClient).to.be.ok();
expect(tangoClient).to.have.property('createAccount');
expect(tangoClient).to.have.property('getAccountInfo');
expect(tangoClient).to.have.property('registerCreditCard');
expect(tangoClient).to.have.property('fundAccount');
expect(tangoClient).to.have.property('deleteCreditCard');
expect(tangoClient).to.have.property('getRewards');
expect(tangoClient).to.have.property('placeOrder');
expect(tangoClient).to.have.property('getOrderInfo');
expect(tangoClient).to.have.property('getOrderHistory');
})
it('should create an account', function(done) {
tangoClient.createAccount({
customer: customer
, identifier: accountIdentifier
, email: "[email protected]"
}, function(err, accountInfo) {
expect(accountInfo).to.be.ok;
expect(accountInfo.success).to.be.true;
expect(accountInfo.account.customer).to.be.equal(customer);
expect(accountInfo.account.identifier).to.be.equal(accountIdentifier);
expect(accountInfo.account.email).to.be.equal('[email protected]');
expect(accountInfo.account.available_balance).to.be.equal(0);
done(err);
});
});
it('should return account information', function(done) {
tangoClient.getAccountInfo(customer, accountIdentifier, function(err, accountInfo) {
expect(accountInfo).to.be.ok;
expect(accountInfo.success).to.be.true;
expect(accountInfo.account.customer).to.be.equal(customer);
expect(accountInfo.account.identifier).to.be.equal(accountIdentifier);
expect(accountInfo.account.email).to.be.equal('[email protected]');
expect(accountInfo.account.available_balance).to.be.equal(0);
done(err);
});
});
it('should register a credit card', function(done) {
var payload = {
customer: customer,
account_identifier: accountIdentifier,
client_ip: "127.0.0.1",
credit_card: {
number: "4111111111111111",
security_code: "123",
expiration: "2016-01",
billing_address: {
f_name: "FName",
l_name: "LName",
address: "Address",
city: "Seattle",
state: "WA",
zip: "98116",
country: "USA",
email: "[email protected]"
}
}
};
tangoClient.registerCreditCard(payload, function(err, cardInfo) {
expect(cardInfo).to.be.ok;
expect(cardInfo.success).to.be.true;
expect(cardInfo).to.have.property('cc_token');
expect(cardInfo).to.have.property('active_date');
cardToken = cardInfo.cc_token;
done(err);
});
});
it('should fund an account', function(done) {
// need to wait approval time
// we dont need to wait it
done();
});
it('should remove a credit card', function(done) {
var payload = {
customer: customer,
account_identifier: accountIdentifier,
cc_token: cardToken
};
tangoClient.deleteCreditCard(payload, function(err, cardInfo) {
expect(cardInfo).to.be.ok;
expect(cardInfo.success).to.be.true;
done(err);
});
});
it('should return list of rewards', function(done) {
tangoClient.getRewards(function(err, rewards) {
expect(rewards).to.be.ok;
expect(rewards.success).to.be.true;
expect(rewards).to.have.property('brands');
expect(rewards.brands).to.have.length.above(0);
done(err);
});
});
it('should place an order', function(done) {
// need to use credit card
done();
});
it('should return information about order', function(done) {
// need to make order
done();
});
it('should return order history', function(done) {
var qs = {
customer: customer
, account_identifier: accountIdentifier
};
tangoClient.getOrderHistory(qs, function(err, history) {
expect(history).to.be.ok;
expect(history.success).to.be.true;
expect(history).to.have.property('orders');
expect(history).to.have.property('offset');
expect(history).to.have.property('limit');
expect(history).to.have.property('result_count');
expect(history).to.have.property('total_count');
done();
});
});
});
function randomString() {
return crypto.randomBytes(20).toString('hex');
}