Skip to content

Commit 357fac1

Browse files
authored
Fix only one reviewer on PR page (#8153)
* Fix only one reviewer on PR page * Tets
1 parent 66a2b23 commit 357fac1

File tree

2 files changed

+143
-2
lines changed

2 files changed

+143
-2
lines changed

src/github/graphql.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ export interface Account extends Actor {
122122

123123
export function isAccount(x: Actor | Team | Node | undefined | null): x is Account {
124124
const asAccount = x as Partial<Account>;
125-
return !!asAccount && !!asAccount?.name && (asAccount?.email !== undefined);
125+
return !!asAccount && (asAccount?.name !== undefined) && (asAccount?.email !== undefined);
126126
}
127127

128128
export function isTeam(x: Actor | Team | Node | undefined | null): x is Team {
129129
const asTeam = x as Partial<Team>;
130-
return !!asTeam && !!asTeam?.slug;
130+
return !!asTeam && (asTeam?.slug !== undefined);
131131
}
132132

133133
export interface Team {

src/test/github/graphql.test.ts

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as assert from 'assert';
7+
import { isAccount, isTeam, Actor, Account, Team, Node } from '../../github/graphql';
8+
9+
describe('graphql type guards', () => {
10+
11+
describe('isAccount', () => {
12+
it('returns true for a valid Account', () => {
13+
const account: Account = {
14+
__typename: 'User',
15+
id: 'acct1',
16+
login: 'alice',
17+
avatarUrl: 'https://example.com/a.png',
18+
url: 'https://example.com/alice',
19+
name: 'Alice',
20+
email: 'alice@example.com'
21+
};
22+
assert.strictEqual(isAccount(account), true);
23+
});
24+
25+
it('returns false for Actor missing name/email', () => {
26+
const actor: Actor = {
27+
__typename: 'User',
28+
id: 'act1',
29+
login: 'bob',
30+
avatarUrl: 'https://example.com/b.png',
31+
url: 'https://example.com/bob'
32+
};
33+
assert.strictEqual(isAccount(actor), false);
34+
});
35+
36+
it('returns false for Team object', () => {
37+
const team: Team = {
38+
avatarUrl: 'https://example.com/t.png',
39+
name: 'Dev Team',
40+
url: 'https://example.com/team',
41+
repositories: { nodes: [] },
42+
slug: 'dev-team',
43+
id: 'team1'
44+
};
45+
assert.strictEqual(isAccount(team), false);
46+
});
47+
48+
it('returns false for Node object', () => {
49+
const node: Node = { id: 'node1' };
50+
assert.strictEqual(isAccount(node), false);
51+
});
52+
53+
it('returns false for null and undefined', () => {
54+
assert.strictEqual(isAccount(null), false);
55+
assert.strictEqual(isAccount(undefined), false);
56+
});
57+
58+
it('returns true when name and email are null', () => {
59+
const obj: any = {
60+
__typename: 'User', id: 'null1', login: 'nullUser', avatarUrl: '', url: '', name: null, email: null
61+
};
62+
assert.strictEqual(isAccount(obj), true);
63+
});
64+
65+
it('returns true when name is null but email present', () => {
66+
const obj: any = {
67+
__typename: 'User', id: 'null2', login: 'nullName', avatarUrl: '', url: '', name: null, email: 'e@example.com'
68+
};
69+
assert.strictEqual(isAccount(obj), true);
70+
});
71+
72+
it('returns false when email or name is undefined', () => {
73+
const obj: any = {
74+
__typename: 'User', id: 'null3', login: 'nullEmail', avatarUrl: '', url: '', name: undefined, email: undefined
75+
};
76+
assert.strictEqual(isAccount(obj), false);
77+
});
78+
});
79+
80+
describe('isTeam', () => {
81+
it('returns true for a valid Team', () => {
82+
const team: Team = {
83+
avatarUrl: 'https://example.com/t.png',
84+
name: 'Engineering',
85+
url: 'https://example.com/eng',
86+
repositories: { nodes: [] },
87+
slug: 'engineering',
88+
id: 'team2'
89+
};
90+
assert.strictEqual(isTeam(team), true);
91+
});
92+
93+
it('returns false for Account object', () => {
94+
const account: Account = {
95+
__typename: 'User',
96+
id: 'acct2',
97+
login: 'carol',
98+
avatarUrl: 'https://example.com/c.png',
99+
url: 'https://example.com/carol',
100+
name: 'Carol',
101+
email: 'carol@example.com'
102+
};
103+
assert.strictEqual(isTeam(account), false);
104+
});
105+
106+
it('returns false for Actor without slug', () => {
107+
const actor: Actor = {
108+
__typename: 'User',
109+
id: 'act2',
110+
login: 'dave',
111+
avatarUrl: 'https://example.com/d.png',
112+
url: 'https://example.com/dave'
113+
};
114+
assert.strictEqual(isTeam(actor), false);
115+
});
116+
117+
it('returns false for Node object', () => {
118+
const node: Node = { id: 'node2' };
119+
assert.strictEqual(isTeam(node), false);
120+
});
121+
122+
it('returns false for null and undefined', () => {
123+
assert.strictEqual(isTeam(null), false);
124+
assert.strictEqual(isTeam(undefined), false);
125+
});
126+
127+
it('returns false when slug is undefined', () => {
128+
const obj: any = {
129+
avatarUrl: '', name: 'Team', url: '', repositories: { nodes: [] }, slug: undefined, id: 'tslugnull'
130+
};
131+
assert.strictEqual(isTeam(obj), false);
132+
});
133+
it('returns true when slug is null', () => {
134+
const obj: any = {
135+
avatarUrl: '', name: 'Team', url: '', repositories: { nodes: [] }, slug: null, id: 'tslugnull'
136+
};
137+
assert.strictEqual(isTeam(obj), true);
138+
});
139+
});
140+
});
141+

0 commit comments

Comments
 (0)