mattermost-mobile/detox/e2e/support/server_api/preference.js
Joseph Baylon 5b7f522404
MM-30423 Detox/E2E: Add e2e for MM-T3192, MM-T3215, MM-T3219, MM-T3221, MM-T3256 (#5180)
* MM-30423 Detox/E2E: Add e2e for MM-T3192, MM-T3215, MM-T3219, MM-T3221, MM-T3256

* Update detox/e2e/test/smoke_test/direct_messages.e2e.js

Co-authored-by: Saturnino Abril <saturnino.abril@gmail.com>

* Update detox/e2e/test/smoke_test/email_notifications.e2e.js

Co-authored-by: Saturnino Abril <saturnino.abril@gmail.com>

* Update detox/e2e/test/smoke_test/email_notifications.e2e.js

Co-authored-by: Saturnino Abril <saturnino.abril@gmail.com>

* Renamed return object status to userStatus

Co-authored-by: Saturnino Abril <saturnino.abril@gmail.com>
2021-02-23 08:09:47 -08:00

79 lines
2.4 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import client from './client';
import {getResponseFromError} from './common';
// ****************************************************************
// Preferences
// See https://api.mattermost.com/#tag/preferences
//
// Exported API function should have the following:
// - documented using JSDoc
// - meaningful description
// - match the referenced API endpoints
// - parameter/s defined by `@param`
// - return value defined by `@return`
// ****************************************************************
/**
* Save the user's preferences.
* See https://api.mattermost.com/#tag/preferences/paths/~1users~1{user_id}~1preferences/put
* @param {string} userId - the user ID
* @param {Array} preferences - a list of user's preferences
* @return {string} returns {status} on success or {error, status} on error
*/
export const apiSaveUserPreferences = async (userId, preferences = []) => {
try {
const response = await client.put(
`/api/v4/users/${userId}/preferences`,
preferences,
);
return {status: response.status};
} catch (err) {
return getResponseFromError(err);
}
};
/**
* Save the user's favorite channel preference.
* @param {string} userId - the user ID
* @param {string} channelId - the channel id to be favorited
* @return {string} returns {status} on success or {error, status} on error
*/
export const apiSaveFavoriteChannelPreference = (userId, channelId) => {
const preference = {
user_id: userId,
category: 'favorite_channel',
name: channelId,
value: 'true',
};
return apiSaveUserPreferences(userId, [preference]);
};
/**
* Save the user's teams order preference.
* @param {string} userId - the user ID
* @param {Array} orderedTeamIds - ordered array of team IDs
* @return {string} returns {status} on success or {error, status} on error
*/
export const apiSaveTeamsOrderPreference = (userId, orderedTeamIds = []) => {
const preference = {
user_id: userId,
category: 'teams_order',
name: '',
value: orderedTeamIds.toString(),
};
return apiSaveUserPreferences(userId, [preference]);
};
export const Preference = {
apiSaveFavoriteChannelPreference,
apiSaveTeamsOrderPreference,
apiSaveUserPreferences,
};
export default Preference;