Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add repository and organization actions tests
- Loading branch information
Showing
4 changed files
with
485 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import configureStore from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
import { | ||
GET_ORG_REPOS_LOADING, | ||
GET_ORG_REPOS_ERROR, | ||
GET_ORG_REPOS, | ||
} from '../../../src/organization/organization.constants'; | ||
import { fetchOrganizationRepos } from '../../../src/organization/organization.action'; | ||
import { v3 } from '../../../src/api'; | ||
|
||
const store = configureStore([thunk])({ auth: { accessToken: 'ABCXYZ' } }); | ||
|
||
jest.mock('../../../src/api', () => ({ | ||
v3: { | ||
getJson: jest.fn(), | ||
}, | ||
})); | ||
|
||
describe('fetchOrganizationRepos()', () => { | ||
afterEach(() => { | ||
store.clearActions(); | ||
}); | ||
|
||
it('should return a success response', async () => { | ||
const expectedData = { name: 'organization' }; | ||
|
||
v3.getJson.mockResolvedValueOnce(expectedData); | ||
await store.dispatch(fetchOrganizationRepos('')); | ||
|
||
expect(store.getActions()).toEqual( | ||
expect.arrayContaining([ | ||
{ | ||
type: GET_ORG_REPOS_LOADING, | ||
payload: true, | ||
}, | ||
{ | ||
type: GET_ORG_REPOS_ERROR, | ||
payload: '', | ||
}, | ||
{ | ||
type: GET_ORG_REPOS, | ||
payload: expectedData, | ||
}, | ||
]) | ||
); | ||
|
||
expect(store.getActions()).not.toEqual( | ||
expect.arrayContaining([ | ||
{ | ||
type: GET_ORG_REPOS_LOADING, | ||
payload: false, | ||
}, | ||
{ | ||
type: GET_ORG_REPOS_ERROR, | ||
payload: expectedData, | ||
}, | ||
]) | ||
); | ||
}); | ||
|
||
it('should return an error response', async () => { | ||
const expectedData = { error: 'no organization' }; | ||
|
||
v3.getJson.mockRejectedValueOnce(expectedData); | ||
await store.dispatch(fetchOrganizationRepos('')); | ||
|
||
expect(store.getActions()).toEqual( | ||
expect.arrayContaining([ | ||
{ | ||
type: GET_ORG_REPOS_LOADING, | ||
payload: true, | ||
}, | ||
{ | ||
type: GET_ORG_REPOS_LOADING, | ||
payload: false, | ||
}, | ||
{ | ||
type: GET_ORG_REPOS_ERROR, | ||
payload: '', | ||
}, | ||
{ | ||
type: GET_ORG_REPOS_ERROR, | ||
payload: expectedData, | ||
}, | ||
]) | ||
); | ||
|
||
expect(store.getActions()).not.toEqual( | ||
expect.arrayContaining([ | ||
{ | ||
type: GET_ORG_REPOS, | ||
payload: expectedData, | ||
}, | ||
]) | ||
); | ||
}); | ||
}); |
Oops, something went wrong.