mattermost-mobile/detox/e2e/plugins/post_message_as.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

46 lines
1.4 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
const axios = require('axios');
module.exports = async (baseUrl, {sender, message, channelId, rootId, createAt = 0}) => {
const loginResponse = await axios({
url: `${baseUrl}/api/v4/users/login`,
headers: {'X-Requested-With': 'XMLHttpRequest'},
method: 'post',
data: {login_id: sender.username, password: sender.password},
});
const setCookie = loginResponse.headers['set-cookie'];
let cookieString = '';
setCookie.forEach((cookie) => {
const nameAndValue = cookie.split(';')[0];
cookieString += nameAndValue + ';';
});
let response;
try {
response = await axios({
url: `${baseUrl}/api/v4/posts`,
headers: {
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
Cookie: cookieString,
},
method: 'post',
data: {
channel_id: channelId,
message,
type: '',
create_at: createAt,
root_id: rootId,
},
});
} catch (err) {
if (err.response) {
response = err.response;
}
}
return {status: response.status, data: response.data};
};