Skip to content

Settings profile #1

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ __coverage__
dist
node_modules
_auto_doc_
.vscode
54 changes: 54 additions & 0 deletions __tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ Object {
"getGroupsDone": [Function],
"getGroupsInit": [Function],
},
"lookup": Object {
"getApprovedSkills": [Function],
},
"memberTasks": Object {
"dropAll": [Function],
"getDone": [Function],
Expand All @@ -64,19 +67,49 @@ Object {
"getStatsInit": [Function],
},
"profile": Object {
"addSkillDone": [Function],
"addSkillInit": [Function],
"addWebLinkDone": [Function],
"addWebLinkInit": [Function],
"deletePhotoDone": [Function],
"deletePhotoInit": [Function],
"deleteWebLinkDone": [Function],
"deleteWebLinkInit": [Function],
"getAchievementsDone": [Function],
"getAchievementsInit": [Function],
"getActiveChallengesCountDone": [Function],
"getActiveChallengesCountInit": [Function],
"getCredentialDone": [Function],
"getCredentialInit": [Function],
"getEmailPreferencesDone": [Function],
"getEmailPreferencesInit": [Function],
"getExternalAccountsDone": [Function],
"getExternalAccountsInit": [Function],
"getExternalLinksDone": [Function],
"getExternalLinksInit": [Function],
"getInfoDone": [Function],
"getInfoInit": [Function],
"getLinkedAccountsDone": [Function],
"getLinkedAccountsInit": [Function],
"getSkillsDone": [Function],
"getSkillsInit": [Function],
"getStatsDone": [Function],
"getStatsInit": [Function],
"hideSkillDone": [Function],
"hideSkillInit": [Function],
"linkExternalAccountDone": [Function],
"linkExternalAccountInit": [Function],
"loadProfile": [Function],
"saveEmailPreferencesDone": [Function],
"saveEmailPreferencesInit": [Function],
"unlinkExternalAccountDone": [Function],
"unlinkExternalAccountInit": [Function],
"updatePasswordDone": [Function],
"updatePasswordInit": [Function],
"updateProfileDone": [Function],
"updateProfileInit": [Function],
"uploadPhotoDone": [Function],
"uploadPhotoInit": [Function],
},
"reviewOpportunity": Object {
"cancelApplicationsDone": [Function],
Expand Down Expand Up @@ -159,13 +192,29 @@ Object {
"default": undefined,
"mockAction": [Function],
},
"reducerFactories": Object {
"authFactory": [Function],
"challengeFactory": [Function],
"directFactory": [Function],
"errorsFactory": [Function],
"groupsFactory": [Function],
"lookupFactory": [Function],
"memberTasksFactory": [Function],
"membersFactory": [Function],
"mySubmissionsManagementFactory": [Function],
"profileFactory": [Function],
"reviewOpportunityFactory": [Function],
"statsFactory": [Function],
"termsFactory": [Function],
},
"reducerFactory": [Function],
"reducers": Object {
"auth": [Function],
"challenge": [Function],
"direct": [Function],
"errors": [Function],
"groups": [Function],
"lookup": [Function],
"memberTasks": [Function],
"members": [Function],
"mySubmissionsManagement": [Function],
Expand Down Expand Up @@ -209,6 +258,10 @@ Object {
"default": undefined,
"getService": [Function],
},
"lookup": Object {
"default": undefined,
"getService": [Function],
},
"members": Object {
"default": undefined,
"getService": [Function],
Expand Down Expand Up @@ -242,6 +295,7 @@ Object {
"Spec Review": "Specification Review",
},
"getApiResponsePayloadV3": [Function],
"looseEqual": [Function],
},
"time": Object {
"default": undefined,
Expand Down
30 changes: 30 additions & 0 deletions __tests__/actions/lookup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as LookupService from 'services/lookup';
import actions from 'actions/lookup';

const tag = {
domain: 'SKILLS',
id: 251,
name: 'Jekyll',
status: 'APPROVED',
};

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


describe('lookup.getApprovedSkills', () => {
const a = actions.lookup.getApprovedSkills();

test('has expected type', () => {
expect(a.type).toEqual('LOOKUP/GET_APPROVED_SKILLS');
});

test('Approved skills should be returned', () =>
a.payload.then((res) => {
expect(res).toEqual([tag]);
expect(mockLookupService.getTags).toBeCalled();
}));
});
252 changes: 252 additions & 0 deletions __tests__/actions/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
import * as ChallengesService from 'services/challenges';
import * as MembersService from 'services/members';
import * as UserService from 'services/user';

import actions from 'actions/profile';

const handle = 'tcscoder';
const tokenV3 = 'tokenV3';
const profile = { userId: 12345, handle };
const skill = { tagId: 123, tagName: 'Node.js' };
const weblink = 'https://www.google.com';
const linkedAccounts = [{
providerType: 'github',
social: true,
userId: '623633',
}];

// Mock services
const mockChanllengesService = {
getUserChallenges: jest.fn().mockReturnValue(Promise.resolve({ totalCount: 3 })),
getUserMarathonMatches: jest.fn().mockReturnValue(Promise.resolve({ totalCount: 5 })),
};
ChallengesService.getService = jest.fn().mockReturnValue(mockChanllengesService);

const mockMembersService = {
getPresignedUrl: jest.fn().mockReturnValue(Promise.resolve()),
uploadFileToS3: jest.fn().mockReturnValue(Promise.resolve()),
updateMemberPhoto: jest.fn().mockReturnValue(Promise.resolve('url-of-photo')),
updateMemberProfile: jest.fn().mockReturnValue(Promise.resolve(profile)),
addSkill: jest.fn().mockReturnValue(Promise.resolve({ skills: [skill] })),
hideSkill: jest.fn().mockReturnValue(Promise.resolve({ skills: [] })),
addWebLink: jest.fn().mockReturnValue(Promise.resolve(weblink)),
deleteWebLink: jest.fn().mockReturnValue(Promise.resolve(weblink)),
};
MembersService.getService = jest.fn().mockReturnValue(mockMembersService);

const mockUserService = {
linkExternalAccount: jest.fn().mockReturnValue(Promise.resolve(linkedAccounts[0])),
unlinkExternalAccount: jest.fn().mockReturnValue(Promise.resolve('unlinked')),
getLinkedAccounts: jest.fn().mockReturnValue(Promise.resolve({ profiles: linkedAccounts })),
getCredential: jest.fn().mockReturnValue(Promise.resolve({ credential: { hasPassword: true } })),
getEmailPreferences:
jest.fn().mockReturnValue(Promise.resolve({ subscriptions: { TOPCODER_NL_DATA: true } })),
saveEmailPreferences:
jest.fn().mockReturnValue(Promise.resolve({ subscriptions: { TOPCODER_NL_DATA: true } })),
updatePassword: jest.fn().mockReturnValue(Promise.resolve({ update: true })),
};
UserService.getService = jest.fn().mockReturnValue(mockUserService);


describe('profile.getActiveChallengesCountDone', () => {
const a = actions.profile.getActiveChallengesCountDone(handle, tokenV3);

test('has expected type', () => {
expect(a.type).toBe('PROFILE/GET_ACTIVE_CHALLENGES_COUNT_DONE');
});

test('Sum of challenges and marathon matches should be returned', () =>
a.payload.then((res) => {
expect(res).toBe(8);
expect(mockChanllengesService.getUserChallenges).toBeCalled();
expect(mockChanllengesService.getUserMarathonMatches).toBeCalled();
}));
});

describe('profile.uploadPhotoDone', () => {
const a = actions.profile.uploadPhotoDone(handle, tokenV3);

test('has expected type', () => {
expect(a.type).toBe('PROFILE/UPLOAD_PHOTO_DONE');
});

test('Photo URL should be returned', () =>
a.payload.then((res) => {
expect(res).toEqual({
handle,
photoURL: 'url-of-photo',
});
expect(mockMembersService.getPresignedUrl).toBeCalled();
expect(mockMembersService.uploadFileToS3).toBeCalled();
expect(mockMembersService.updateMemberPhoto).toBeCalled();
}));
});

describe('profile.updateProfileDone', () => {
const a = actions.profile.updateProfileDone(profile, tokenV3);

test('has expected type', () => {
expect(a.type).toBe('PROFILE/UPDATE_PROFILE_DONE');
});

test('Profile should be updated', () =>
a.payload.then((res) => {
expect(res).toEqual(profile);
expect(mockMembersService.updateMemberProfile).toBeCalled();
}));
});

describe('profile.addSkillDone', () => {
const a = actions.profile.addSkillDone(handle, tokenV3, skill);

test('has expected type', () => {
expect(a.type).toBe('PROFILE/ADD_SKILL_DONE');
});

test('Skill should be added', () =>
a.payload.then((res) => {
expect(res).toEqual({ skills: [skill], handle, skill });
expect(mockMembersService.addSkill).toBeCalled();
}));
});

describe('profile.hideSkillDone', () => {
const a = actions.profile.hideSkillDone(handle, tokenV3, skill);

test('has expected type', () => {
expect(a.type).toBe('PROFILE/HIDE_SKILL_DONE');
});

test('Skill should be removed', () =>
a.payload.then((res) => {
expect(res).toEqual({ skills: [], handle, skill });
expect(mockMembersService.hideSkill).toBeCalled();
}));
});

describe('profile.addWebLinkDone', () => {
const a = actions.profile.addWebLinkDone(handle, tokenV3, weblink);

test('has expected type', () => {
expect(a.type).toBe('PROFILE/ADD_WEB_LINK_DONE');
});

test('Web link should be added', () =>
a.payload.then((res) => {
expect(res).toEqual({ data: weblink, handle });
expect(mockMembersService.addWebLink).toBeCalled();
}));
});

describe('profile.deleteWebLinkDone', () => {
const a = actions.profile.deleteWebLinkDone(handle, tokenV3, weblink);

test('has expected type', () => {
expect(a.type).toBe('PROFILE/DELETE_WEB_LINK_DONE');
});

test('Web link should be deleted', () =>
a.payload.then((res) => {
expect(res).toEqual({ data: weblink, handle });
expect(mockMembersService.deleteWebLink).toBeCalled();
}));
});

describe('profile.linkExternalAccountDone', () => {
const a = actions.profile.linkExternalAccountDone(profile, tokenV3, 'github');

test('has expected type', () => {
expect(a.type).toBe('PROFILE/LINK_EXTERNAL_ACCOUNT_DONE');
});

test('External account should be linked', () =>
a.payload.then((res) => {
expect(res).toEqual({ data: linkedAccounts[0], handle });
expect(mockUserService.linkExternalAccount).toBeCalled();
}));
});

describe('profile.unlinkExternalAccountDone', () => {
const a = actions.profile.unlinkExternalAccountDone(profile, tokenV3, 'github');

test('has expected type', () => {
expect(a.type).toBe('PROFILE/UNLINK_EXTERNAL_ACCOUNT_DONE');
});

test('External account should be unlinked', () =>
a.payload.then((res) => {
expect(res).toEqual({ handle, providerType: 'github' });
expect(mockUserService.unlinkExternalAccount).toBeCalled();
}));
});

describe('profile.getLinkedAccountsDone', () => {
const a = actions.profile.getLinkedAccountsDone(profile, tokenV3);

test('has expected type', () => {
expect(a.type).toBe('PROFILE/GET_LINKED_ACCOUNTS_DONE');
});

test('Linked account should be returned', () =>
a.payload.then((res) => {
expect(res).toEqual({ profiles: linkedAccounts });
expect(mockUserService.getLinkedAccounts).toBeCalled();
}));
});

describe('profile.getCredentialDone', () => {
const a = actions.profile.getCredentialDone(profile, tokenV3);

test('has expected type', () => {
expect(a.type).toBe('PROFILE/GET_CREDENTIAL_DONE');
});

test('Credential should be returned', () =>
a.payload.then((res) => {
expect(res).toEqual({ credential: { hasPassword: true } });
expect(mockUserService.getCredential).toBeCalled();
}));
});

describe('profile.getEmailPreferencesDone', () => {
const a = actions.profile.getEmailPreferencesDone(profile, tokenV3);

test('has expected type', () => {
expect(a.type).toBe('PROFILE/GET_EMAIL_PREFERENCES_DONE');
});

test('Email preferences should be returned', () =>
a.payload.then((res) => {
expect(res).toEqual({ subscriptions: { TOPCODER_NL_DATA: true } });
expect(mockUserService.getEmailPreferences).toBeCalled();
}));
});

describe('profile.saveEmailPreferencesDone', () => {
const a = actions.profile.saveEmailPreferencesDone(profile, tokenV3, {});

test('has expected type', () => {
expect(a.type).toBe('PROFILE/SAVE_EMAIL_PREFERENCES_DONE');
});

test('Email preferences should be updated', () =>
a.payload.then((res) => {
expect(res).toEqual({ handle, data: { subscriptions: { TOPCODER_NL_DATA: true } } });
expect(mockUserService.saveEmailPreferences).toBeCalled();
}));
});

describe('profile.updatePasswordDone', () => {
const a = actions.profile.updatePasswordDone(profile, tokenV3, 'newPassword', 'oldPassword');

test('has expected type', () => {
expect(a.type).toBe('PROFILE/UPDATE_PASSWORD_DONE');
});

test('User password should be updated', () =>
a.payload.then((res) => {
expect(res).toEqual({ handle, data: { update: true } });
expect(mockUserService.updatePassword).toBeCalled();
}));
});

Loading