Skip to content

Commit 1b8b42f

Browse files
committed
Fix: unit tests, and few things in the core code
1 parent 706933a commit 1b8b42f

File tree

8 files changed

+280
-54
lines changed

8 files changed

+280
-54
lines changed

__tests__/__snapshots__/index.js.snap

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Library interface test 1`] = `
4+
Object {
5+
"actions": Object {
6+
"auth": Object {
7+
"loadProfile": [Function],
8+
"setTcTokenV2": [Function],
9+
"setTcTokenV3": [Function],
10+
},
11+
"challenge": Object {
12+
"dropCheckpoints": [Function],
13+
"dropResults": [Function],
14+
"fetchCheckpointsDone": [Function],
15+
"fetchCheckpointsInit": [Function],
16+
"getDetailsDone": [Function],
17+
"getDetailsInit": [Function],
18+
"getSubmissionsDone": [Function],
19+
"getSubmissionsInit": [Function],
20+
"loadResultsDone": [Function],
21+
"loadResultsInit": [Function],
22+
"registerDone": [Function],
23+
"registerInit": [Function],
24+
"toggleCheckpointFeedback": [Function],
25+
"unregisterDone": [Function],
26+
"unregisterInit": [Function],
27+
"updateChallengeDone": [Function],
28+
"updateChallengeInit": [Function],
29+
},
30+
"direct": Object {
31+
"dropAll": [Function],
32+
"getProjectDetailsDone": [Function],
33+
"getProjectDetailsInit": [Function],
34+
"getProjectPermissionsDone": [Function],
35+
"getProjectPermissionsInit": [Function],
36+
"getUserProjectsDone": [Function],
37+
"getUserProjectsInit": [Function],
38+
},
39+
"errors": Object {
40+
"clearAllErrorIcons": [Function],
41+
"clearError": [Function],
42+
"clearErrorIcon": [Function],
43+
"newError": [Function],
44+
"setErrorIcon": [Function],
45+
},
46+
"groups": Object {
47+
"dropGroups": [Function],
48+
"getGroupsDone": [Function],
49+
"getGroupsInit": [Function],
50+
},
51+
"memberTasks": Object {
52+
"dropAll": [Function],
53+
"getDone": [Function],
54+
"getInit": [Function],
55+
},
56+
"members": Object {
57+
"drop": [Function],
58+
"dropAll": [Function],
59+
"getAchievementsDone": [Function],
60+
"getAchievementsInit": [Function],
61+
"getFinancesDone": [Function],
62+
"getFinancesInit": [Function],
63+
"getStatsDone": [Function],
64+
"getStatsInit": [Function],
65+
},
66+
"profile": Object {
67+
"getAchievementsDone": [Function],
68+
"getAchievementsInit": [Function],
69+
"getExternalAccountsDone": [Function],
70+
"getExternalAccountsInit": [Function],
71+
"getExternalLinksDone": [Function],
72+
"getExternalLinksInit": [Function],
73+
"getInfoDone": [Function],
74+
"getInfoInit": [Function],
75+
"getSkillsDone": [Function],
76+
"getSkillsInit": [Function],
77+
"getStatsDone": [Function],
78+
"getStatsInit": [Function],
79+
"loadProfile": [Function],
80+
},
81+
"reviewOpportunity": Object {
82+
"cancelApplicationsDone": [Function],
83+
"cancelApplicationsInit": [Function],
84+
"getDetailsDone": [Function],
85+
"getDetailsInit": [Function],
86+
"submitApplicationsDone": [Function],
87+
"submitApplicationsInit": [Function],
88+
},
89+
"smp": Object {
90+
"deleteSubmissionDone": [Function],
91+
"deleteSubmissionInit": [Function],
92+
"downloadSubmission": [Function],
93+
},
94+
"stats": Object {
95+
"getCommunityStatsDone": [Function],
96+
"getCommunityStatsInit": [Function],
97+
},
98+
"terms": Object {
99+
"agreeTermDone": [Function],
100+
"agreeTermInit": [Function],
101+
"checkStatusDone": [Function],
102+
"checkStatusInit": [Function],
103+
"getDocuSignUrlDone": [Function],
104+
"getDocuSignUrlInit": [Function],
105+
"getTermDetailsDone": [Function],
106+
"getTermDetailsInit": [Function],
107+
"getTermsDone": [Function],
108+
"getTermsInit": [Function],
109+
},
110+
},
111+
"challenges": Object {
112+
"filter": Object {
113+
"addTrack": [Function],
114+
"combine": [Function],
115+
"default": undefined,
116+
"getFilterFunction": [Function],
117+
"getReviewOpportunitiesFilterFunction": [Function],
118+
"mapToBackend": [Function],
119+
"removeTrack": [Function],
120+
"setEndDate": [Function],
121+
"setReviewOpportunityType": [Function],
122+
"setStartDate": [Function],
123+
"setSubtracks": [Function],
124+
"setTags": [Function],
125+
"setText": [Function],
126+
},
127+
},
128+
"errors": Object {
129+
"ERROR_ICON_TYPES": Object {
130+
"API": "api",
131+
"NETWORK": "network",
132+
},
133+
"clearAllErrorIcons": [Function],
134+
"clearErrorIcon": [Function],
135+
"fireErrorMessage": [Function],
136+
"setErrorIcon": [Function],
137+
"setErrorsStore": [Function],
138+
},
139+
"logger": Object {
140+
"_getSourceMaps": [Function],
141+
"assert": [Function],
142+
"clear": [Function],
143+
"count": [Function],
144+
"countReset": [Function],
145+
"debug": [Function],
146+
"dir": [Function],
147+
"error": [Function],
148+
"group": [Function],
149+
"groupCollapsed": [Function],
150+
"groupEnd": [Function],
151+
"info": [Function],
152+
"log": [Function],
153+
"time": [Function],
154+
"timeEnd": [Function],
155+
"trace": [Function],
156+
"warn": [Function],
157+
},
158+
"mock": Object {
159+
"default": undefined,
160+
"mockAction": [Function],
161+
},
162+
"reducerFactory": [Function],
163+
"reducers": Object {
164+
"auth": [Function],
165+
"challenge": [Function],
166+
"direct": [Function],
167+
"errors": [Function],
168+
"groups": [Function],
169+
"memberTasks": [Function],
170+
"members": [Function],
171+
"mySubmissionsManagement": [Function],
172+
"profile": [Function],
173+
"reviewOpportunity": [Function],
174+
"stats": [Function],
175+
"terms": [Function],
176+
},
177+
"services": Object {
178+
"api": Object {
179+
"default": [Function],
180+
"getApiV2": [Function],
181+
"getApiV3": [Function],
182+
},
183+
"billing": Object {
184+
"default": [Function],
185+
"getService": [Function],
186+
},
187+
"challenge": Object {
188+
"ORDER_BY": Object {
189+
"SUBMISSION_END_DATE": "submissionEndDate",
190+
},
191+
"default": undefined,
192+
"getService": [Function],
193+
"normalizeChallenge": [Function],
194+
"normalizeChallengeDetails": [Function],
195+
},
196+
"communities": Object {
197+
"default": undefined,
198+
"getService": [Function],
199+
},
200+
"direct": Object {
201+
"default": undefined,
202+
"getService": [Function],
203+
},
204+
"groups": Object {
205+
"addDescendantGroups": [Function],
206+
"checkGroupsStatus": [Function],
207+
"checkUserGroups": [Function],
208+
"default": undefined,
209+
"getService": [Function],
210+
},
211+
"members": Object {
212+
"default": undefined,
213+
"getService": [Function],
214+
},
215+
"reviewOpportunities": Object {
216+
"default": undefined,
217+
"getReviewOpportunitiesService": [Function],
218+
},
219+
"terms": Object {
220+
"default": undefined,
221+
"getService": [Function],
222+
},
223+
"user": Object {
224+
"default": [Function],
225+
"getService": [Function],
226+
},
227+
"userSetting": Object {
228+
"default": [Function],
229+
"getUserSettingsService": [Function],
230+
},
231+
},
232+
"tc": Object {
233+
"COMPETITION_TRACKS": Object {
234+
"DATA_SCIENCE": "data_science",
235+
"DESIGN": "design",
236+
"DEVELOP": "develop",
237+
},
238+
"REVIEW_OPPORTUNITY_TYPES": Object {
239+
"Contest Review": "Review",
240+
"Iterative Review": "Iterative Review",
241+
"Spec Review": "Specification Review",
242+
},
243+
"getApiResponsePayloadV3": [Function],
244+
},
245+
"time": Object {
246+
"default": undefined,
247+
"delay": [Function],
248+
"formatDuration": [Function],
249+
},
250+
}
251+
`;

__tests__/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test('Library interface test', () => {
2+
expect(require('../src')).toMatchSnapshot();
3+
});

__tests__/reducers/auth.js

Lines changed: 21 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { mockAction } from 'utils/mock';
12
import { redux } from 'topcoder-react-utils';
2-
import { mockAction } from '../../src/utils/mock';
33

44
const dummy = 'DUMMY';
55

@@ -10,13 +10,16 @@ const mockActions = {
1010
setTcTokenV3: mockAction('SET_TC_TOKEN_V3', 'Token V3'),
1111
},
1212
};
13-
jest.setMock(require.resolve('../../src/actions/auth'), mockActions);
13+
jest.setMock(require.resolve('actions/auth'), mockActions);
1414

15-
const { reducers } = require('../../src');
15+
jest.setMock('tc-accounts', {
16+
decodeToken: () => 'User object',
17+
isTokenExpired: () => false,
18+
});
1619

17-
let reducer;
20+
const reducers = require('reducers/auth');
1821

19-
function testReducer(istate) {
22+
function testReducer(reducer, istate) {
2023
test('Initial state', () => {
2124
const state = reducer(undefined, {});
2225
expect(state).toEqual(istate);
@@ -45,10 +48,7 @@ function testReducer(istate) {
4548
expect(state).toEqual({
4649
dummy,
4750
tokenV3: 'Token V3',
48-
user: {
49-
handle: 'username12345',
50-
userId: '12345',
51-
},
51+
user: 'User object',
5252
});
5353
});
5454

@@ -65,52 +65,24 @@ function testReducer(istate) {
6565
}
6666

6767
describe('Default reducer', () => {
68-
beforeAll(() => {
69-
reducer = reducers.auth.default;
70-
});
71-
72-
testReducer({
73-
authenticating: true,
74-
});
75-
});
76-
77-
describe('Factory without server side rendering', () => {
78-
beforeAll((done) => {
79-
reducers.auth.factory().then((res) => {
80-
reducer = res;
81-
done();
82-
});
83-
});
84-
85-
testReducer({
68+
testReducer(reducers.default, {
8669
authenticating: true,
70+
profile: null,
8771
tokenV2: '',
8872
tokenV3: '',
8973
user: null,
9074
});
9175
});
9276

93-
describe('Factory with server side rendering', () => {
94-
beforeAll((done) => {
95-
reducers.auth.factory({
96-
auth: {
97-
tokenV2: 'Token V2',
98-
tokenV3: 'Token V3',
99-
},
100-
}).then((res) => {
101-
reducer = res;
102-
done();
103-
});
104-
});
77+
describe('Factory without server side rendering', () =>
78+
reducers.factory().then(res =>
79+
testReducer(res, {})));
10580

106-
testReducer({
107-
authenticating: false,
108-
profile: 'Profile',
109-
tokenV2: 'Token V2',
110-
tokenV3: 'Token V3',
111-
user: {
112-
handle: 'username12345',
113-
userId: '12345',
81+
describe('Factory with server side rendering', () =>
82+
reducers.factory({
83+
cookies: {
84+
tcjwt: 'Token V2',
85+
v3jwt: 'Token V3',
11486
},
115-
});
116-
});
87+
}).then(res =>
88+
testReducer(res, {})));

__tests__/utils/filter.js renamed to __tests__/utils/challenges/filter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setText, setTags, setSubtracks, setStartDate } from '../../src/utils/filter';
1+
import { setText, setTags, setSubtracks, setStartDate } from '../../../src/utils/challenges/filter';
22

33
describe('challenge filter', () => {
44
let res;

src/actions/profile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export default createActions({
135135
GET_EXTERNAL_ACCOUNTS_INIT: getExternalAccountsInit,
136136
GET_EXTERNAL_ACCOUNTS_DONE: getExternalAccountsDone,
137137
GET_EXTERNAL_LINKS_INIT: getExternalLinksInit,
138-
GET_EXTERNAL_LINKS_DONE: getExternalLinksDone,
138+
GET_EXTERNAL_LINKS_DONE: getExternalLinksDone,
139139
GET_INFO_INIT: getInfoInit,
140140
GET_INFO_DONE: getInfoDone,
141141
GET_SKILLS_INIT: getSkillsInit,

src/actions/stats.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import _ from 'lodash';
88

99
import { createActions } from 'redux-actions';
10-
import * as Filter from '../utils/filter';
10+
import * as Filter from '../utils/challenges/filter';
1111
import { getService as getGroupService } from '../services/groups';
1212

1313
/**

src/actions/terms.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function getTermsInit(arg) {
2626
* @param {String} [entity.type] entity type: `challenge` or `community`
2727
* @param {String} [entity.id] entity id
2828
* @param {Object} tokens object with tokenV2 and tokenV3 properties
29-
* @param {Boolean} mockAgreed if true, then all terms will be mocked as
29+
* @param {Boolean} mockAgreed if true, then all terms will be mocked as
3030
* agreed this only makes effect if MOCK_TERMS_SERVICE is `true` and the only
3131
* purpose of this param is testing terms
3232
* @return {Action}

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ export { actions } from './actions';
1111

1212
export { services } from './services';
1313

14-
export { logger, errors, tc, time, mock, filter } from './utils';
14+
export { challenges, logger, errors, tc, time, mock } from './utils';

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy