Skip to content

Commit 2b9f551

Browse files
nersohchinesedfan
authored andcommitted
test: Add repository and organization actions tests (#912)
1 parent 5061b0d commit 2b9f551

File tree

4 files changed

+486
-0
lines changed

4 files changed

+486
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import configureStore from 'redux-mock-store';
2+
import thunk from 'redux-thunk';
3+
import {
4+
GET_ORG_REPOS_LOADING,
5+
GET_ORG_REPOS_ERROR,
6+
GET_ORG_REPOS,
7+
} from 'organization/organization.constants';
8+
import { fetchOrganizationRepos } from 'organization/organization.action';
9+
import { v3 } from 'api';
10+
11+
const store = configureStore([thunk])({ auth: { accessToken: 'ABCXYZ' } });
12+
13+
jest.mock('api', () => ({
14+
v3: {
15+
getJson: jest.fn(),
16+
},
17+
}));
18+
19+
describe('fetchOrganizationRepos()', () => {
20+
afterEach(() => {
21+
store.clearActions();
22+
});
23+
24+
it('should return a success response', async () => {
25+
const expectedData = { name: 'organization' };
26+
27+
v3.getJson.mockResolvedValueOnce(expectedData);
28+
await store.dispatch(fetchOrganizationRepos(''));
29+
30+
expect(store.getActions()).toEqual(
31+
expect.arrayContaining([
32+
{
33+
type: GET_ORG_REPOS_LOADING,
34+
payload: true,
35+
},
36+
{
37+
type: GET_ORG_REPOS_ERROR,
38+
payload: '',
39+
},
40+
{
41+
type: GET_ORG_REPOS,
42+
payload: expectedData,
43+
},
44+
])
45+
);
46+
47+
expect(store.getActions()).not.toEqual(
48+
expect.arrayContaining([
49+
{
50+
type: GET_ORG_REPOS_LOADING,
51+
payload: false,
52+
},
53+
{
54+
type: GET_ORG_REPOS_ERROR,
55+
payload: expectedData,
56+
},
57+
])
58+
);
59+
});
60+
61+
it('should return an error response', async () => {
62+
const expectedData = { error: 'no organization' };
63+
64+
v3.getJson.mockRejectedValueOnce(expectedData);
65+
await store.dispatch(fetchOrganizationRepos(''));
66+
67+
expect(store.getActions()).toEqual(
68+
expect.arrayContaining([
69+
{
70+
type: GET_ORG_REPOS_LOADING,
71+
payload: true,
72+
},
73+
{
74+
type: GET_ORG_REPOS_LOADING,
75+
payload: false,
76+
},
77+
{
78+
type: GET_ORG_REPOS_ERROR,
79+
payload: '',
80+
},
81+
{
82+
type: GET_ORG_REPOS_ERROR,
83+
payload: expectedData,
84+
},
85+
])
86+
);
87+
88+
expect(store.getActions()).not.toEqual(
89+
expect.arrayContaining([
90+
{
91+
type: GET_ORG_REPOS,
92+
payload: expectedData,
93+
},
94+
])
95+
);
96+
});
97+
});

0 commit comments

Comments
 (0)