Skip to content

update email preferences to use v5 api #66

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 1 commit into from
May 10, 2019
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 __tests__/actions/__snapshots__/profile.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ Object {
},
},
"handle": "tcscoder",
"preferences": Object {},
},
"type": "PROFILE/SAVE_EMAIL_PREFERENCES_DONE",
}
Expand Down
12 changes: 6 additions & 6 deletions __tests__/reducers/__snapshots__/profile.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ Object {
"deletingPhoto": false,
"deletingWebLink": false,
"emailPreferences": Object {
"TOPCODER_NL_DATA": true,
"Dev Newsletter": true,
},
"externalLinks": Array [
Object {
Expand Down Expand Up @@ -939,7 +939,7 @@ Object {
"deletingPhoto": false,
"deletingWebLink": false,
"emailPreferences": Object {
"TOPCODER_NL_DATA": true,
"Dev Newsletter": true,
},
"externalLinks": Array [
Object {
Expand Down Expand Up @@ -989,7 +989,7 @@ Object {
"deletingPhoto": false,
"deletingWebLink": false,
"emailPreferences": Object {
"TOPCODER_NL_DATA": true,
"Dev Newsletter": true,
},
"externalLinks": Array [
Object {
Expand Down Expand Up @@ -1926,7 +1926,7 @@ Object {
"deletingPhoto": false,
"deletingWebLink": false,
"emailPreferences": Object {
"TOPCODER_NL_DATA": true,
"Dev Newsletter": true,
},
"externalLinks": Array [
Object {
Expand Down Expand Up @@ -2125,7 +2125,7 @@ Object {
"deletingPhoto": false,
"deletingWebLink": false,
"emailPreferences": Object {
"TOPCODER_NL_DATA": true,
"Dev Newsletter": true,
},
"externalLinks": Array [
Object {
Expand Down Expand Up @@ -2175,7 +2175,7 @@ Object {
"deletingPhoto": false,
"deletingWebLink": false,
"emailPreferences": Object {
"TOPCODER_NL_DATA": true,
"Dev Newsletter": true,
},
"externalLinks": Array [
Object {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/reducers/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const mockActions = {
deleteWebLinkInit: mockAction('DELETE_WEB_LINK_INIT'),
deleteWebLinkDone: mockAction('DELETE_WEB_LINK_DONE', { handle, data: webLink }),
saveEmailPreferencesInit: mockAction('SAVE_EMAIL_PREFERENCES_INIT'),
saveEmailPreferencesDone: mockAction('SAVE_EMAIL_PREFERENCES_DONE', { handle, data: { subscriptions: { TOPCODER_NL_DATA: true } } }),
saveEmailPreferencesDone: mockAction('SAVE_EMAIL_PREFERENCES_DONE', { handle, preferences: { 'Dev Newsletter': true } }),
linkExternalAccountInit: mockAction('LINK_EXTERNAL_ACCOUNT_INIT'),
linkExternalAccountDone: mockAction('LINK_EXTERNAL_ACCOUNT_DONE', { handle, data: linkedAccount2 }),
unlinkExternalAccountInit: mockAction('UNLINK_EXTERNAL_ACCOUNT_INIT'),
Expand Down
1 change: 1 addition & 0 deletions config/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
API: {
V2: 'https://api.topcoder-dev.com/v2',
V3: 'https://api.topcoder-dev.com/v3',
V5: 'https://api.topcoder-dev.com/v5',
},
dummyConfigKey: 'Dummy config value',
};
2 changes: 1 addition & 1 deletion src/actions/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ function saveEmailPreferencesInit() {}
function saveEmailPreferencesDone(profile, tokenV3, preferences) {
const service = getUserService(tokenV3);
return service.saveEmailPreferences(profile, preferences)
.then(res => ({ data: res, handle: profile.handle }));
.then(res => ({ data: res, handle: profile.handle, preferences }));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/reducers/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,13 @@ function onSaveEmailPreferencesDone(state, { payload, error }) {
return newState;
}

if (newState.profileForHandle !== payload.handle || !payload.data) {
if (newState.profileForHandle !== payload.handle) {
return newState;
}

return {
...newState,
emailPreferences: payload.data.subscriptions,
emailPreferences: payload.preferences,
};
}

Expand Down
28 changes: 14 additions & 14 deletions src/services/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class User {
this.private = {
api: getApi('V3', tokenV3),
apiV2: getApi('V2', tokenV2),
apiV5: getApi('V5', tokenV3),
tokenV2,
tokenV3,
};
Expand Down Expand Up @@ -174,10 +175,10 @@ class User {
* @returns {Promise} Resolves to the email preferences result
*/
async getEmailPreferences(userId) {
const url = `/users/${userId}/preferences/email`;
const res = await this.private.api.get(url);
const x = (await res.json()).result;
return x.content;
const url = `/users/${userId}/preferences`;
const res = await this.private.apiV5.get(url);
const x = (await res.json());
return x.email;
}

/**
Expand All @@ -193,18 +194,17 @@ class User {
const settings = {
firstName,
lastName,
subscriptions: {},
createdBy: String(userId),
updatedBy: String(userId),
subscriptions: preferences,
};

if (!preferences) {
settings.subscriptions.TOPCODER_NL_GEN = true;
} else {
settings.subscriptions = preferences;
}
const url = `/users/${userId}/preferences/email`;

const res = await this.private.api.putJson(url, { param: settings });
return getApiResponsePayload(res);
const url = `/users/${userId}/preferences`;
const res = await this.private.apiV5.putJson(
url,
{ email: settings, objectId: String(userId) },
);
return res;
}

/**
Expand Down