Passed
Push — master ( ac43d7...a52e56 )
by Johan
02:27
created

( ➔ ... ➔ it(ꞌ"Get a Disposable Device Token"ꞌ)   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
        });
60
        describe("Endpoints", function () {
61
            // Expand timeout for network & API lentency
62
            this.timeout(10000);
63
            it("Get a Disposable Device Token", function (done) {
64
                Blockfolio.getDisposableDeviceToken(token => {
65
                   should.exist(token);
66
                   return done();
67
                });
68
            });
69
            it("Get market details for an AEON/BTC", function (done) {
70
                Blockfolio.getMarketDetails("AEON/BTC", "bittrex", (err, details) => {
71
                    if (err) { return done(err); }
72
73
                    should.exist(details.ask);
74
                    expect(details.ask).to.be.a("string");
75
                    return done();
76
                });
77
            });
78
            it("Get available exchanges for this token", function (done) {
79
                Blockfolio.getExchanges("AEON/BTC", (err, exchanges) => {
80
                    if (err) { return done(err); }
81
82
                    expect(exchanges).to.be.an("array");
83
                    return done();
84
                });
85
            });
86
            it("Get available exchanges for an incorrect token", function (done) {
87
                Blockfolio.getExchanges("ZSKJD/BTC", (err, exchanges) => {
88
                    should.exist(err.message);
89
                    expect(err.message).to.equal("ZSKJD is not an available token on Blockfolio!");
90
                    should.not.exist(exchanges);
91
                    return done();
92
                });
93
            });
94
            it("Add a token pair to watch from Bittrex", function (done) {
95
                Blockfolio.watchCoin("AEON/BTC", "bittrex", (err, res) => {
96
                    if (err) { return done(err); }
97
98
                    expect(res).to.equal("success");
99
                    return done();
100
                });
101
            });
102
            it("Get the last price of an incorrect token on this exchange", function (done) {
103
                Blockfolio.getPrice("EAZRREZREZ/BTC", "bittrex", (err, rPrice) => {
104
                    should.exist(err.message);
105
                    expect(err.message).to.equal("EAZRREZREZ is not an available token on Blockfolio!");
106
                    should.not.exist(rPrice);
107
                    return done();
108
                });
109
            });
110
111
112
            it("... and with a valid token, but an incorrect base", function (done) {
113
                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...
114
                    should.exist(err.message);
115
                    expect(err.message).to.equal("BTC is not an available in DSQFSDFDSF on Blockfolio!");
116
                    return done();
117
                });
118
            });
119
120
121
            it("Get the last price of AEON on this exchange", function (done) {
122
                Blockfolio.getPrice("AEON/BTC", "bittrex", (err, cPrice) => {
123
                    if (err) { return done(err); }
124
125
                    expect(cPrice).to.be.a("number");
126
                    return done();
127
                });
128
            });
129
            it("Add a BTC position on this pair", function (done) {
130
                Blockfolio.addPosition(true, "AEON/BTC", "bittrex", 0.00018, 200, "AEON FTW", (err, res) => {
131
                    if (err) { return done(err); }
132
133
                    expect(res).to.equal("success");
134
                    return done();
135
                });
136
            });
137
            it("Get the summary for current position", function (done) {
138
                Blockfolio.getHoldings("AEON/BTC", (err, summary) => {
139
                    if (err) { return done(err); }
140
141
                    should.exist(summary.holdingValueString);
142
                    expect(summary.holdingValueString).to.be.a("string");
143
                    return done();
144
                });
145
            });
146
            it("Get orders details for this position", function (done) {
147
                Blockfolio.getPositions("AEON/BTC", (err, positions) => {
148
                    if (err) { return done(err); }
149
150
                    should.exist(positions);
151
                    expect(positions).to.be.an("array");
152
                    return done();
153
                });
154
            });
155
            it("And then remove the coin from portfolio", function (done) {
156
                Blockfolio.removeCoin("AEON/BTC", (err, res) => {
157
                    if (err) { return done(err); }
158
159
                    expect(res).to.equal("success");
160
                    return done();
161
                });
162
            });
163
            it("Get actual positions", function (done) {
164
                Blockfolio.getPositions((err, positions) => {
165
                    if (err) { return done(err); }
166
167
                    should.exist(positions);
168
                    expect(positions).to.be.an("array");
169
                    return done();
170
                });
171
            });
172
        });
173
    });
174
175
})();