2022-01-26 12:08:38 +05:30
import axios from 'axios' ;
import MockAdapter from 'axios-mock-adapter' ;
2020-10-24 23:57:45 +05:30
import testAction from 'helpers/vuex_action_helper' ;
2022-01-26 12:08:38 +05:30
import { I18N _FETCH _TEST _SETTINGS _DEFAULT _ERROR _MESSAGE } from '~/integrations/constants' ;
2021-01-29 00:20:46 +05:30
import {
setOverride ,
2021-03-11 19:13:27 +05:30
requestJiraIssueTypes ,
receiveJiraIssueTypesSuccess ,
receiveJiraIssueTypesError ,
2021-01-29 00:20:46 +05:30
} from '~/integrations/edit/store/actions' ;
2020-07-28 23:09:34 +05:30
import * as types from '~/integrations/edit/store/mutation_types' ;
2021-03-11 19:13:27 +05:30
import createState from '~/integrations/edit/store/state' ;
2022-01-26 12:08:38 +05:30
import { mockJiraIssueTypes } from '../mock_data' ;
2020-07-28 23:09:34 +05:30
2021-02-22 17:27:13 +05:30
jest . mock ( '~/lib/utils/url_utility' ) ;
2020-07-28 23:09:34 +05:30
describe ( 'Integration form store actions' , ( ) => {
let state ;
2022-01-26 12:08:38 +05:30
let mockAxios ;
2020-07-28 23:09:34 +05:30
beforeEach ( ( ) => {
state = createState ( ) ;
2022-01-26 12:08:38 +05:30
mockAxios = new MockAdapter ( axios ) ;
} ) ;
afterEach ( ( ) => {
mockAxios . restore ( ) ;
2020-07-28 23:09:34 +05:30
} ) ;
describe ( 'setOverride' , ( ) => {
it ( 'should commit override mutation' , ( ) => {
return testAction ( setOverride , true , state , [ { type : types . SET _OVERRIDE , payload : true } ] ) ;
} ) ;
} ) ;
2021-01-29 00:20:46 +05:30
2021-03-11 19:13:27 +05:30
describe ( 'requestJiraIssueTypes' , ( ) => {
2022-01-26 12:08:38 +05:30
describe . each `
scenario | responseCode | response | action
$ { 'when successful' } | $ { 200 } | $ { { issuetypes : mockJiraIssueTypes } } | $ { { type : 'receiveJiraIssueTypesSuccess' , payload : mockJiraIssueTypes } }
$ { 'when response has no issue types' } | $ { 200 } | $ { { issuetypes : [ ] } } | $ { { type : 'receiveJiraIssueTypesError' , payload : I18N _FETCH _TEST _SETTINGS _DEFAULT _ERROR _MESSAGE } }
$ { 'when response includes error' } | $ { 200 } | $ { { error : new Error ( ) } } | $ { { type : 'receiveJiraIssueTypesError' , payload : I18N _FETCH _TEST _SETTINGS _DEFAULT _ERROR _MESSAGE } }
$ { 'when error occurs' } | $ { 500 } | $ { { } } | $ { { type : 'receiveJiraIssueTypesError' , payload : expect . any ( String ) } }
` (' $ scenario', ({ responseCode, response, action }) => {
it ( ` should commit SET_JIRA_ISSUE_TYPES_ERROR_MESSAGE and SET_IS_LOADING_JIRA_ISSUE_TYPES mutations, and dispatch ${ action . type } ` , ( ) => {
mockAxios . onPut ( '/test' ) . replyOnce ( responseCode , response ) ;
return testAction (
requestJiraIssueTypes ,
new FormData ( ) ,
{ propsSource : { testPath : '/test' } } ,
[
// should clear the error messages and set the loading state
{ type : types . SET _JIRA _ISSUE _TYPES _ERROR _MESSAGE , payload : '' } ,
{ type : types . SET _IS _LOADING _JIRA _ISSUE _TYPES , payload : true } ,
] ,
[ action ] ,
) ;
} ) ;
2021-03-11 19:13:27 +05:30
} ) ;
} ) ;
describe ( 'receiveJiraIssueTypesSuccess' , ( ) => {
it ( 'should commit SET_IS_LOADING_JIRA_ISSUE_TYPES and SET_JIRA_ISSUE_TYPES mutations' , ( ) => {
const issueTypes = [ 'issue' , 'epic' ] ;
return testAction ( receiveJiraIssueTypesSuccess , issueTypes , state , [
{ type : types . SET _IS _LOADING _JIRA _ISSUE _TYPES , payload : false } ,
{ type : types . SET _JIRA _ISSUE _TYPES , payload : issueTypes } ,
] ) ;
} ) ;
} ) ;
describe ( 'receiveJiraIssueTypesError' , ( ) => {
it ( 'should commit SET_IS_LOADING_JIRA_ISSUE_TYPES, SET_JIRA_ISSUE_TYPES and SET_JIRA_ISSUE_TYPES_ERROR_MESSAGE mutations' , ( ) => {
const errorMessage = 'something went wrong' ;
return testAction ( receiveJiraIssueTypesError , errorMessage , state , [
{ type : types . SET _IS _LOADING _JIRA _ISSUE _TYPES , payload : false } ,
{ type : types . SET _JIRA _ISSUE _TYPES , payload : [ ] } ,
{ type : types . SET _JIRA _ISSUE _TYPES _ERROR _MESSAGE , payload : errorMessage } ,
] ) ;
} ) ;
} ) ;
2020-07-28 23:09:34 +05:30
} ) ;