|
3 | 3 | var test = require('tape');
|
4 | 4 |
|
5 | 5 | test('makes a rest call', function (t) {
|
6 |
| - t.plan(2); |
| 6 | + t.plan(2); |
7 | 7 |
|
8 |
| - var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
9 |
| - var data = [{x:[0,1,2], y:[3,2,1], type: 'bar'}]; |
10 |
| - var layout = {fileopt : 'overwrite', filename : 'nodenodenodetest'}; |
| 8 | + var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
| 9 | + var data = [{x:[0,1,2], y:[3,2,1], type: 'bar'}]; |
| 10 | + var layout = {fileopt : 'overwrite', filename : 'nodenodenodetest'}; |
11 | 11 |
|
12 |
| - plotly.plot(data, layout, function (err, msg) { |
13 |
| - t.isEqual(msg.url, 'https://plot.ly/~node-test-account/0', 'url matches'); |
14 |
| - t.notOk(err ,'no error'); |
15 |
| - t.end(); |
16 |
| - }); |
| 12 | + plotly.plot(data, layout, function (err, msg) { |
| 13 | + t.isEqual(msg.url, 'https://plot.ly/~node-test-account/0', 'url matches'); |
| 14 | + t.notOk(err ,'no error'); |
| 15 | + t.end(); |
| 16 | + }); |
17 | 17 | });
|
18 | 18 |
|
19 | 19 | test('makes a rest call', function (t) {
|
20 |
| - t.plan(2); |
21 |
| - |
22 |
| - var options = { |
23 |
| - username: 'node-test-account', |
24 |
| - apiKey: 'tpmz9ye8hg', |
25 |
| - host: 'plot.ly', |
26 |
| - port: 443 |
27 |
| - }; |
28 |
| - |
29 |
| - var plotly = require('../index')(options); |
30 |
| - var data = [{x:[0,1,2], y:[3,2,1], type: 'bar'}]; |
31 |
| - var layout = {fileopt : 'overwrite', filename : 'nodenodenodetest'}; |
32 |
| - |
33 |
| - plotly.plot(data, layout, function (err, msg) { |
34 |
| - t.isEqual(msg.url, 'https://plot.ly/~node-test-account/0', 'url matches'); |
35 |
| - t.notOk(err ,'no error'); |
36 |
| - t.end(); |
37 |
| - }); |
| 20 | + t.plan(2); |
| 21 | + |
| 22 | + var options = { |
| 23 | + username: 'node-test-account', |
| 24 | + apiKey: 'tpmz9ye8hg', |
| 25 | + host: 'plot.ly', |
| 26 | + port: 443 |
| 27 | + }; |
| 28 | + |
| 29 | + var plotly = require('../index')(options); |
| 30 | + var data = [{x:[0,1,2], y:[3,2,1], type: 'bar'}]; |
| 31 | + var layout = {fileopt : 'overwrite', filename : 'nodenodenodetest'}; |
| 32 | + |
| 33 | + plotly.plot(data, layout, function (err, msg) { |
| 34 | + t.isEqual(msg.url, 'https://plot.ly/~node-test-account/0', 'url matches'); |
| 35 | + t.notOk(err ,'no error'); |
| 36 | + t.end(); |
| 37 | + }); |
38 | 38 | });
|
39 | 39 |
|
40 | 40 | test('makes a rest call', function (t) {
|
41 |
| - t.plan(2); |
42 |
| - var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
43 |
| - var data = [{x:[0,1,2], y:[3,2,1], type: 'bar'}]; |
44 |
| - var layout = {fileopt : 'overwrite', filename : 'nodenodenodetest'}; |
45 |
| - |
46 |
| - plotly.plot(data, layout, function (err, msg) { |
47 |
| - t.isEqual(msg.url, 'https://plot.ly/~node-test-account/0', 'url matches'); |
48 |
| - t.notOk(err, 'no error'); |
49 |
| - t.end(); |
50 |
| - }); |
| 41 | + t.plan(2); |
| 42 | + var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
| 43 | + var data = [{x:[0,1,2], y:[3,2,1], type: 'bar'}]; |
| 44 | + var layout = {fileopt : 'overwrite', filename : 'nodenodenodetest'}; |
| 45 | + |
| 46 | + plotly.plot(data, layout, function (err, msg) { |
| 47 | + t.isEqual(msg.url, 'https://plot.ly/~node-test-account/0', 'url matches'); |
| 48 | + t.notOk(err, 'no error'); |
| 49 | + t.end(); |
| 50 | + }); |
51 | 51 | });
|
52 | 52 |
|
53 | 53 | test('plot with incorrect userdata and return error', function (t) {
|
54 |
| - t.plan(1); |
| 54 | + t.plan(1); |
55 | 55 |
|
56 |
| - var plotly = require('../index')('node-test-accountasdfadsgaghaha', 'tpmz9ye8hg'); |
57 |
| - var data = [{x:[0,1,2], y:[3,2,1], type: 'bar'}]; |
58 |
| - var layout = {fileopt : 'overwrite', filename : 'nodenodenodetest'}; |
| 56 | + var plotly = require('../index')('node-test-accountasdfadsgaghaha', 'tpmz9ye8hg'); |
| 57 | + var data = [{x:[0,1,2], y:[3,2,1], type: 'bar'}]; |
| 58 | + var layout = {fileopt : 'overwrite', filename : 'nodenodenodetest'}; |
59 | 59 |
|
60 |
| - plotly.plot(data, layout, function (err, msg) { |
| 60 | + plotly.plot(data, layout, function (err, msg) { |
61 | 61 |
|
62 |
| - var errMessage = msg.message.split(',')[0]; |
| 62 | + var errMessage = msg.message.split(',')[0]; |
63 | 63 |
|
64 |
| - t.isEqual(errMessage, 'Aw', 'incorrect user info returns error... not properly though.'); |
65 |
| - t.end(); |
66 |
| - }); |
| 64 | + t.isEqual(errMessage, 'Aw', 'incorrect user info returns error... not properly though.'); |
| 65 | + t.end(); |
| 66 | + }); |
67 | 67 | });
|
68 | 68 |
|
69 | 69 | test('makes a rest call with host foo', function (t) {
|
70 |
| - t.plan(1); |
71 |
| - var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
72 |
| - plotly.host = 'foo'; |
73 |
| - var data = [{x:[0,1,2], y:[3,2,1], type: 'bar'}]; |
74 |
| - var layout = {fileopt : 'overwrite', filename : 'nodenodenodetest'}; |
75 |
| - |
76 |
| - plotly.plot(data, layout, function (err) { |
77 |
| - t.ok(err, 'error received as host was set to "foo"'); |
78 |
| - t.end(); |
79 |
| - }); |
| 70 | + t.plan(1); |
| 71 | + var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
| 72 | + plotly.host = 'foo'; |
| 73 | + var data = [{x:[0,1,2], y:[3,2,1], type: 'bar'}]; |
| 74 | + var layout = {fileopt : 'overwrite', filename : 'nodenodenodetest'}; |
| 75 | + |
| 76 | + plotly.plot(data, layout, function (err) { |
| 77 | + t.ok(err, 'error received as host was set to "foo"'); |
| 78 | + t.end(); |
| 79 | + }); |
80 | 80 | });
|
81 | 81 |
|
82 | 82 | test('makes a rest call with no callback', function (t) {
|
83 |
| - t.plan(1); |
84 |
| - var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
85 |
| - plotly.host = 'foo'; |
86 |
| - var data = [{x:[0,1,2], y:[3,2,1], type: 'bar'}]; |
87 |
| - var layout = {fileopt : 'overwrite', filename : 'nodenodenodetest'}; |
| 83 | + t.plan(1); |
| 84 | + var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
| 85 | + plotly.host = 'foo'; |
| 86 | + var data = [{x:[0,1,2], y:[3,2,1], type: 'bar'}]; |
| 87 | + var layout = {fileopt : 'overwrite', filename : 'nodenodenodetest'}; |
88 | 88 |
|
89 |
| - plotly.plot(data, layout); |
90 |
| - t.ok(true); |
91 |
| - t.end(); |
| 89 | + plotly.plot(data, layout); |
| 90 | + t.ok(true); |
| 91 | + t.end(); |
92 | 92 |
|
93 | 93 | });
|
94 | 94 |
|
95 | 95 | test('makes a rest call with object for data', function (t) {
|
96 |
| - t.plan(1); |
97 |
| - var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
98 |
| - plotly.host = 'foo'; |
99 |
| - var data = {x:[0,1,2], y:[3,2,1], type: 'bar'}; |
100 |
| - var layout = {fileopt : 'overwrite', filename : 'nodenodenodetest'}; |
| 96 | + t.plan(1); |
| 97 | + var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
| 98 | + plotly.host = 'foo'; |
| 99 | + var data = {x:[0,1,2], y:[3,2,1], type: 'bar'}; |
| 100 | + var layout = {fileopt : 'overwrite', filename : 'nodenodenodetest'}; |
101 | 101 |
|
102 |
| - plotly.plot(data, layout); |
103 |
| - t.ok(true); |
104 |
| - t.end(); |
| 102 | + plotly.plot(data, layout); |
| 103 | + t.ok(true); |
| 104 | + t.end(); |
105 | 105 |
|
106 | 106 | });
|
107 | 107 |
|
108 | 108 | test('getFigure', function (t) {
|
109 |
| - t.plan(1); |
110 |
| - var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
111 |
| - plotly.getFigure('node-test-account', '0', function (err, figure) { |
112 |
| - t.ok(figure); |
113 |
| - t.end(); |
114 |
| - }); |
| 109 | + t.plan(1); |
| 110 | + var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
| 111 | + plotly.getFigure('node-test-account', '0', function (err, figure) { |
| 112 | + t.ok(figure); |
| 113 | + t.end(); |
| 114 | + }); |
115 | 115 |
|
116 | 116 | });
|
117 | 117 |
|
118 | 118 | test('getFigure error', function (t) {
|
119 |
| - t.plan(1); |
120 |
| - var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
121 |
| - plotly.getFigure('node-test-account', '99', function (err) { |
| 119 | + t.plan(1); |
| 120 | + var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
| 121 | + plotly.getFigure('node-test-account', '99', function (err) { |
122 | 122 |
|
123 |
| - t.ok(err); |
124 |
| - t.end(); |
125 |
| - }); |
| 123 | + t.ok(err); |
| 124 | + t.end(); |
| 125 | + }); |
126 | 126 | });
|
127 | 127 |
|
128 | 128 | test('getImage, good and error', function (t) {
|
129 |
| - t.plan(2); |
130 |
| - var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
131 |
| - |
132 |
| - var trace1 = { |
133 |
| - x: [1, 2, 3, 4], |
134 |
| - y: [10, 15, 13, 17], |
135 |
| - type: 'scatter' |
136 |
| - }; |
137 |
| - |
138 |
| - var trace2 = { |
139 |
| - x: [1, 2, 3, 4], |
140 |
| - y: [16, 5, 11, 9], |
141 |
| - type: 'scatter' |
142 |
| - }; |
143 |
| - |
144 |
| - var figure = { |
145 |
| - 'data': [trace1, trace2] |
146 |
| - }; |
147 |
| - |
148 |
| - plotly.getImage(figure, {}, function (err, imageData) { |
149 |
| - t.notOk(err); |
150 |
| - t.ok(imageData); |
151 |
| - t.end(); |
152 |
| - }); |
| 129 | + t.plan(2); |
| 130 | + var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
| 131 | + |
| 132 | + var trace1 = { |
| 133 | + x: [1, 2, 3, 4], |
| 134 | + y: [10, 15, 13, 17], |
| 135 | + type: 'scatter' |
| 136 | + }; |
| 137 | + |
| 138 | + var trace2 = { |
| 139 | + x: [1, 2, 3, 4], |
| 140 | + y: [16, 5, 11, 9], |
| 141 | + type: 'scatter' |
| 142 | + }; |
| 143 | + |
| 144 | + var figure = { |
| 145 | + 'data': [trace1, trace2] |
| 146 | + }; |
| 147 | + |
| 148 | + plotly.getImage(figure, {}, function (err, imageData) { |
| 149 | + t.notOk(err); |
| 150 | + t.ok(imageData); |
| 151 | + t.end(); |
| 152 | + }); |
153 | 153 | });
|
154 | 154 |
|
155 | 155 | test('getImage, imageserver error', function (t) {
|
156 |
| - t.plan(2); |
157 |
| - var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
158 |
| - |
159 |
| - var trace1 = { |
160 |
| - x: [1, 2, 3, 4], |
161 |
| - y: [10, 15, 13, 17], |
162 |
| - type: 'scatter' |
163 |
| - }; |
164 |
| - |
165 |
| - var trace2 = { |
166 |
| - x: [1, 2, 3, 4], |
167 |
| - y: [16, 5, 11, 9], |
168 |
| - type: 'scatter' |
169 |
| - }; |
170 |
| - |
171 |
| - var data = [trace1, trace2]; |
172 |
| - plotly.getImage(data, 'img', function (err, imageData) { |
173 |
| - t.ok(err); |
174 |
| - t.notOk(imageData); |
175 |
| - t.end(); |
176 |
| - }); |
| 156 | + t.plan(2); |
| 157 | + var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
| 158 | + |
| 159 | + var trace1 = { |
| 160 | + x: [1, 2, 3, 4], |
| 161 | + y: [10, 15, 13, 17], |
| 162 | + type: 'scatter' |
| 163 | + }; |
| 164 | + |
| 165 | + var trace2 = { |
| 166 | + x: [1, 2, 3, 4], |
| 167 | + y: [16, 5, 11, 9], |
| 168 | + type: 'scatter' |
| 169 | + }; |
| 170 | + |
| 171 | + var data = [trace1, trace2]; |
| 172 | + plotly.getImage(data, 'img', function (err, imageData) { |
| 173 | + t.ok(err); |
| 174 | + t.notOk(imageData); |
| 175 | + t.end(); |
| 176 | + }); |
177 | 177 |
|
178 | 178 | });
|
179 | 179 |
|
| 180 | +test('creates a plot with UTF chars in filename', function (t) { |
| 181 | + t.plan(1); |
| 182 | + |
| 183 | + var options = { |
| 184 | + username: 'node-test-account', |
| 185 | + apiKey: 'tpmz9ye8hg', |
| 186 | + host: 'plot.ly', |
| 187 | + port: 443 |
| 188 | + }; |
| 189 | + |
| 190 | + var plotly = require('../index')(options); |
| 191 | + var data = [{x:[0,1,2], y:[3,2,1], type: 'bar'}]; |
| 192 | + var layout = {fileopt : 'overwrite', filename : 'üüüü'}; |
180 | 193 |
|
| 194 | + plotly.plot(data, layout, function (err, msg) { |
| 195 | + t.notOk(err ,'no error'); |
| 196 | + t.end(); |
| 197 | + }); |
| 198 | + |
| 199 | +}); |
181 | 200 |
|
182 | 201 | test('streams some data', function (t) {
|
183 |
| - t.plan(1); |
184 |
| - var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
185 |
| - var initdata = [{x:[], y:[], stream:{token:'i9zxn8goas', maxpoints:200}}]; |
186 |
| - var initlayout = {fileopt : 'extend', filename : 'nodenodenode-test-stream'}; |
187 |
| - |
188 |
| - plotly.plot(initdata, initlayout, function (err) { |
189 |
| - if (err) return console.log(err); |
190 |
| - |
191 |
| - var streamObject = JSON.stringify({ x : 1, y : 1 }); |
192 |
| - |
193 |
| - var stream = plotly.stream({ |
194 |
| - token: 'i9zxn8goas', |
195 |
| - host: undefined, |
196 |
| - port: null |
197 |
| - }); |
198 |
| - |
199 |
| - setInterval(function () { |
200 |
| - stream.write(streamObject+'\n'); |
201 |
| - }, 500); |
202 |
| - |
203 |
| - setTimeout(function () { |
204 |
| - t.ok(true, 'no errors'); |
205 |
| - t.end(); |
206 |
| - process.exit(0); |
207 |
| - }, 5000); |
208 |
| - }); |
| 202 | + t.plan(1); |
| 203 | + var plotly = require('../index')('node-test-account', 'tpmz9ye8hg'); |
| 204 | + var initdata = [{x:[], y:[], stream:{token:'i9zxn8goas', maxpoints:200}}]; |
| 205 | + var initlayout = {fileopt : 'extend', filename : 'nodenodenode-test-stream'}; |
| 206 | + |
| 207 | + plotly.plot(initdata, initlayout, function (err) { |
| 208 | + if (err) return console.log(err); |
| 209 | + |
| 210 | + var streamObject = JSON.stringify({ x : 1, y : 1 }); |
| 211 | + |
| 212 | + var stream = plotly.stream({ |
| 213 | + token: 'i9zxn8goas', |
| 214 | + host: undefined, |
| 215 | + port: null |
| 216 | + }); |
| 217 | + |
| 218 | + setInterval(function () { |
| 219 | + stream.write(streamObject+'\n'); |
| 220 | + }, 500); |
| 221 | + |
| 222 | + setTimeout(function () { |
| 223 | + t.ok(true, 'no errors'); |
| 224 | + t.end(); |
| 225 | + process.exit(0); |
| 226 | + }, 5000); |
| 227 | + }); |
209 | 228 | });
|
0 commit comments