Passed
Push — master ( a52e56...f0a985 )
by Johan
01:47
created

( ➔ ... ➔ it(ꞌ"should convert properly BTC-BCH to a pair struct"ꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 1
rs 10
1
/*jslint node: true, nomen: true, regexp: true, plusplus: true */
2
(function () {
3
4
    'use strict';
0 ignored issues
show
Unused Code introduced by
The expression "'use strict'" has no effects. Consider removing it.
Loading history...
5
6
    const   chai            = require("chai"),
7
            should          = chai.should(),
8
            expect          = chai.expect;
9
10
    const   Blockfolio      = require("../index");
11
12
    const   FAKE_TOKEN      = "1915f3d2ef313e86";
13
14
    describe("Blockfolio API", function() {
15
        describe("Module Instanciation", function () {
16
            it("a protected method called without it should return an error", function (done) {
17
                Blockfolio.getPositions("BTC/USD", (err, positions) => {
18
                    should.exist(err.message);
19
                    expect(err.message).to.equal("A valid CLIENT_TOKEN should be provided! (Have you called Blockfolio.init()?)");
20
                    should.not.exist(positions);
21
                    return done();
22
                });
23
            });
24
            // Expand timeout for initialization
25
            this.timeout(5000);
26
            it("should be ok with a working token", function (done) {
27
                try {
28
                    Blockfolio.init(FAKE_TOKEN, (err) => {
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
29
                        if (err) { return done(err); }
30
31
                        return done();
32
                    });
33
                } catch (e) {
34
                    return done(e);
35
                }
36
            });
37
        });
38
        describe("Tools", function () {
39
            it("should convert properly XRP/BTC to a pair struct", function (done) {
40
                const pair = Blockfolio.utils.parseToken("XRP/BTC");
41
                expect(pair).to.be.deep.equal({base: "BTC", token: "XRP"});
42
                return done();
43
            });
44
            it("should convert properly BTC/USD to a pair struct", function (done) {
45
                const pair = Blockfolio.utils.parseToken("BTC/USD");
46
                expect(pair).to.be.deep.equal({base: "USD", token: "BTC"});
47
                return done();
48
            });
49
            it("should convert properly AEON to a pair struct", function (done) {
50
                const pair = Blockfolio.utils.parseToken("AEON");
51
                expect(pair).to.be.deep.equal({base: "BTC", token: "AEON"});
52
                return done();
53
            });
54
            it("should convert properly BTC-LTC to a pair struct", function (done) {
55
                const pair = Blockfolio.utils.parseToken("BTC-LTC");
56
                expect(pair).to.be.deep.equal({base: "BTC", token: "LTC"});
57
                return done();
58
            });
59
            it("should convert properly BTC-DASH to a pair struct", function (done) {
60
                const pair = Blockfolio.utils.parseToken("BTC-DASH");
61
                expect(pair).to.be.deep.equal({base: "BTC", token: "DASH"});
62
                return done();
63
            });
64
            it("should convert properly BTC-BCH to a pair struct", function (done) {
65
                const pair = Blockfolio.utils.parseToken("BTC-BCH");
66
                expect(pair).to.be.deep.equal({base: "BTC", token: "BCH"});
67
                return done();
68
            });
69
        });
70
        describe("Endpoints", function () {
71
            // Expand timeout for network & API lentency
72
            this.timeout(10000);
73
            it("Get a Disposable Device Token", function (done) {
74
                Blockfolio.getDisposableDeviceToken(token => {
75
                   should.exist(token);
76
                   return done();
77
                });
78
            });
79
            it("Get market details for an AEON/BTC", function (done) {
80
                Blockfolio.getMarketDetails("AEON/BTC", "bittrex", (err, details) => {
81
                    if (err) { return done(err); }
82
83
                    should.exist(details.ask);
84
                    expect(details.ask).to.be.a("string");
85
                    return done();
86
                });
87
            });
88
            it("Get available exchanges for this token", function (done) {
89
                Blockfolio.getExchanges("AEON/BTC", (err, exchanges) => {
90
                    if (err) { return done(err); }
91
92
                    expect(exchanges).to.be.an("array");
93
                    return done();
94
                });
95
            });
96
            it("Get available exchanges for an incorrect token", function (done) {
97
                Blockfolio.getExchanges("ZSKJD/BTC", (err, exchanges) => {
98
                    should.exist(err.message);
99
                    expect(err.message).to.equal("ZSKJD is not an available token on Blockfolio!");
100
                    should.not.exist(exchanges);
101
                    return done();
102
                });
103
            });
104
            it("Add a token pair to watch from Bittrex", function (done) {
105
                Blockfolio.watchCoin("AEON/BTC", "bittrex", (err, res) => {
106
                    if (err) { return done(err); }
107
108
                    expect(res).to.equal("success");
109
                    return done();
110
                });
111
            });
112
            it("Get the last price of an incorrect token on this exchange", function (done) {
113
                Blockfolio.getPrice("EAZRREZREZ/BTC", "bittrex", (err, rPrice) => {
114
                    should.exist(err.message);
115
                    expect(err.message).to.equal("EAZRREZREZ is not an available token on Blockfolio!");
116
                    should.not.exist(rPrice);
117
                    return done();
118
                });
119
            });
120
121
122
            it("... and with a valid token, but an incorrect base", function (done) {
123
                Blockfolio.getPrice("BTC/DSQFSDFDSF", "bittrex", (err, nPrice) => {
0 ignored issues
show
Unused Code introduced by
The parameter nPrice is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
124
                    should.exist(err.message);
125
                    expect(err.message).to.equal("BTC is not an available in DSQFSDFDSF on Blockfolio!");
126
                    return done();
127
                });
128
            });
129
130
131
            it("Get the last price of AEON on this exchange", function (done) {
132
                Blockfolio.getPrice("AEON/BTC", "bittrex", (err, cPrice) => {
133
                    if (err) { return done(err); }
134
135
                    expect(cPrice).to.be.a("number");
136
                    return done();
137
                });
138
            });
139
            it("Add a BTC position on this pair", function (done) {
140
                Blockfolio.addPosition(true, "AEON/BTC", "bittrex", 0.00018, 200, "AEON FTW", (err, res) => {
141
                    if (err) { return done(err); }
142
143
                    expect(res).to.equal("success");
144
                    return done();
145
                });
146
            });
147
            it("Get the summary for current position", function (done) {
148
                Blockfolio.getHoldings("AEON/BTC", (err, summary) => {
149
                    if (err) { return done(err); }
150
151
                    should.exist(summary.holdingValueString);
152
                    expect(summary.holdingValueString).to.be.a("string");
153
                    return done();
154
                });
155
            });
156
            it("Get orders details for this position", function (done) {
157
                Blockfolio.getPositions("AEON/BTC", (err, positions) => {
158
                    if (err) { return done(err); }
159
160
                    should.exist(positions);
161
                    expect(positions).to.be.an("array");
162
                    return done();
163
                });
164
            });
165
            it("And then remove the coin from portfolio", function (done) {
166
                Blockfolio.removeCoin("AEON/BTC", (err, res) => {
167
                    if (err) { return done(err); }
168
169
                    expect(res).to.equal("success");
170
                    return done();
171
                });
172
            });
173
            it("Get actual positions", function (done) {
174
                Blockfolio.getPositions((err, positions) => {
175
                    if (err) { return done(err); }
176
177
                    should.exist(positions);
178
                    expect(positions).to.be.an("array");
179
                    return done();
180
                });
181
            });
182
        });
183
    });
184
185
})();