mattermost-mobile/detox/e2e/support/server_api/preference.js
Joseph Baylon b87cf8358b
MM-41854 Detox/E2E: Setup detox infrastructure in Gekidou (#5979)
* MM-41854 Detox/E2E: Setup detox infrastructure in Gekidou

* Fix lint issues

* Fix lint issues

* Update API to include baseUrl for multiple servers

* Update init.js to have default siteUrl as baseUrl

* Update init.js to have default siteUrl as baseUrl

* Update import of testConfig

* Update import of testConfig

* Update postMessageAs signature

* Update detox/webhook_server.js

Co-authored-by: Avinash Lingaloo <avinashlng1080@gmail.com>

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Avinash Lingaloo <avinashlng1080@gmail.com>
2022-03-01 07:20:59 -08:00

101 lines
3.2 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 favorite channel preference.
* @param {string} baseUrl - the base server URL
* @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 = (baseUrl, userId, channelId) => {
const preference = {
user_id: userId,
category: 'favorite_channel',
name: channelId,
value: 'true',
};
return apiSaveUserPreferences(baseUrl, userId, [preference]);
};
/**
* Save the user's teammate name display preference.
* @param {string} baseUrl - the base server URL
* @param {string} userId - the user ID
* @param {string} nameFormat - one of "username" (default), "nickname_full_name" or "full_name"
* @returns
*/
export const apiSaveTeammateNameDisplayPreference = (baseUrl, userId, nameFormat = 'username') => {
const preference = {
user_id: userId,
category: 'display_settings',
name: 'name_format',
value: nameFormat,
};
return apiSaveUserPreferences(baseUrl, userId, [preference]);
};
/**
* Save the user's teams order preference.
* @param {string} baseUrl - the base server URL
* @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 = (baseUrl, userId, orderedTeamIds = []) => {
const preference = {
user_id: userId,
category: 'teams_order',
name: '',
value: orderedTeamIds.toString(),
};
return apiSaveUserPreferences(baseUrl, userId, [preference]);
};
/**
* Save the user's preferences.
* See https://api.mattermost.com/#operation/UpdatePreferences
* @param {string} baseUrl - the base server URL
* @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 (baseUrl, userId, preferences = []) => {
try {
const response = await client.put(
`${baseUrl}/api/v4/users/${userId}/preferences`,
preferences,
);
return {status: response.status};
} catch (err) {
return getResponseFromError(err);
}
};
export const Preference = {
apiSaveFavoriteChannelPreference,
apiSaveTeammateNameDisplayPreference,
apiSaveTeamsOrderPreference,
apiSaveUserPreferences,
};
export default Preference;