mattermost-mobile/detox/e2e/support/server_api/system.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

72 lines
1.9 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import merge from 'merge-deep';
import testConfig from '@support/test_config';
import client from './client';
import {getResponseFromError} from './common';
import defaultServerConfig from './default_config.json';
// ****************************************************************
// System
// See https://api.mattermost.com/#tag/system
//
// 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`
// ****************************************************************
/**
* Get configuration.
* See https://api.mattermost.com/#tag/system/paths/~1config/get
*/
export const apiGetConfig = async () => {
try {
const response = await client.get('/api/v4/config');
return {config: response.data};
} catch (err) {
return getResponseFromError(err);
}
};
/**
* Update configuration.
* See https://api.mattermost.com/#tag/system/paths/~1config/put
* @param {Object} newConfig - specific config to update
*/
export const apiUpdateConfig = async (newConfig = {}) => {
try {
const {config: currentConfig} = await apiGetConfig();
const config = merge(currentConfig, getDefaultConfig(), newConfig);
const response = await client.put(
'/api/v4/config',
config,
);
return {config: response.data};
} catch (err) {
return getResponseFromError(err);
}
};
const getDefaultConfig = () => {
const fromEnv = {
ServiceSettings: {SiteURL: testConfig.siteUrl},
};
return merge(defaultServerConfig, fromEnv);
};
export const System = {
apiGetConfig,
apiUpdateConfig,
};
export default System;