@@ -85,6 +85,20 @@ function makeLabels(overrides: { currentIssueLabels?: string[] } = {}): Labels {
8585 return labels ;
8686}
8787
88+ function makeIssueTypes ( ) : IssueTypes {
89+ return new IssueTypes (
90+ 'Task' , 'Task desc' , 'BLUE' ,
91+ 'Bug' , 'Bug desc' , 'RED' ,
92+ 'Feature' , 'Feature desc' , 'GREEN' ,
93+ 'Docs' , 'Docs desc' , 'GREY' ,
94+ 'Maintenance' , 'Maint desc' , 'GREY' ,
95+ 'Hotfix' , 'Hotfix desc' , 'RED' ,
96+ 'Release' , 'Release desc' , 'BLUE' ,
97+ 'Question' , 'Q desc' , 'PURPLE' ,
98+ 'Help' , 'Help desc' , 'PURPLE'
99+ ) ;
100+ }
101+
88102describe ( 'IssueRepository' , ( ) => {
89103 const repo = new IssueRepository ( ) ;
90104
@@ -470,6 +484,12 @@ describe('IssueRepository', () => {
470484 expect ( result ) . toEqual ( [ ] ) ;
471485 expect ( mockRest . issues . listLabelsOnIssue ) . toHaveBeenCalled ( ) ;
472486 } ) ;
487+
488+ it ( 'returns empty array when listLabelsOnIssue returns non-404 error' , async ( ) => {
489+ mockRest . issues . listLabelsOnIssue . mockRejectedValue ( new Error ( 'Some other error' ) ) ;
490+ const result = await repo . getLabels ( 'owner' , 'repo' , 1 , 'token' ) ;
491+ expect ( result ) . toEqual ( [ ] ) ;
492+ } ) ;
473493 } ) ;
474494
475495 describe ( 'setLabels' , ( ) => {
@@ -1147,6 +1167,41 @@ describe('IssueRepository', () => {
11471167 expect ( result . errors . length ) . toBeGreaterThan ( 0 ) ;
11481168 expect ( result . errors . some ( ( e ) => e . includes ( 'Create failed' ) ) ) . toBe ( true ) ;
11491169 } ) ;
1170+
1171+ it ( 'setIssueType catches error and continues (re-throws in IssueRepository)' , async ( ) => {
1172+ const labels = makeLabels ( { currentIssueLabels : [ 'bug' ] } ) ;
1173+ const issueTypes = makeIssueTypes ( ) ;
1174+ mockGraphql . mockRejectedValue ( new Error ( 'Global error' ) ) ;
1175+ await expect ( repo . setIssueType ( 'o' , 'r' , 1 , labels , issueTypes , 't' ) ) . rejects . toThrow ( 'Global error' ) ;
1176+ } ) ;
1177+
1178+ it ( 'createIssueType throws when organization is null' , async ( ) => {
1179+ mockGraphql . mockResolvedValueOnce ( { organization : null } ) ;
1180+ await expect ( repo . createIssueType ( 'o' , 'n' , 'd' , 'c' , 't' ) ) . rejects . toThrow ( 'No se pudo obtener la organización o' ) ;
1181+ } ) ;
1182+
1183+ it ( 'listIssueTypes throws when organization is null' , async ( ) => {
1184+ mockGraphql . mockResolvedValueOnce ( { organization : null } ) ;
1185+ await expect ( repo . listIssueTypes ( 'o' , 't' ) ) . rejects . toThrow ( 'No se pudo obtener la organización o' ) ;
1186+ } ) ;
1187+
1188+ it ( 'createIssueType throws when organization is missing (GraphQL error scenario)' , async ( ) => {
1189+ mockGraphql . mockResolvedValueOnce ( { organization : null } ) ;
1190+ await expect ( repo . createIssueType ( 'o' , 'n' , 'd' , 'c' , 't' ) ) . rejects . toThrow ( 'No se pudo obtener la organización o' ) ;
1191+ } ) ;
1192+
1193+ it ( 'ensureLabel handles 422 error "already exists"' , async ( ) => {
1194+ mockRest . issues . listLabelsForRepo . mockResolvedValue ( { data : [ ] } ) ;
1195+ mockRest . issues . createLabel . mockRejectedValue ( { status : 422 , message : 'already exists' } ) ;
1196+ const result = await repo . ensureLabel ( 'o' , 'r' , 'new' , 'c' , 'd' , 't' ) ;
1197+ expect ( result ) . toEqual ( { created : false , existed : true } ) ;
1198+ } ) ;
1199+
1200+ it ( 'ensureLabel re-throws other errors' , async ( ) => {
1201+ mockRest . issues . listLabelsForRepo . mockResolvedValue ( { data : [ ] } ) ;
1202+ mockRest . issues . createLabel . mockRejectedValue ( new Error ( 'Fatal' ) ) ;
1203+ await expect ( repo . ensureLabel ( 'o' , 'r' , 'new' , 'c' , 'd' , 't' ) ) . rejects . toThrow ( 'Fatal' ) ;
1204+ } ) ;
11501205 } ) ;
11511206} ) ;
11521207
0 commit comments