-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
119 lines (105 loc) · 2.69 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const assert = require('assert')
// Query by teamId
setupGithubServer(function (err, server) {
if (err) throw err
const keys = require('./keys')({
token: 'mock',
host: `localhost`,
protocol: 'http',
port: server.port
})
keys.get({teamId: 123})
.then((users) => {
assert.ok(Array.isArray(users), 'Expect response to be an array of users')
assert.deepEqual(users, [{
id: 12345,
login: 'foo',
avatar_url: 'http://github.com/some/avatar/url',
keys: ['ssh-rsa firstfookey']
}, {
id: 23456,
login: 'bar',
avatar_url: 'http://github.com/some/avatar/url',
keys: ['ssh-rsa firstbarkey', 'ssh-rsa secondbarkey']
}])
})
.catch(function (err) {
console.error(err)
server.destroy()
process.exit(1)
})
.then(server.destroy)
})
// Query by orgName & teamName
setupGithubServer(function (err, server) {
if (err) throw err
const keys = require('./keys')({
token: 'mock',
host: `localhost`,
protocol: 'http',
port: server.port
})
keys.get({org: 'some-org', teamName: 'Some team'})
.then((users) => {
assert.ok(Array.isArray(users), 'Expect response to be an array of users')
assert.deepEqual(users, [{
id: 12345,
login: 'foo',
avatar_url: 'http://github.com/some/avatar/url',
keys: ['ssh-rsa firstfookey']
}, {
id: 23456,
login: 'bar',
avatar_url: 'http://github.com/some/avatar/url',
keys: ['ssh-rsa firstbarkey', 'ssh-rsa secondbarkey']
}])
})
.catch(function (err) {
console.error(err)
server.destroy()
process.exit(1)
})
.then(server.destroy)
})
function setupGithubServer (cb) {
const fastify = require('fastify')()
fastify.get('/orgs/some-org/teams', (req, rep) => {
rep.send([{
id: 123,
name: 'Some team'
}])
})
fastify.get('/teams/123/members', (req, rep) => {
rep.send([{
id: 12345,
login: 'foo',
avatar_url: 'http://github.com/some/avatar/url',
type: 'User'
}, {
id: 23456,
login: 'bar',
avatar_url: 'http://github.com/some/avatar/url',
type: 'User'
}])
})
fastify.get('/users/foo/keys', (req, rep) => {
rep.send([{
id: 12346,
key: 'ssh-rsa firstfookey'
}])
})
fastify.get('/users/bar/keys', (req, rep) => {
rep.send([{
id: 23457,
key: 'ssh-rsa firstbarkey'
}, {
id: 23458,
key: 'ssh-rsa secondbarkey'
}])
})
fastify.listen(0, function (err) {
if (err) return cb(err)
const server = fastify.server
cb(null, {port: server.address().port, destroy: server.close.bind(server)})
})
}