forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphql.test.ts
More file actions
141 lines (124 loc) · 4.13 KB
/
Copy pathgraphql.test.ts
File metadata and controls
141 lines (124 loc) · 4.13 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { isAccount, isTeam, Actor, Account, Team, Node } from '../../github/graphql';
describe('graphql type guards', () => {
describe('isAccount', () => {
it('returns true for a valid Account', () => {
const account: Account = {
__typename: 'User',
id: 'acct1',
login: 'alice',
avatarUrl: 'https://example.com/a.png',
url: 'https://example.com/alice',
name: 'Alice',
email: 'alice@example.com'
};
assert.strictEqual(isAccount(account), true);
});
it('returns false for Actor missing name/email', () => {
const actor: Actor = {
__typename: 'User',
id: 'act1',
login: 'bob',
avatarUrl: 'https://example.com/b.png',
url: 'https://example.com/bob'
};
assert.strictEqual(isAccount(actor), false);
});
it('returns false for Team object', () => {
const team: Team = {
avatarUrl: 'https://example.com/t.png',
name: 'Dev Team',
url: 'https://example.com/team',
repositories: { nodes: [] },
slug: 'dev-team',
id: 'team1'
};
assert.strictEqual(isAccount(team), false);
});
it('returns false for Node object', () => {
const node: Node = { id: 'node1' };
assert.strictEqual(isAccount(node), false);
});
it('returns false for null and undefined', () => {
assert.strictEqual(isAccount(null), false);
assert.strictEqual(isAccount(undefined), false);
});
it('returns true when name and email are null', () => {
const obj: any = {
__typename: 'User', id: 'null1', login: 'nullUser', avatarUrl: '', url: '', name: null, email: null
};
assert.strictEqual(isAccount(obj), true);
});
it('returns true when name is null but email present', () => {
const obj: any = {
__typename: 'User', id: 'null2', login: 'nullName', avatarUrl: '', url: '', name: null, email: 'e@example.com'
};
assert.strictEqual(isAccount(obj), true);
});
it('returns false when email or name is undefined', () => {
const obj: any = {
__typename: 'User', id: 'null3', login: 'nullEmail', avatarUrl: '', url: '', name: undefined, email: undefined
};
assert.strictEqual(isAccount(obj), false);
});
});
describe('isTeam', () => {
it('returns true for a valid Team', () => {
const team: Team = {
avatarUrl: 'https://example.com/t.png',
name: 'Engineering',
url: 'https://example.com/eng',
repositories: { nodes: [] },
slug: 'engineering',
id: 'team2'
};
assert.strictEqual(isTeam(team), true);
});
it('returns false for Account object', () => {
const account: Account = {
__typename: 'User',
id: 'acct2',
login: 'carol',
avatarUrl: 'https://example.com/c.png',
url: 'https://example.com/carol',
name: 'Carol',
email: 'carol@example.com'
};
assert.strictEqual(isTeam(account), false);
});
it('returns false for Actor without slug', () => {
const actor: Actor = {
__typename: 'User',
id: 'act2',
login: 'dave',
avatarUrl: 'https://example.com/d.png',
url: 'https://example.com/dave'
};
assert.strictEqual(isTeam(actor), false);
});
it('returns false for Node object', () => {
const node: Node = { id: 'node2' };
assert.strictEqual(isTeam(node), false);
});
it('returns false for null and undefined', () => {
assert.strictEqual(isTeam(null), false);
assert.strictEqual(isTeam(undefined), false);
});
it('returns false when slug is undefined', () => {
const obj: any = {
avatarUrl: '', name: 'Team', url: '', repositories: { nodes: [] }, slug: undefined, id: 'tslugnull'
};
assert.strictEqual(isTeam(obj), false);
});
it('returns true when slug is null', () => {
const obj: any = {
avatarUrl: '', name: 'Team', url: '', repositories: { nodes: [] }, slug: null, id: 'tslugnull'
};
assert.strictEqual(isTeam(obj), true);
});
});
});