Skip to content

code 30086294 #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions __tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Object {
"getLookerDone": [Function],
},
"lookup": Object {
"getCountriesDone": [Function],
"getCountriesInit": [Function],
"getSkillTagsDone": [Function],
"getSkillTagsInit": [Function],
},
Expand Down Expand Up @@ -201,14 +203,17 @@ Object {
"countReset": [Function],
"debug": [Function],
"dir": [Function],
"dirxml": [Function],
"error": [Function],
"group": [Function],
"groupCollapsed": [Function],
"groupEnd": [Function],
"info": [Function],
"log": [Function],
"table": [Function],
"time": [Function],
"timeEnd": [Function],
"timeLog": [Function],
"trace": [Function],
"warn": [Function],
},
Expand Down
20 changes: 20 additions & 0 deletions __tests__/actions/__snapshots__/lookup.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,32 @@
exports[`Module exports 1`] = `
Object {
"lookup": Object {
"getCountriesDone": [Function],
"getCountriesInit": [Function],
"getSkillTagsDone": [Function],
"getSkillTagsInit": [Function],
},
}
`;

exports[`lookup.getCountriesDone 1`] = `
Object {
"payload": Array [
Object {
"country": "Afghanistan",
"countryCode": "AFG",
},
],
"type": "LOOKUP/GET_COUNTRIES_DONE",
}
`;

exports[`lookup.getCountriesInit 1`] = `
Object {
"type": "LOOKUP/GET_COUNTRIES_INIT",
}
`;

exports[`lookup.getSkillTagsDone 1`] = `
Object {
"payload": Array [
Expand Down
17 changes: 17 additions & 0 deletions __tests__/actions/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ const tag = {
status: 'APPROVED',
};

const country = {
country: 'Afghanistan',
countryCode: 'AFG',
};

// Mock services
const mockLookupService = {
getTags: jest.fn().mockReturnValue(Promise.resolve([tag])),
getCountries: jest.fn().mockReturnValue(Promise.resolve([country])),
};
LookupService.getService = jest.fn().mockReturnValue(mockLookupService);

Expand All @@ -28,3 +34,14 @@ test('lookup.getSkillTagsDone', async () => {
expect(actionResult).toMatchSnapshot();
expect(mockLookupService.getTags).toBeCalled();
});

test('lookup.getCountriesInit', async () => {
const actionResult = actions.lookup.getCountriesInit();
expect(actionResult).toMatchSnapshot();
});

test('lookup.getCountriesDone', async () => {
const actionResult = await redux.resolveAction(actions.lookup.getCountriesDone());
expect(actionResult).toMatchSnapshot();
expect(mockLookupService.getCountries).toBeCalled();
});
90 changes: 90 additions & 0 deletions __tests__/reducers/__snapshots__/lookup.js.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,50 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Default reducer Get countries 1`] = `
Object {
"countries": Array [
Object {
"country": "Afghanistan",
"countryCode": "AFG",
},
],
"loadingCountriesError": false,
"loadingSkillTagsError": true,
"skillTags": Array [
Object {
"domain": "SKILLS",
"id": 251,
"name": "Jekyll",
"status": "APPROVED",
},
],
}
`;

exports[`Default reducer Get countries error 1`] = `
Object {
"countries": Array [
Object {
"country": "Afghanistan",
"countryCode": "AFG",
},
],
"loadingCountriesError": true,
"loadingSkillTagsError": true,
"skillTags": Array [
Object {
"domain": "SKILLS",
"id": 251,
"name": "Jekyll",
"status": "APPROVED",
},
],
}
`;

