Skip to content

Commit 0a85900

Browse files
Copilotkarpikpl
andauthored
Fix null assignee handling in Seat model to prevent 500 Internal Server Error (#217)
* Initial plan * Fix null assignee handling in Seat model to prevent 500 errors Co-authored-by: karpikpl <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: karpikpl <[email protected]>
1 parent 2906bd0 commit 0a85900

File tree

4 files changed

+160
-4
lines changed

4 files changed

+160
-4
lines changed

app/model/Seat.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export class Seat {
77
last_activity_editor: string;
88

99
constructor(data: any) {
10-
this.login = data.assignee.login;
11-
this.id = data.assignee.id;
10+
this.login = data.assignee ? data.assignee.login : 'deprecated';
11+
this.id = data.assignee ? data.assignee.id : 0;
1212
this.team = data.assigning_team ? data.assigning_team.name : '';
1313
this.created_at = data.created_at;
1414
this.last_activity_at = data.last_activity_at;

public/mock-data/enterprise_seats_response_sample.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"total_seats": 2,
2+
"total_seats": 3,
33
"seats": [
44
{
55
"created_at": "2021-08-03T18:00:00-06:00",
@@ -69,6 +69,15 @@
6969
"type": "User",
7070
"site_admin": false
7171
}
72+
},
73+
{
74+
"created_at": "2021-09-23T18:00:00-06:00",
75+
"updated_at": "2021-09-23T15:00:00-06:00",
76+
"pending_cancellation_date": "2021-11-01",
77+
"last_activity_at": "2021-10-12T00:53:32-06:00",
78+
"last_activity_editor": "vscode/1.77.3/copilot/1.86.82",
79+
"assignee": null,
80+
"assigning_team": null
7281
}
7382
]
7483
}

public/mock-data/organization_seats_response_sample.json

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"total_seats": 2,
2+
"total_seats": 3,
33
"seats": [
44
{
55
"created_at": "2021-08-03T18:00:00-06:00",
@@ -69,6 +69,29 @@
6969
"type": "User",
7070
"site_admin": false
7171
}
72+
},
73+
{
74+
"created_at": "2021-09-23T18:00:00-06:00",
75+
"updated_at": "2021-09-23T15:00:00-06:00",
76+
"pending_cancellation_date": "2021-11-01",
77+
"last_activity_at": "2021-10-12T00:53:32-06:00",
78+
"last_activity_editor": "vscode/1.77.3/copilot/1.86.82",
79+
"assignee": null,
80+
"assigning_team": {
81+
"id": 1,
82+
"node_id": "MDQ6VGVhbTE=",
83+
"url": "https://api.github.com/teams/1",
84+
"html_url": "https://github.com/orgs/github/teams/justice-league",
85+
"name": "Justice League",
86+
"slug": "justice-league",
87+
"description": "A great team.",
88+
"privacy": "closed",
89+
"notification_setting": "notifications_enabled",
90+
"permission": "admin",
91+
"members_url": "https://api.github.com/teams/1/members{/member}",
92+
"repositories_url": "https://api.github.com/teams/1/repos",
93+
"parent": null
94+
}
7295
}
7396
]
7497
}

