forked from nodejs/node-core-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteam_info.test.js
More file actions
83 lines (71 loc) · 2.48 KB
/
team_info.test.js
File metadata and controls
83 lines (71 loc) · 2.48 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
'use strict';
const assert = require('assert');
const sinon = require('sinon');
const TestCLI = require('../fixtures/test_cli');
const TeamInfo = require('../../lib/team_info');
const { readJSON, readFile, path: getPath } = require('../fixtures');
const collabList =
`- [@Bar](https://github.com/Bar) - Bar Bar
- [@foo](https://github.com/foo) - Mr. foo
- [@quo](https://github.com/quo) - Ms. Quo`;
describe('TeamInfo', function() {
let request;
let cli;
before(() => {
cli = new TestCLI();
request = {
gql: sinon.stub()
};
const collab = readJSON('team_collab.json');
const bots = readJSON('team_bots.json');
request.gql.withArgs(
'Team',
{ org: 'nodejs', team: 'automation-collaborators' },
['organization', 'team', 'members']
).returns(Promise.resolve(collab.organization.team.members.nodes));
request.gql.withArgs(
'Team',
{ org: 'nodejs', team: 'bots' },
['organization', 'team', 'members']
).returns(Promise.resolve(bots.organization.team.members.nodes));
request.gql.returns(new Error('unknown query'));
});
after(() => {
cli.clearCalls();
});
it('getMembersContact', async() => {
const data = new TeamInfo(
cli, request, 'nodejs', 'automation-collaborators');
const contact = await data.getMemberContacts();
assert.strictEqual(contact, collabList);
});
it('syncFile() with empty file', async() => {
const expected = readFile('ncu_team_sync_expected.md');
await TeamInfo.syncFile(cli, request,
getPath('ncu_team_sync_in.md'),
getPath('ncu_team_sync_out.md'));
const actual = readFile('ncu_team_sync_out.md');
assert.strictEqual(expected, actual);
});
it('syncFile() with old file', async() => {
const expected = readFile('ncu_team_sync_expected.md');
await TeamInfo.syncFile(cli, request,
getPath('ncu_team_sync_out.md'));
const actual = readFile('ncu_team_sync_out.md');
assert.strictEqual(expected, actual);
});
it('syncFile() with a file without special blocks', async() => {
const expected = readFile('README', 'README.md');
let thrown = null;
try {
await TeamInfo.syncFile(cli, request, getPath('README', 'README.md'));
} catch (err) {
thrown = err;
}
assert(thrown instanceof Error);
assert(thrown.message, 'Could not find blocks matching ' +
'<!-- ncu-team-sync.team($org/$team)>');
const actual = readFile('README', 'README.md');
assert.strictEqual(expected, actual);
});
});