exports[`Default reducer Get skill tags 1`] = `
Object {
"countries": Array [],
"loadingSkillTagsError": false,
"skillTags": Array [
Object {
Expand All @@ -16,6 +59,7 @@ Object {

exports[`Default reducer Get skill tags error 1`] = `
Object {
"countries": Array [],
"loadingSkillTagsError": true,
"skillTags": Array [
Object {
Expand All @@ -30,12 +74,56 @@ Object {

exports[`Default reducer Initial state 1`] = `
Object {
"countries": Array [],
"skillTags": Array [],
}
`;

exports[`Factory without server side rendering Get countries 1`] = `
Object {
"countries": Array [
Object {
"country": "Afghanistan",
"countryCode": "AFG",
},
],
"loadingCountriesError": false,
"loadingSkillTagsError": true,
"skillTags": Array [
Object {
"domain": "SKILLS",
"id": 251,
"name": "Jekyll",
"status": "APPROVED",
},
],
}
`;

exports[`Factory without server side rendering Get countries error 1`] = `
Object {
"countries": Array [
Object {
"country": "Afghanistan",
"countryCode": "AFG",
},
],
"loadingCountriesError": true,
"loadingSkillTagsError": true,
"skillTags": Array [
Object {
"domain": "SKILLS",
"id": 251,
"name": "Jekyll",
"status": "APPROVED",
},
],
}
`;

exports[`Factory without server side rendering Get skill tags 1`] = `
Object {
"countries": Array [],
"loadingSkillTagsError": false,
"skillTags": Array [
Object {
Expand All @@ -50,6 +138,7 @@ Object {

exports[`Factory without server side rendering Get skill tags error 1`] = `
Object {
"countries": Array [],
"loadingSkillTagsError": true,
"skillTags": Array [
Object {
Expand All @@ -64,6 +153,7 @@ Object {

exports[`Factory without server side rendering Initial state 1`] = `
Object {
"countries": Array [],
"skillTags": Array [],
}
`;
19 changes: 19 additions & 0 deletions __tests__/reducers/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ const tag = {
status: 'APPROVED',
};

const country = {
country: 'Afghanistan',
countryCode: 'AFG',
};

const mockActions = {
lookup: {
getSkillTagsInit: mockAction('LOOKUP/GET_SKILL_TAGS_INIT'),
getSkillTagsDone: mockAction('LOOKUP/GET_SKILL_TAGS_DONE', [tag]),
getSkillTagsDoneError: mockAction('LOOKUP/GET_SKILL_TAGS_DONE', null, 'Unknown error'),
getCountriesInit: mockAction('LOOKUP/GET_COUNTRIES_INIT'),
getCountriesDone: mockAction('LOOKUP/GET_COUNTRIES_DONE', [country]),
getCountriesDoneError: mockAction('LOOKUP/GET_COUNTRIES_DONE', null, 'Unknown error'),
},
};
jest.setMock(require.resolve('actions/lookup'), mockActions);
Expand All @@ -38,6 +46,17 @@ function testReducer() {
state = reducer(state, mockActions.lookup.getSkillTagsDoneError());
expect(state).toMatchSnapshot();
});

test('Get countries', () => {
state = reducer(state, mockActions.lookup.getCountriesInit());
state = reducer(state, mockActions.lookup.getCountriesDone());
expect(state).toMatchSnapshot();
});

test('Get countries error', () => {
state = reducer(state, mockActions.lookup.getCountriesDoneError());
expect(state).toMatchSnapshot();
});
}

describe('Default reducer', () => {
Expand Down
8 changes: 8 additions & 0 deletions docs/actions.lookup.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Actions related to lookup data.
* [actions.lookup](#module_actions.lookup)
* [.getSkillTagsInit()](#module_actions.lookup.getSkillTagsInit) ⇒ <code>Action</code>
* [.getSkillTagsDone()](#module_actions.lookup.getSkillTagsDone) ⇒ <code>Action</code>
* [.getCountriesInit()](#module_actions.lookup.getCountriesInit) ⇒ <code>Action</code>
* [.getCountriesDone()](#module_actions.lookup.getCountriesDone) ⇒ <code>Action</code>

<a name="module_actions.lookup.getSkillTagsInit"></a>

Expand All @@ -20,3 +22,9 @@ Creates an action that signals beginning of getting all skill tags.
Creates an action that gets all skill tags.

**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)
<a name="module_actions.lookup.getCountriesDone"></a>

### actions.lookup.getCountriesDone() ⇒ <code>Action</code>
Creates an action that gets all countries.

**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)
8 changes: 8 additions & 0 deletions docs/reducers.lookup.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ State segment managed by this reducer has the following structure:
* [.factory()](#module_reducers.lookup.factory) ⇒ <code>Promise</code>
* _inner_
* [~onGetSkillTagsDone(state, action)](#module_reducers.lookup..onGetSkillTagsDone) ⇒ <code>Object</code>
* [~onGetCountriesDone(state, action)](#module_reducers.lookup..onGetCountriesDone) ⇒ <code>Object</code>
* [~create(initialState)](#module_reducers.lookup..create) ⇒ <code>function</code>

<a name="module_reducers.lookup.default"></a>
Expand All @@ -37,6 +38,13 @@ Factory which creates a new reducer.
### reducers.lookup~onGetSkillTagsDone(state, action) ⇒ <code>Object</code>
Handles LOOKUP/GET_SKILL_TAGS_DONE action.

**Kind**: static method of [<code>reducers.lookup</code>](#module_reducers.lookup)
**Resolves**: <code>Function(state, action): state</code> New reducer.
<a name="module_reducers.lookup..onGetCountriesDone"></a>

### reducers.lookup~onGetCountriesDone(state, action) ⇒ <code>Object</code>
Handles LOOKUP/GET_COUNTRIES_DONE action.

**Kind**: inner method of [<code>reducers.lookup</code>](#module_reducers.lookup)
**Returns**: <code>Object</code> - New state

Expand Down
18 changes: 18 additions & 0 deletions src/actions/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,27 @@ function getSkillTagsDone() {
return getService().getTags(params);
}

/**
* @static
* @desc Creates an action that signals beginning of getting all countries.
* @return {Action}
*/
function getCountriesInit() {}

/**
* @static
* @desc Creates an action that gets all countries.
* @return {Action}
*/
function getCountriesDone() {
return getService().getCountries();
}

export default createActions({
LOOKUP: {
GET_SKILL_TAGS_INIT: getSkillTagsInit,
GET_SKILL_TAGS_DONE: getSkillTagsDone,
GET_COUNTRIES_INIT: getCountriesInit,
GET_COUNTRIES_DONE: getCountriesDone,
},
});
22 changes: 22 additions & 0 deletions src/reducers/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ function onGetSkillTagsDone(state, { payload, error }) {
});
}

/**
* Handles LOOKUP/GET_COUNTRIES_DONE action.
* @param {Object} state
* @param {Object} action Payload will be JSON from api call
* @return {Object} New state
*/
function onGetCountriesDone(state, { payload, error }) {
if (error) {
logger.error('Failed to get countries', payload);
return { ...state, loadingCountriesError: true };
}

return ({
...state,
loadingCountriesError: false,
countries: payload,
});
}

/**
* Creates a new Lookup reducer with the specified initial state.
* @param {Object} initialState Optional. Initial state.
Expand All @@ -39,8 +58,11 @@ function create(initialState = {}) {
return handleActions({
[a.getSkillTagsInit]: state => state,
[a.getSkillTagsDone]: onGetSkillTagsDone,
[a.getCountriesInit]: state => state,
[a.getCountriesDone]: onGetCountriesDone,
}, _.defaults(initialState, {
skillTags: [],
countries: [],
}));
}

Expand Down
10 changes: 10 additions & 0 deletions src/services/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ class LookupService {
const res = await this.private.api.get(`/tags/?${qs.stringify(params)}`);
return getApiResponsePayload(res);
}

/**
* Gets countries.
* @param {Object} params Parameters
* @return {Promise} Resolves to the countries.
*/
async getCountries() {
const res = await this.private.api.get('/members/lookup/countries');
return getApiResponsePayload(res);
}
}

let lastInstance = null;
Expand Down