Skip to content

Commit

Permalink
ft(Add member): Add member to team
Browse files Browse the repository at this point in the history
- Modified invite member page
- Tested member actions
-[Finishes #161283383]
  • Loading branch information
Kevin Eze authored and Kevin Eze committed Oct 18, 2018
1 parent 53a1962 commit a0da9ac
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 23 deletions.
12 changes: 3 additions & 9 deletions client/src/redux/actions/teams/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,19 @@ export const addMember = data => async dispatch => {
try {
let request;
await api(`teams/${data.teamId}/members/${data.userId}`, 'post', { role: 'developer' });

const member = { type: 'team', name: data.teamName, invited: true };

if (data.accounts.length) {
request = data.accounts.map(async (account) => {
try {
const response = await api(`teams/${data.teamId}/accounts/${account.accountId}/members/${data.userId}`, 'post', null);
console.log(response);
console.log('response >>>>>>>>>>>>>>>>>>>>>>>>>>');
return {
type: account.type,
name: account.name,
invited: response.data.response.invitedUser.ok
};
} catch (error) {
console.log(error);
console.log('error >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
return {
type: account.type,
name: account.name,
Expand All @@ -54,16 +51,13 @@ export const addMember = data => async dispatch => {

const allResponse = await Promise.all(request);
allResponse.push(member);
console.log(allResponse);
dispatch(success(ADD_MEMBER, allResponse));
console.log('allResponse >>>>>>>>>>>>>>]]]]]]]]]]]]]]]]]]]]]]=');

console.log(allResponse);
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
successMessage('user successfully added to this team');
dispatch(isLoading(false));
} catch (error) {
dispatch(isLoading(false));
console.log('member error >>>>>>>>>>>>>>>>>>>');
console.log(error);
errorMessage(error);
}
};
58 changes: 56 additions & 2 deletions client/src/tests/__mocks__/__mockData__/memberMock.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const addMemberRequest = {
userId: 2,
teamId: 3,
teamName: 'team',
accounts: [
{
type: 'github_repo',
Expand All @@ -10,10 +11,63 @@ export const addMemberRequest = {
]
};

export const addMembeResponse = [
export const addMemberResponse =
{
type: 'github_repo',
name: 'github_repo',
invited: true
invited: true,
response: {
data: {
response: {
invitedUser: {
ok: true
}
}
}
}
};

export const response =
{
type: 'github_repo',
name: 'github_repo',
invited: true,
data: {
response: {
invitedUser: {
ok: true
}
}
}
};

export const expectedActions = [
{
name: "OLUWAFEMI",
payload: true,
type: "[auth]: check if user is logged in"
},
{
payload: true,
type: "[ui]: show preloader"
},
{
payload: [
{
invited: true,
name: "github_repo",
type: "github_repo"
},
{
invited: true,
name: "team",
type: "team"
}
],
type: "[users]: add member to a team"
},
{
payload: false,
type: "[ui]: show preloader"
}
];
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,18 @@ describe('<Test Component />', () => {
wrapper.instance().handleSubmit({ preventDefault: jest.fn() });
expect(handleSubmit).toHaveBeenCalled();
});

it('toggleSearch class methods should be called', () => {
const toggleSearch = jest.spyOn(InviteMember.prototype, 'toggleSearch');
const wrapper = shallow(<InviteMember {...props} />);
wrapper.instance().toggleSearch();
expect(toggleSearch).toHaveBeenCalled();
});

it('multiSelectOptions class methods should be called', () => {
const multiSelectOptions = jest.spyOn(InviteMember.prototype, 'multiSelectOptions');
const wrapper = shallow(<InviteMember {...props} />);
wrapper.instance().multiSelectOptions();
expect(multiSelectOptions).toHaveBeenCalled();
});
});
22 changes: 10 additions & 12 deletions client/src/tests/redux/actions/teams/member.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';

import { addMember } from '../../../../redux/actions/teams/members';
import { ADD_MEMBER } from '../../../../redux/actions/types';
import { addMemberRequest, addMemberResponse } from '../../../__mocks__/__mockData__/memberMock';

import { addMemberRequest, addMemberResponse, response, expectedActions } from '../../../__mocks__/__mockData__/memberMock';


const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
Expand All @@ -17,20 +18,17 @@ describe('Add a new user to team accounts', () => {
mock.reset();
});

it('creates a new team with valid form inputs', async () => {
const expectedActions = [{ "name": "OLUWAFEMI", "payload": true, "type": "[auth]: check if user is logged in" },
{ "payload": true, "type": "[ui]: show preloader" }, { "payload": false, "type": "[ui]: show preloader" },
{
"payload": { "github": [{ "created": true, "name": "ah-ghoulie" }], "team": [{ "created": true, "name": "ghoulie" }] },
"type": ADD_MEMBER
}];
it('Adds a user to a team accounts', async () => {
const store = mockStore({});

await mock
.onPost('teams/3/members/2', { role: 'developer' })
.reply(201);
await mock
.onPost('teams/3/accounts/4/members/2', null)
.reply(201, addMemberResponse);

await mock
.onPost('teams/3/accounts/4/members/2')
.reply(201, response);

await store.dispatch(addMember(addMemberRequest));
expect(store.getActions()).toEqual(expectedActions);
});
Expand Down

0 comments on commit a0da9ac

Please sign in to comment.