Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/model/Seat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion public/mock-data/enterprise_seats_response_sample.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"total_seats": 2,
"total_seats": 3,
"seats": [
{
"created_at": "2021-08-03T18:00:00-06:00",
Expand Down Expand Up @@ -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
}
]
}
25 changes: 24 additions & 1 deletion public/mock-data/organization_seats_response_sample.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"total_seats": 2,
"total_seats": 3,
"seats": [
{
"created_at": "2021-08-03T18:00:00-06:00",
Expand Down Expand Up @@ -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
}
}
]
}
124 changes: 124 additions & 0 deletions tests/Seat.nuxt.spec.ts
Original file line number Diff line number Diff line change
@@ -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')
})
})
Loading