-
Notifications
You must be signed in to change notification settings - Fork 800
Expand file tree
/
Copy pathteam.spec.js
More file actions
190 lines (164 loc) · 5.73 KB
/
team.spec.js
File metadata and controls
190 lines (164 loc) · 5.73 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import assert from 'assert';
import expect from 'must';
import Github from '../lib/GitHub';
import testUser from './fixtures/user.json';
import getTestRepoName from './helpers/getTestRepoName';
import altUser from './fixtures/alt-user.json';
function createTestTeam() {
const name = getTestRepoName();
const github = new Github({
username: testUser.USERNAME,
password: testUser.PASSWORD,
auth: 'basic',
});
const org = github.getOrganization(testUser.ORGANIZATION);
return org.createTeam({
name,
privacy: 'closed',
}).then(({data: result}) => {
const team = github.getTeam(result.id);
return {team, name};
});
}
let team;
let name;
describe('Team', function() { // Isolate tests that are based on a fixed team
before(function() {
const github = new Github({
username: testUser.USERNAME,
password: testUser.PASSWORD,
auth: 'basic',
});
const org = github.getOrganization(testUser.ORGANIZATION);
/* eslint-disable no-console */
// The code below add a fixed-test-repo-1
let promiseRepo = new Promise((resolve) => {
org
.createRepo({name: 'fixed-test-repo-1'})
.then(resolve, () => {
console.log('skiped fixed-test-repo-1 creation');
resolve();
});
});
// The code below add a fixed-test-repo-1
let promiseTeam = org
.createTeam({
name: 'fixed-test-repo-1',
repo_names: [testUser.ORGANIZATION + '/fixed-test-repo-1'], // eslint-disable-line camelcase
})
.then(({data: team}) => team)
.catch(() => {
console.log('skiped fixed-test-repo-1 creation');
// Team already exists, fetch the team
return org.getTeams().then(({data: teams}) => {
let team = teams
.filter((team) => team.name === 'fixed-test-repo-1')
.pop();
if (!team) {
throw new Error('missing fixed-test-repo-1');
}
return team;
});
});
/* eslint-enable no-console */
return promiseRepo.then(() => {
return promiseTeam
.then((t) => {
team = github.getTeam(t.id);
return team;
})
.then((team) => {
let setupTeam = [
team.addMembership(altUser.USERNAME),
team.addMembership(testUser.USERNAME),
team.manageRepo(testUser.ORGANIZATION, 'fixed-test-repo-1'),
];
return Promise.all(setupTeam);
});
});
});
it('should get membership for a given user', function() {
return team.getMembership(altUser.USERNAME)
.then(function({data}) {
expect(data.state).to.equal('active');
expect(data.role).to.equal('member');
});
});
it('should list the users in the team', function() {
return team.listMembers()
.then(function({data: members}) {
expect(members).to.be.an.array();
const hasTestUser = members.some((member) => member.login === testUser.USERNAME);
expect(hasTestUser).to.be.true();
});
});
it('should get team repos', function() {
return team.listRepos()
.then(({data}) => {
const hasRepo = data.some((repo) => repo.name === 'fixed-test-repo-1');
expect(hasRepo).to.be.true();
});
});
it('should get team', function() {
return team.getTeam()
.then(({data}) => {
expect(data.name).to.equal('fixed-test-repo-1');
});
});
it('should check if team manages repo', function() {
return team.isManagedRepo(testUser.ORGANIZATION, 'fixed-test-repo-1')
.then((result) => {
expect(result).to.be.true();
});
});
});
describe('Team', function() { // Isolate tests that need a new team per test
beforeEach(function() {
return createTestTeam()
.then((x) => {
team = x.team;
name = x.name;
});
});
// Test for Team deletion
afterEach(async function() {
await team.deleteTeam();
try {
await team.getTeam();
assert.fail(undefined, undefined, 'Failed to delete the team');
} catch (error) {
// Swallow intentionally
}
});
it('should update team', function() {
const newName = `${name}-updated`;
return team.editTeam({name: newName})
.then(function({data}) {
expect(data.name).to.equal(newName);
});
});
it('should add membership for a given user', async function() {
const {data: {state, role}} = await team.addMembership(testUser.USERNAME);
expect(state === 'active' || state === 'pending').to.be.true();
// TODO: This does not appear to match the documentation...
expect(role).to.equal('maintainer');
});
it('should add membership as a maintainer for a given user', function() {
return team.addMembership(altUser.USERNAME, {role: 'maintainer'})
.then(({data}) => {
const {state, role} = data;
expect(state === 'active' || state === 'pending').to.be.true();
expect(role).to.equal('maintainer');
});
});
it('should add/remove team management of repo', function() {
return team.manageRepo(testUser.ORGANIZATION, 'fixed-test-repo-1', {permission: 'pull'})
.then((result) => {
expect(result).to.be.true();
return team.unmanageRepo(testUser.ORGANIZATION, 'fixed-test-repo-1');
})
.then((result) => {
expect(result).to.be.true();
});
});
});