forked from github-tools/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteam.spec.js
More file actions
146 lines (123 loc) · 4.07 KB
/
team.spec.js
File metadata and controls
146 lines (123 loc) · 4.07 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
import expect from 'must';
import Github from '../lib/GitHub';
import testUser from './fixtures/user.json';
import {assertFailure} from './helpers/callbacks';
import getTestRepoName from './helpers/getTestRepoName';
const altUser = {
USERNAME: 'mtscout6-test'
};
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'
});
team = github.getTeam(2027812); // github-api-tests/fixed-test-team-1
});
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();
let hasTestUser = members.reduce(
(found, member) => member.login === testUser.USERNAME || found,
false
);
expect(hasTestUser).to.be.true();
});
});
it('should get team repos', function() {
return team.listRepos()
.then(({data}) => {
const hasRepo = data.reduce(
(found, repo) => repo.name === 'fixed-test-repo-1' || found,
false
);
expect(hasRepo).to.be.true();
});
});
it('should get team', function() {
return team.getTeam()
.then(({data}) => {
expect(data.name).to.equal('Fixed Test Team 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(function(done) {
team.deleteTeam()
.then(() => team.getTeam(assertFailure(done)));
});
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', function() {
return team.addMembership(testUser.USERNAME)
.then(({data}) => {
const {state, role} = data;
expect(state === 'active' || state === 'pending').to.be.true();
expect(role).to.equal('member');
});
});
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();
});
});
});