refactor chatuser api tests (#2416)

* block and unblock ipv6 explicitly

* refactor admin api tests

* use sendAdminPayload() for chatuser tests

* fix sendAdminRequests

* add getAdminResponse() to api test lib/admin.js

* some admin apis don't have response body

* cleanup test/automated/api/chatusers.test.js

* cleanup test/automated/api/chatusers.test.js

use getAdminResponse() to access admin apis
This commit is contained in:
Meisam
2022-12-08 19:07:54 +01:00
committed by GitHub
parent e5fef18b1c
commit fd683f0a72
4 changed files with 89 additions and 132 deletions

View File

@@ -3,30 +3,22 @@ request = request('http://127.0.0.1:8080');
const defaultAdminPassword = 'abc123';
async function getAdminConfig(adminPassword = defaultAdminPassword) {
async function getAdminResponse(endpoint, adminPassword = defaultAdminPassword) {
const url = '/api/admin/' + endpoint;
const res = request
.get('/api/admin/serverconfig')
.get(url)
.auth('admin', adminPassword)
.expect(200);
return res;
}
async function getAdminStatus(adminPassword = defaultAdminPassword) {
const res = request
.get('/api/admin/status')
.auth('admin', adminPassword)
.expect(200);
return res;
}
async function sendConfigChangeRequest(
async function sendAdminRequest(
endpoint,
value,
adminPassword = defaultAdminPassword
) {
const url = '/api/admin/config/' + endpoint;
const url = '/api/admin/' + endpoint;
const res = await request
.post(url)
.auth('admin', adminPassword)
@@ -37,24 +29,23 @@ async function sendConfigChangeRequest(
return res;
}
async function sendConfigChangePayload(
async function sendAdminPayload(
endpoint,
payload,
adminPassword = defaultAdminPassword
) {
const url = '/api/admin/config/' + endpoint;
const url = '/api/admin/' + endpoint;
const res = await request
.post(url)
.auth('admin', adminPassword)
.send(payload)
.expect(200);
expect(res.body.success).toBe(true);
expect(res.body.success).not.toBe(false);
return res;
}
module.exports.getAdminConfig = getAdminConfig;
module.exports.getAdminStatus = getAdminStatus;
module.exports.sendConfigChangeRequest = sendConfigChangeRequest;
module.exports.sendConfigChangePayload = sendConfigChangePayload;
module.exports.getAdminResponse = getAdminResponse;
module.exports.sendAdminRequest = sendAdminRequest;
module.exports.sendAdminPayload = sendAdminPayload;