forked from heroku/node-heroku-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
82 lines (66 loc) · 1.73 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict'
const ava = require('ava')
const test = ava.test
const Heroku = require('.')
const heroku = new Heroku()
const nock = require('nock')
test.before(() => {
nock.disableNetConnect()
})
test('get /apps', t => {
let api = nock('https://api.heroku.com')
.get('/apps')
.reply(200, [{name: 'myapp'}])
return heroku.get('/apps')
.then(apps => {
t.is(apps[0].name, 'myapp')
})
.then(() => api.done())
})
test('post /apps', t => {
let api = nock('https://api.heroku.com')
.post('/apps', {name: 'myapp'})
.reply(201)
return heroku.post('/apps', {body: {name: 'myapp'}})
.then(() => api.done())
})
test('delete /apps', t => {
let api = nock('https://api.heroku.com')
.delete('/apps', {name: 'myapp'})
.reply(201)
return heroku.delete('/apps', {body: {name: 'myapp'}})
.then(() => api.done())
})
test('patch /apps', t => {
let api = nock('https://api.heroku.com')
.patch('/apps', {name: 'myapp'})
.reply(201)
return heroku.patch('/apps', {body: {name: 'myapp'}})
.then(() => api.done())
})
test('put /apps', t => {
let api = nock('https://api.heroku.com')
.put('/apps', {name: 'myapp'})
.reply(201)
return heroku.put('/apps', {body: {name: 'myapp'}})
.then(() => api.done())
})
test('non-http', t => {
let api = nock('http://api.heroku.com')
.get('/apps')
.reply(200, [{name: 'myapp'}])
return heroku.get('/apps', {host: 'http://api.heroku.com'})
.then(apps => {
t.is(apps[0].name, 'myapp')
})
.then(() => api.done())
})
test('url: https', t => {
const url = require('./lib/url')
t.true(url('https://api.heroku.com').secure)
t.true(url('api.heroku.com').secure)
})
test('url: http', t => {
const url = require('./lib/url')
t.false(url('http://api.heroku.com').secure)
})