UNPKG

2.29 kBJavaScriptView Raw
1/**
2 * Robinhood API NodeJS Wrapper - Tests
3 * @author Alejandro U. Alvarez
4 * @license AGPLv3 - See LICENSE file for more details
5 */
6
7var test = require('ava');
8var Robinhood = require('../src/robinhood');
9
10var TEST_SYMBOL = 'GOOG';
11
12test('Should get ' + TEST_SYMBOL + ' quote', function(t) {
13 Robinhood(null).quote_data(TEST_SYMBOL, function(err, response, body) {
14 if(err) {
15 done(err);
16 return;
17 }
18
19 t.is(body.results[0].symbol, TEST_SYMBOL);
20 });
21});
22
23test('Should get ' + TEST_SYMBOL + ' fundamentals', function(t) {
24 Robinhood(null).fundamentals(TEST_SYMBOL, function(err, response, body) {
25 if(err) {
26 done(err);
27 return;
28 }
29
30 // TODO make this test better
31 t.is(Object.keys(body).length, 21);
32 });
33});
34
35test('Should get markets', function(t) {
36 Robinhood(null).markets(function(err, response, body) {
37 if(err) {
38 done(err);
39 return;
40 }
41
42 t.true(body.results.length > 0);
43 });
44});
45
46test('Should get news about ' + TEST_SYMBOL, function(t) {
47 Robinhood(null).news(TEST_SYMBOL, function(err, response, body) {
48 if(err) {
49 done(err);
50 return;
51 }
52
53 t.true(body.results.length > 0);
54 });
55});
56
57test('Should get data for the SP500 index up', function(t) {
58 Robinhood(null).sp500_up(function(err, response, body) {
59 if(err) {
60 done(err);
61 return;
62 }
63
64 t.true(body.results.length > 0);
65 });
66});
67
68test('Should get data for the SP500 index down', function(t) {
69 Robinhood(null).sp500_down(function(err, response, body) {
70 if(err) {
71 done(err);
72 return;
73 }
74
75 t.true(body.results.length > 0);
76 });
77});
78
79test('Should not get positions without login', function(t) {
80 Robinhood(null).positions(function(err, response, body) {
81 if(err) {
82 done(err);
83 return;
84 }
85
86 t.true(body.detail);
87 });
88});
89
90test('Should not get nonzero positions without credentials', function(t){
91 Robinhood(null).nonzero_positions(function(err,response,body) {
92 if(err) {
93 done(err);
94 return;
95 }
96
97 t.true(body.detail);
98 });
99});