* 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>
59 lines
1.7 KiB
JavaScript
59 lines
1.7 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';
|
|
|
|
// ****************************************************************
|
|
// Bots
|
|
// See https://api.mattermost.com/#tag/bots
|
|
//
|
|
// 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 bot.
|
|
* See https://api.mattermost.com/#operation/CreateBot
|
|
* @param {string} baseUrl - the base server URL
|
|
* @param {string} option.prefix - prefix to username and display name
|
|
* @param {Object} option.bot - bot object to be created
|
|
* @return {Object} returns {bot} on success or {error, status} on error
|
|
*/
|
|
export const apiCreateBot = async (baseUrl, {prefix = 'bot', bot = null} = {}) => {
|
|
try {
|
|
const newBot = bot || generateRandomBot({prefix});
|
|
|
|
const response = await client.post(
|
|
`${baseUrl}/api/v4/bots`,
|
|
newBot,
|
|
);
|
|
|
|
return {bot: response.data};
|
|
} catch (err) {
|
|
return getResponseFromError(err);
|
|
}
|
|
};
|
|
|
|
export const generateRandomBot = ({prefix = 'bot', randomIdLength = 6} = {}) => {
|
|
const randomId = getRandomId(randomIdLength);
|
|
|
|
return {
|
|
username: `${prefix}-${randomId}`,
|
|
display_name: `${capitalize(prefix)} ${randomId}`,
|
|
description: `Test bot description ${randomId}`,
|
|
};
|
|
};
|
|
|
|
export const Bot = {
|
|
apiCreateBot,
|
|
generateRandomBot,
|
|
};
|
|
|
|
export default Bot;
|