tests/Seat.nuxt.spec.ts

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// @vitest-environment nuxt
2+
import { describe, test, expect } from 'vitest'
3+
import { Seat } from '@/model/Seat'
4+
5+
describe('Seat.ts', () => {
6+
test('handles normal seat data with assignee', () => {
7+
const seatData = {
8+
assignee: {
9+
login: 'octocat',
10+
id: 123
11+
},
12+
assigning_team: {
13+
name: 'Justice League'
14+
},
15+
created_at: '2021-08-03T18:00:00-06:00',
16+
last_activity_at: '2021-10-14T00:53:32-06:00',
17+
last_activity_editor: 'vscode/1.77.3/copilot/1.86.82'
18+
}
19+
20+
const seat = new Seat(seatData)
21+
22+
expect(seat.login).toBe('octocat')
23+
expect(seat.id).toBe(123)
24+
expect(seat.team).toBe('Justice League')
25+
expect(seat.created_at).toBe('2021-08-03T18:00:00-06:00')
26+
expect(seat.last_activity_at).toBe('2021-10-14T00:53:32-06:00')
27+
expect(seat.last_activity_editor).toBe('vscode/1.77.3/copilot/1.86.82')
28+
})
29+
30+
test('handles seat data without assigning_team', () => {
31+
const seatData = {
32+
assignee: {
33+
login: 'octocat',
34+
id: 123
35+
},
36+
assigning_team: null,
37+
created_at: '2021-08-03T18:00:00-06:00',
38+
last_activity_at: '2021-10-14T00:53:32-06:00',
39+
last_activity_editor: 'vscode/1.77.3/copilot/1.86.82'
40+
}
41+
42+
const seat = new Seat(seatData)
43+
44+
expect(seat.login).toBe('octocat')
45+
expect(seat.id).toBe(123)
46+
expect(seat.team).toBe('')
47+
expect(seat.created_at).toBe('2021-08-03T18:00:00-06:00')
48+
expect(seat.last_activity_at).toBe('2021-10-14T00:53:32-06:00')
49+
expect(seat.last_activity_editor).toBe('vscode/1.77.3/copilot/1.86.82')
50+
})
51+
52+
test('handles seat data with null assignee - should not throw error', () => {
53+
const seatData = {
54+
assignee: null,
55+
assigning_team: {
56+
name: 'Justice League'
57+
},
58+
created_at: '2021-08-03T18:00:00-06:00',
59+
last_activity_at: '2021-10-14T00:53:32-06:00',
60+
last_activity_editor: 'vscode/1.77.3/copilot/1.86.82'
61+
}
62+
63+
// This should not throw an error after the fix
64+
expect(() => new Seat(seatData)).not.toThrow()
65+
66+
const seat = new Seat(seatData)
67+
68+
// Should use fallback values for null assignee
69+
expect(seat.login).toBe('deprecated')
70+
expect(seat.id).toBe(0)
71+
expect(seat.team).toBe('Justice League')
72+
expect(seat.created_at).toBe('2021-08-03T18:00:00-06:00')
73+
expect(seat.last_activity_at).toBe('2021-10-14T00:53:32-06:00')
74+
expect(seat.last_activity_editor).toBe('vscode/1.77.3/copilot/1.86.82')
75+
})
76+
77+
test('handles seat data with null assignee and null assigning_team', () => {
78+
const seatData = {
79+
assignee: null,
80+
assigning_team: null,
81+
created_at: '2021-08-03T18:00:00-06:00',
82+
last_activity_at: '2021-10-14T00:53:32-06:00',
83+
last_activity_editor: 'vscode/1.77.3/copilot/1.86.82'
84+
}
85+
86+
// This should not throw an error after the fix
87+
expect(() => new Seat(seatData)).not.toThrow()
88+
89+
const seat = new Seat(seatData)
90+
91+
// Should use fallback values for both null fields
92+
expect(seat.login).toBe('deprecated')
93+
expect(seat.id).toBe(0)
94+
expect(seat.team).toBe('')
95+
expect(seat.created_at).toBe('2021-08-03T18:00:00-06:00')
96+
expect(seat.last_activity_at).toBe('2021-10-14T00:53:32-06:00')
97+
expect(seat.last_activity_editor).toBe('vscode/1.77.3/copilot/1.86.82')
98+
})
99+
100+
test('handles mock data with null assignee like in organization_seats_response_sample.json', () => {
101+
// This simulates the exact structure from our updated mock data
102+
const seatDataFromMock = {
103+
"created_at": "2021-09-23T18:00:00-06:00",
104+
"updated_at": "2021-09-23T15:00:00-06:00",
105+
"pending_cancellation_date": "2021-11-01",
106+
"last_activity_at": "2021-10-12T00:53:32-06:00",
107+
"last_activity_editor": "vscode/1.77.3/copilot/1.86.82",
108+
"assignee": null,
109+
"assigning_team": {
110+
"id": 1,
111+
"name": "Justice League",
112+
"slug": "justice-league"
113+
}
114+
}
115+
116+
expect(() => new Seat(seatDataFromMock)).not.toThrow()
117+
118+
const seat = new Seat(seatDataFromMock)
119+
120+
expect(seat.login).toBe('deprecated')
121+
expect(seat.id).toBe(0)
122+
expect(seat.team).toBe('Justice League')
123+
})
124+
})

0 commit comments

Comments
 (0)