From 5a637925e898900839140b273adca026eb97c88c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 1 Jul 2025 22:12:23 +0000 Subject: [PATCH 1/2] Initial plan From 5b4cbc1b7d4afa05417697985211464689d0cc00 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 1 Jul 2025 22:21:08 +0000 Subject: [PATCH 2/2] Fix null assignee handling in Seat model to prevent 500 errors Co-authored-by: karpikpl <3539908+karpikpl@users.noreply.github.com> --- app/model/Seat.ts | 4 +- .../enterprise_seats_response_sample.json | 11 +- .../organization_seats_response_sample.json | 25 +++- tests/Seat.nuxt.spec.ts | 124 ++++++++++++++++++ 4 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 tests/Seat.nuxt.spec.ts diff --git a/app/model/Seat.ts b/app/model/Seat.ts index 984a9a7f..7a9c94b7 100644 --- a/app/model/Seat.ts +++ b/app/model/Seat.ts @@ -7,8 +7,8 @@ export class Seat { last_activity_editor: string; constructor(data: any) { - this.login = data.assignee.login; - this.id = data.assignee.id; + this.login = data.assignee ? data.assignee.login : 'deprecated'; + this.id = data.assignee ? data.assignee.id : 0; this.team = data.assigning_team ? data.assigning_team.name : ''; this.created_at = data.created_at; this.last_activity_at = data.last_activity_at; diff --git a/public/mock-data/enterprise_seats_response_sample.json b/public/mock-data/enterprise_seats_response_sample.json index 2399b99d..c5ebf025 100644 --- a/public/mock-data/enterprise_seats_response_sample.json +++ b/public/mock-data/enterprise_seats_response_sample.json @@ -1,5 +1,5 @@ { - "total_seats": 2, + "total_seats": 3, "seats": [ { "created_at": "2021-08-03T18:00:00-06:00", @@ -69,6 +69,15 @@ "type": "User", "site_admin": false } + }, + { + "created_at": "2021-09-23T18:00:00-06:00", + "updated_at": "2021-09-23T15:00:00-06:00", + "pending_cancellation_date": "2021-11-01", + "last_activity_at": "2021-10-12T00:53:32-06:00", + "last_activity_editor": "vscode/1.77.3/copilot/1.86.82", + "assignee": null, + "assigning_team": null } ] } \ No newline at end of file diff --git a/public/mock-data/organization_seats_response_sample.json b/public/mock-data/organization_seats_response_sample.json index b3bbad76..652c0ff4 100644 --- a/public/mock-data/organization_seats_response_sample.json +++ b/public/mock-data/organization_seats_response_sample.json @@ -1,5 +1,5 @@ { - "total_seats": 2, + "total_seats": 3, "seats": [ { "created_at": "2021-08-03T18:00:00-06:00", @@ -69,6 +69,29 @@ "type": "User", "site_admin": false } + }, + { + "created_at": "2021-09-23T18:00:00-06:00", + "updated_at": "2021-09-23T15:00:00-06:00", + "pending_cancellation_date": "2021-11-01", + "last_activity_at": "2021-10-12T00:53:32-06:00", + "last_activity_editor": "vscode/1.77.3/copilot/1.86.82", + "assignee": null, + "assigning_team": { + "id": 1, + "node_id": "MDQ6VGVhbTE=", + "url": "https://api.github.com/teams/1", + "html_url": "https://github.com/orgs/github/teams/justice-league", + "name": "Justice League", + "slug": "justice-league", + "description": "A great team.", + "privacy": "closed", + "notification_setting": "notifications_enabled", + "permission": "admin", + "members_url": "https://api.github.com/teams/1/members{/member}", + "repositories_url": "https://api.github.com/teams/1/repos", + "parent": null + } } ] } \ No newline at end of file diff --git a/tests/Seat.nuxt.spec.ts b/tests/Seat.nuxt.spec.ts new file mode 100644 index 00000000..0563864a --- /dev/null +++ b/tests/Seat.nuxt.spec.ts @@ -0,0 +1,124 @@ +// @vitest-environment nuxt +import { describe, test, expect } from 'vitest' +import { Seat } from '@/model/Seat' + +describe('Seat.ts', () => { + test('handles normal seat data with assignee', () => { + const seatData = { + assignee: { + login: 'octocat', + id: 123 + }, + assigning_team: { + name: 'Justice League' + }, + created_at: '2021-08-03T18:00:00-06:00', + last_activity_at: '2021-10-14T00:53:32-06:00', + last_activity_editor: 'vscode/1.77.3/copilot/1.86.82' + } + + const seat = new Seat(seatData) + + expect(seat.login).toBe('octocat') + expect(seat.id).toBe(123) + expect(seat.team).toBe('Justice League') + expect(seat.created_at).toBe('2021-08-03T18:00:00-06:00') + expect(seat.last_activity_at).toBe('2021-10-14T00:53:32-06:00') + expect(seat.last_activity_editor).toBe('vscode/1.77.3/copilot/1.86.82') + }) + + test('handles seat data without assigning_team', () => { + const seatData = { + assignee: { + login: 'octocat', + id: 123 + }, + assigning_team: null, + created_at: '2021-08-03T18:00:00-06:00', + last_activity_at: '2021-10-14T00:53:32-06:00', + last_activity_editor: 'vscode/1.77.3/copilot/1.86.82' + } + + const seat = new Seat(seatData) + + expect(seat.login).toBe('octocat') + expect(seat.id).toBe(123) + expect(seat.team).toBe('') + expect(seat.created_at).toBe('2021-08-03T18:00:00-06:00') + expect(seat.last_activity_at).toBe('2021-10-14T00:53:32-06:00') + expect(seat.last_activity_editor).toBe('vscode/1.77.3/copilot/1.86.82') + }) + + test('handles seat data with null assignee - should not throw error', () => { + const seatData = { + assignee: null, + assigning_team: { + name: 'Justice League' + }, + created_at: '2021-08-03T18:00:00-06:00', + last_activity_at: '2021-10-14T00:53:32-06:00', + last_activity_editor: 'vscode/1.77.3/copilot/1.86.82' + } + + // This should not throw an error after the fix + expect(() => new Seat(seatData)).not.toThrow() + + const seat = new Seat(seatData) + + // Should use fallback values for null assignee + expect(seat.login).toBe('deprecated') + expect(seat.id).toBe(0) + expect(seat.team).toBe('Justice League') + expect(seat.created_at).toBe('2021-08-03T18:00:00-06:00') + expect(seat.last_activity_at).toBe('2021-10-14T00:53:32-06:00') + expect(seat.last_activity_editor).toBe('vscode/1.77.3/copilot/1.86.82') + }) + + test('handles seat data with null assignee and null assigning_team', () => { + const seatData = { + assignee: null, + assigning_team: null, + created_at: '2021-08-03T18:00:00-06:00', + last_activity_at: '2021-10-14T00:53:32-06:00', + last_activity_editor: 'vscode/1.77.3/copilot/1.86.82' + } + + // This should not throw an error after the fix + expect(() => new Seat(seatData)).not.toThrow() + + const seat = new Seat(seatData) + + // Should use fallback values for both null fields + expect(seat.login).toBe('deprecated') + expect(seat.id).toBe(0) + expect(seat.team).toBe('') + expect(seat.created_at).toBe('2021-08-03T18:00:00-06:00') + expect(seat.last_activity_at).toBe('2021-10-14T00:53:32-06:00') + expect(seat.last_activity_editor).toBe('vscode/1.77.3/copilot/1.86.82') + }) + + test('handles mock data with null assignee like in organization_seats_response_sample.json', () => { + // This simulates the exact structure from our updated mock data + const seatDataFromMock = { + "created_at": "2021-09-23T18:00:00-06:00", + "updated_at": "2021-09-23T15:00:00-06:00", + "pending_cancellation_date": "2021-11-01", + "last_activity_at": "2021-10-12T00:53:32-06:00", + "last_activity_editor": "vscode/1.77.3/copilot/1.86.82", + "assignee": null, + "assigning_team": { + "id": 1, + "name": "Justice League", + "slug": "justice-league" + } + } + + expect(() => new Seat(seatDataFromMock)).not.toThrow() + + const seat = new Seat(seatDataFromMock) + + expect(seat.login).toBe('deprecated') + expect(seat.id).toBe(0) + expect(seat.team).toBe('Justice League') + }) +}) \ No newline at end of file