@@ -4,6 +4,7 @@ import { TestAccountOpen } from './testData'
44
55const kIssueKey = 'AAA-123'
66const requestUrlMock = jest . spyOn ( obsidian , 'requestUrl' )
7+ const defaultHeaders = { 'content-type' : 'application/json' }
78
89describe ( 'JiraClient' , ( ) => {
910 describe ( 'Positive tests' , ( ) => {
@@ -19,11 +20,15 @@ describe('JiraClient', () => {
1920 // })
2021
2122 test ( 'testConnection' , async ( ) => {
22- requestUrlMock . mockReturnValue ( { status : 200 } as any )
23+ requestUrlMock . mockReturnValue ( { status : 200 , headers : defaultHeaders , json : { issues : [ ] } } as any )
2324 expect ( await JiraClient . testConnection ( TestAccountOpen ) ) . toEqual ( true )
2425 expect ( requestUrlMock . mock . calls [ 0 ] [ 0 ] ) . toEqual ( {
2526 contentType : 'application/json' ,
26- headers : { } ,
27+ headers : {
28+ "Accept" : "application/json" ,
29+ "User-Agent" : "obsidian-jira-issue-plugin" ,
30+ "X-Atlassian-Token" : "no-check" ,
31+ } ,
2732 method : 'GET' ,
2833 url : 'https://test-company.atlassian.net/rest/api/latest/project' ,
2934 } )
@@ -33,14 +38,18 @@ describe('JiraClient', () => {
3338 describe ( 'Negative tests' , ( ) => {
3439 test ( 'testConnection' , async ( ) => {
3540 expect . assertions ( 2 )
36- requestUrlMock . mockReturnValue ( { status : 401 } as any )
41+ requestUrlMock . mockReturnValue ( { status : 401 , headers : defaultHeaders } as any )
3742 try {
3843 await JiraClient . testConnection ( TestAccountOpen )
3944 } catch ( e ) {
40- expect ( e ) . toEqual ( new Error ( `HTTP status 401 ` ) )
45+ expect ( e ) . toEqual ( new Error ( `Unauthorized: Please check your authentication credentials ` ) )
4146 expect ( requestUrlMock . mock . calls [ 0 ] [ 0 ] ) . toEqual ( {
4247 contentType : 'application/json' ,
43- headers : { } ,
48+ headers : {
49+ "Accept" : "application/json" ,
50+ "User-Agent" : "obsidian-jira-issue-plugin" ,
51+ "X-Atlassian-Token" : "no-check" ,
52+ } ,
4453 method : 'GET' ,
4554 url : 'https://test-company.atlassian.net/rest/api/latest/project' ,
4655 } )
0 commit comments