mattermost-mobile/detox/e2e/support/server_api/team.js
Saturnino Abril f05faaa949
E2E: Initial Detox setup for Mobile UI automation (#4535)
* initial Detox setup for mobile UI automation

* fix iOS allow permission on opening the app, add npm script to root folder, fix test when using longer site URL and add detox dependency to root for android build dependency

* remove detox proguardFile

* update packages and emulator

* change folder build on local and CI

* add test to post a message, ability to have test in isolation, server API commands, server config, dependency updates and update folder structure

* update snapshot

* update detox and do clean up

* update dependencies
2020-08-29 07:18:41 +08:00

77 lines
2.3 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {capitalize, getRandomId} from '@support/utils';
import client from './client';
import {getResponseFromError} from './common';
// ****************************************************************
// Teams
// See https://api.mattermost.com/#tag/teams
//
// 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`
// ****************************************************************
/**
* Create a team.
* See https://api.mattermost.com/#tag/teams/paths/~1teams/post
* @param {string} option.type - 'O' (default) for open, 'I' for invite only
* @param {string} option.prefix - option to add prefix to name and display name
* @param {Object} team - fix team object to be created
* @return {Object} returns {team} on success or {error, status} on error
*/
export const apiCreateTeam = async ({type = 'O', prefix = 'team', team = null} = {}) => {
try {
const response = await client.post(
'/api/v4/teams',
team || generateRandomTeam(type, prefix),
);
return {team: response.data};
} catch (err) {
return getResponseFromError(err);
}
};
/**
* Add user to team.
* See https://api.mattermost.com/#tag/teams/paths/~1teams~1{team_id}~1members/post
* @param {string} userId - The ID of user to add into the team
* @param {string} teamId - The team ID
* @return {Object} returns {member} on success or {error, status} on error
*/
export const apiAddUserToTeam = async (userId, teamId) => {
try {
const response = await client.post(
`/api/v4/teams/${teamId}/members`,
{team_id: teamId, user_id: userId},
);
return {member: response.data};
} catch (err) {
return getResponseFromError(err);
}
};
function generateRandomTeam(type, prefix) {
const randomId = getRandomId();
return {
name: `${prefix}-${randomId}`,
display_name: `${capitalize(prefix)} ${randomId}`,
type,
};
}
export const Team = {
apiAddUserToTeam,
apiCreateTeam,
};
export default Team;