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