1
1
if ( typeof ( require ) !== 'undefined' ) {
2
- var bitballoon = require ( "../lib/bitballoon .js" ) ,
2
+ var netlify = require ( "../lib/netlify .js" ) ,
3
3
crypto = require ( "crypto" ) ,
4
4
fs = require ( "fs" ) ;
5
5
}
@@ -25,7 +25,7 @@ var http = {
25
25
request = new Emitter ( ) ,
26
26
response = new Emitter ( ) ,
27
27
requestBody = "" ;
28
-
28
+
29
29
request . write = function ( data ) { requestBody += data ; } ;
30
30
request . end = function ( ) {
31
31
options . body = requestBody ;
@@ -38,9 +38,9 @@ var http = {
38
38
cb ( response ) ;
39
39
response . emit ( 'data' , test . response ) ;
40
40
response . emit ( 'end' ) ;
41
- } , 0 ) ;
41
+ } , 0 ) ;
42
42
}
43
-
43
+
44
44
return request ;
45
45
}
46
46
} ;
@@ -49,7 +49,7 @@ var firstIfArray = function(obj) {
49
49
return Array . isArray ( obj ) ? obj . shift ( ) : obj ;
50
50
} ;
51
51
52
- describe ( "bitballoon " , function ( ) {
52
+ describe ( "netlify " , function ( ) {
53
53
var testApiCall = function ( options ) {
54
54
var httpCalls = Array . isArray ( options . http ) ? options . http : [ options . http ] ;
55
55
httpCalls . forEach ( function ( httpCall ) {
@@ -64,21 +64,21 @@ describe("bitballoon", function() {
64
64
waitsFor ( options . waitsFor , 100 ) ;
65
65
runs ( options . expectations ) ;
66
66
} ;
67
-
67
+
68
68
beforeEach ( function ( ) {
69
69
http . test = [ ] ;
70
70
} ) ;
71
71
72
72
it ( "should create a client" , function ( ) {
73
- var client = bitballoon . createClient ( { access_token : "1234" } ) ;
73
+ var client = netlify . createClient ( { access_token : "1234" } ) ;
74
74
expect ( client . access_token ) . toEqual ( "1234" ) ;
75
75
expect ( client . isAuthorized ( ) ) . toEqual ( true ) ;
76
76
} ) ;
77
77
78
78
it ( "should authenticate from credentials" , function ( ) {
79
- var client = bitballoon . createClient ( { client_id : "client_id" , client_secret : "client_secret" , http : http } ) ;
80
- var access_token = null ;
81
-
79
+ var client = netlify . createClient ( { client_id : "client_id" , client_secret : "client_secret" , http : http } ) ;
80
+ var access_token = null ;
81
+
82
82
testApiCall ( {
83
83
http : {
84
84
expectations : function ( options ) {
@@ -102,25 +102,25 @@ describe("bitballoon", function() {
102
102
} ) ;
103
103
104
104
it ( "should generate an authorize url" , function ( ) {
105
- var client = bitballoon . createClient ( {
106
- client_id : "client_id" ,
105
+ var client = netlify . createClient ( {
106
+ client_id : "client_id" ,
107
107
client_secret : "client_secret" ,
108
108
redirect_uri : "http://www.example.com/callback"
109
109
} ) ;
110
110
var url = client . authorizeUrl ( ) ;
111
111
112
- expect ( url ) . toEqual ( "https://www.bitballoon .com/oauth/authorize?response_type=code&client_id=client_id&redirect_uri=http%3A%2F%2Fwww.example.com%2Fcallback" )
112
+ expect ( url ) . toEqual ( "https://www.netlify .com/oauth/authorize?response_type=code&client_id=client_id&redirect_uri=http%3A%2F%2Fwww.example.com%2Fcallback" )
113
113
} ) ;
114
114
115
115
it ( "should authorize from authorization code" , function ( ) {
116
- var client = bitballoon . createClient ( {
117
- client_id : "client_id" ,
116
+ var client = netlify . createClient ( {
117
+ client_id : "client_id" ,
118
118
client_secret : "client_secret" ,
119
119
redirect_uri : "http://www.example.com/callback" ,
120
120
http : http
121
121
} ) ;
122
122
var access_token = null ;
123
-
123
+
124
124
testApiCall ( {
125
125
http : {
126
126
expectations : function ( options ) {
@@ -144,9 +144,9 @@ describe("bitballoon", function() {
144
144
} ) ;
145
145
146
146
it ( "should get a list of sites" , function ( ) {
147
- var client = bitballoon . createClient ( { access_token : "1234" , http : http } ) ,
147
+ var client = netlify . createClient ( { access_token : "1234" , http : http } ) ,
148
148
sites = [ ] ;
149
-
149
+
150
150
testApiCall ( {
151
151
http : {
152
152
expectations : function ( options ) {
@@ -165,9 +165,9 @@ describe("bitballoon", function() {
165
165
} ) ;
166
166
167
167
it ( "should get a list of sites with pagination" , function ( ) {
168
- var client = bitballoon . createClient ( { access_token : "1234" , http : http } ) ,
168
+ var client = netlify . createClient ( { access_token : "1234" , http : http } ) ,
169
169
sites = [ ] ;
170
-
170
+
171
171
testApiCall ( {
172
172
http : {
173
173
expectations : function ( options ) {
@@ -186,15 +186,15 @@ describe("bitballoon", function() {
186
186
} ) ;
187
187
188
188
it ( "should get a single site" , function ( ) {
189
- var client = bitballoon . createClient ( { access_token : "1234" , http : http } ) ,
189
+ var client = netlify . createClient ( { access_token : "1234" , http : http } ) ,
190
190
site = null ;
191
191
192
192
testApiCall ( {
193
193
http : {
194
194
expectations : function ( options ) {
195
195
expect ( options . headers [ 'Authorization' ] ) . toEqual ( "Bearer 1234" ) ;
196
196
expect ( options . method ) . toEqual ( "get" ) ;
197
- expect ( options . path ) . toEqual ( "/api/v1/sites/123" ) ;
197
+ expect ( options . path ) . toEqual ( "/api/v1/sites/123" ) ;
198
198
} ,
199
199
response : { id : "123" }
200
200
} ,
@@ -205,17 +205,17 @@ describe("bitballoon", function() {
205
205
}
206
206
} ) ;
207
207
} ) ;
208
-
208
+
209
209
it ( "should refresh the state of a site" , function ( ) {
210
- var client = bitballoon . createClient ( { access_token : "1234" , http : http } ) ,
211
- site = new bitballoon . Client . models . Site ( client , { id : "123" , state : "processing" } ) ;
212
-
210
+ var client = netlify . createClient ( { access_token : "1234" , http : http } ) ,
211
+ site = new netlify . Client . models . Site ( client , { id : "123" , state : "processing" } ) ;
212
+
213
213
testApiCall ( {
214
214
http : {
215
215
expectations : function ( options ) {
216
216
expect ( options . headers [ 'Authorization' ] ) . toEqual ( "Bearer 1234" ) ;
217
217
expect ( options . method ) . toEqual ( "get" ) ;
218
- expect ( options . path ) . toEqual ( "/api/v1/sites/123" ) ;
218
+ expect ( options . path ) . toEqual ( "/api/v1/sites/123" ) ;
219
219
} ,
220
220
response : { id : 123 , state : "current" }
221
221
} ,
@@ -226,10 +226,10 @@ describe("bitballoon", function() {
226
226
}
227
227
} ) ;
228
228
} ) ;
229
-
229
+
230
230
it ( "should update a site" , function ( ) {
231
- var client = bitballoon . createClient ( { access_token : "1234" , http : http } ) ,
232
- site = new bitballoon . Client . models . Site ( client , { id : "123" , name : "test" } ) ;
231
+ var client = netlify . createClient ( { access_token : "1234" , http : http } ) ,
232
+ site = new netlify . Client . models . Site ( client , { id : "123" , name : "test" } ) ;
233
233
234
234
testApiCall ( {
235
235
http : {
@@ -249,10 +249,10 @@ describe("bitballoon", function() {
249
249
}
250
250
} ) ;
251
251
} ) ;
252
-
252
+
253
253
it ( "should destroy a site" , function ( ) {
254
- var client = bitballoon . createClient ( { access_token : "1234" , http : http } ) ,
255
- site = new bitballoon . Client . models . Site ( client , { id : "123" , name : "test" } ) ,
254
+ var client = netlify . createClient ( { access_token : "1234" , http : http } ) ,
255
+ site = new netlify . Client . models . Site ( client , { id : "123" , name : "test" } ) ,
256
256
done = false ;
257
257
258
258
testApiCall ( {
@@ -274,11 +274,11 @@ describe("bitballoon", function() {
274
274
}
275
275
} ) ;
276
276
} ) ;
277
-
277
+
278
278
it ( "should list all forms" , function ( ) {
279
- var client = bitballoon . createClient ( { access_token : "1234" , http : http } ) ,
279
+ var client = netlify . createClient ( { access_token : "1234" , http : http } ) ,
280
280
forms = null ;
281
-
281
+
282
282
testApiCall ( {
283
283
http : {
284
284
expectations : function ( options ) {
@@ -294,12 +294,12 @@ describe("bitballoon", function() {
294
294
}
295
295
} ) ;
296
296
} ) ;
297
-
297
+
298
298
it ( "should list forms for a site" , function ( ) {
299
- var client = bitballoon . createClient ( { access_token : "1234" , http : http } ) ,
300
- site = new bitballoon . Client . models . Site ( client , { id : "123" , name : "test" } ) ,
299
+ var client = netlify . createClient ( { access_token : "1234" , http : http } ) ,
300
+ site = new netlify . Client . models . Site ( client , { id : "123" , name : "test" } ) ,
301
301
forms = null ;
302
-
302
+
303
303
testApiCall ( {
304
304
http : {
305
305
expectations : function ( options ) {
@@ -315,11 +315,11 @@ describe("bitballoon", function() {
315
315
}
316
316
} ) ;
317
317
} )
318
-
318
+
319
319
it ( "should create a user" , function ( ) {
320
- var client = bitballoon . createClient ( { access_token : "1234" , http : http } ) ,
320
+ var client = netlify . createClient ( { access_token : "1234" , http : http } ) ,
321
321
user = null ;
322
-
322
+
323
323
testApiCall ( {
324
324
http : {
325
325
expectations : function ( options ) {
@@ -339,10 +339,10 @@ describe("bitballoon", function() {
339
339
}
340
340
} )
341
341
} ) ;
342
-
342
+
343
343
it ( "should update a user" , function ( ) {
344
- var client = bitballoon . createClient ( { access_token : "1234" , http : http } ) ,
345
- user = new bitballoon . Client . models . User ( client , { id : "123" , email : "test@example.com" } ) ,
344
+ var client = netlify . createClient ( { access_token : "1234" , http : http } ) ,
345
+ user = new netlify . Client . models . User ( client , { id : "123" , email : "test@example.com" } ) ,
346
346
done = false ;
347
347
348
348
testApiCall ( {
@@ -364,10 +364,10 @@ describe("bitballoon", function() {
364
364
}
365
365
} ) ;
366
366
} ) ;
367
-
367
+
368
368
it ( "should destroy a user" , function ( ) {
369
- var client = bitballoon . createClient ( { access_token : "1234" , http : http } ) ,
370
- user = new bitballoon . Client . models . User ( client , { id : "123" , email : "test@example.com" } ) ,
369
+ var client = netlify . createClient ( { access_token : "1234" , http : http } ) ,
370
+ user = new netlify . Client . models . User ( client , { id : "123" , email : "test@example.com" } ) ,
371
371
done = false ;
372
372
373
373
testApiCall ( {
@@ -389,12 +389,12 @@ describe("bitballoon", function() {
389
389
}
390
390
} ) ;
391
391
} ) ;
392
-
392
+
393
393
it ( "should create a snippet" , function ( ) {
394
- var client = bitballoon . createClient ( { access_token : "1234" , http : http } ) ,
395
- site = new bitballoon . Client . models . Site ( client , { id : "123" , name : "test" } ) ,
394
+ var client = netlify . createClient ( { access_token : "1234" , http : http } ) ,
395
+ site = new netlify . Client . models . Site ( client , { id : "123" , name : "test" } ) ,
396
396
snippet = null ;
397
-
397
+
398
398
testApiCall ( {
399
399
http : {
400
400
expectations : function ( options ) {
@@ -417,10 +417,10 @@ describe("bitballoon", function() {
417
417
}
418
418
} ) ;
419
419
} ) ;
420
-
420
+
421
421
it ( "should update a snippet" , function ( ) {
422
- var client = bitballoon . createClient ( { access_token : "1234" , http : http } ) ,
423
- snippet = new bitballoon . Client . models . Snippet ( client , { id : "1" , title : "test" , site_id : "123" } ) ,
422
+ var client = netlify . createClient ( { access_token : "1234" , http : http } ) ,
423
+ snippet = new netlify . Client . models . Snippet ( client , { id : "1" , title : "test" , site_id : "123" } ) ,
424
424
done = false ;
425
425
426
426
testApiCall ( {
@@ -444,10 +444,10 @@ describe("bitballoon", function() {
444
444
}
445
445
} )
446
446
} ) ;
447
-
447
+
448
448
it ( "should delete a snippet" , function ( ) {
449
- var client = bitballoon . createClient ( { access_token : "1234" , http : http } ) ,
450
- snippet = new bitballoon . Client . models . Snippet ( client , { id : "1" , title : "test" , site_id : "123" } ) ,
449
+ var client = netlify . createClient ( { access_token : "1234" , http : http } ) ,
450
+ snippet = new netlify . Client . models . Snippet ( client , { id : "1" , title : "test" , site_id : "123" } ) ,
451
451
done = false ;
452
452
453
453
testApiCall ( {
@@ -468,11 +468,11 @@ describe("bitballoon", function() {
468
468
expect ( done ) . toEqual ( true ) ;
469
469
}
470
470
} )
471
- } ) ;
472
-
471
+ } ) ;
472
+
473
473
it ( "should restore an old deploy" , function ( ) {
474
- var client = bitballoon . createClient ( { access_token : "1234" , http : http } ) ,
475
- deploy = new bitballoon . Client . models . Deploy ( client , { id : "1" , state : "old" , site_id : "123" } ) ,
474
+ var client = netlify . createClient ( { access_token : "1234" , http : http } ) ,
475
+ deploy = new netlify . Client . models . Deploy ( client , { id : "1" , state : "old" , site_id : "123" } ) ,
476
476
done = false ;
477
477
478
478
testApiCall ( {
@@ -494,17 +494,17 @@ describe("bitballoon", function() {
494
494
}
495
495
} ) ;
496
496
} ) ;
497
-
497
+
498
498
// Node specific methods
499
499
if ( typeof ( window ) === "undefined" ) {
500
500
var crypto = require ( 'crypto' ) ,
501
501
fs = require ( 'fs' ) ;
502
-
502
+
503
503
it ( "should upload a site from a dir" , function ( ) {
504
- var client = bitballoon . createClient ( { access_token : "1234" , http : http } ) ,
504
+ var client = netlify . createClient ( { access_token : "1234" , http : http } ) ,
505
505
site = null ,
506
506
shasum = crypto . createHash ( 'sha1' ) ;
507
-
507
+
508
508
shasum . update ( fs . readFileSync ( __dirname + '/files/site-dir/index.html' ) ) ;
509
509
510
510
var index_sha = shasum . digest ( 'hex' ) ;
@@ -515,7 +515,7 @@ describe("bitballoon", function() {
515
515
expectations : function ( options ) {
516
516
expect ( options . headers [ 'Authorization' ] ) . toEqual ( "Bearer 1234" ) ;
517
517
expect ( options . method ) . toEqual ( "post" ) ;
518
- expect ( options . path ) . toEqual ( "/api/v1/sites" ) ;
518
+ expect ( options . path ) . toEqual ( "/api/v1/sites" ) ;
519
519
} ,
520
520
status : 201 ,
521
521
response : { id : 123 , state : "uploading" , required : [ index_sha ] }
@@ -533,7 +533,7 @@ describe("bitballoon", function() {
533
533
expectations : function ( options ) {
534
534
expect ( options . headers [ 'Authorization' ] ) . toEqual ( "Bearer 1234" ) ;
535
535
expect ( options . method ) . toEqual ( "get" ) ;
536
- expect ( options . path ) . toEqual ( "/api/v1/sites/123" ) ;
536
+ expect ( options . path ) . toEqual ( "/api/v1/sites/123" ) ;
537
537
} ,
538
538
response : { id : 123 , state : "processing" }
539
539
}
@@ -547,11 +547,11 @@ describe("bitballoon", function() {
547
547
}
548
548
} ) ;
549
549
} ) ;
550
-
550
+
551
551
it ( "should upload a site from a zip" , function ( ) {
552
- var client = bitballoon . createClient ( { access_token : "1234" , http : http } ) ,
552
+ var client = netlify . createClient ( { access_token : "1234" , http : http } ) ,
553
553
site = null ;
554
-
554
+
555
555
testApiCall ( {
556
556
http : {
557
557
expectations : function ( options ) {
@@ -572,4 +572,4 @@ describe("bitballoon", function() {
572
572
} )
573
573
} ) ;
574
574
}
575
- } ) ;
575
+ } ) ;
0 commit comments