0
Meisam fd683f0a72
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
2022-12-08 10:07:54 -08:00

52 lines
1.1 KiB
JavaScript

var request = require('supertest');
request = request('http://127.0.0.1:8080');
const defaultAdminPassword = 'abc123';
async function getAdminResponse(endpoint, adminPassword = defaultAdminPassword) {
const url = '/api/admin/' + endpoint;
const res = request
.get(url)
.auth('admin', adminPassword)
.expect(200);
return res;
}
async function sendAdminRequest(
endpoint,
value,
adminPassword = defaultAdminPassword
) {
const url = '/api/admin/' + endpoint;
const res = await request
.post(url)
.auth('admin', adminPassword)
.send({ value: value })
.expect(200);
expect(res.body.success).toBe(true);
return res;
}
async function sendAdminPayload(
endpoint,
payload,
adminPassword = defaultAdminPassword
) {
const url = '/api/admin/' + endpoint;
const res = await request
.post(url)
.auth('admin', adminPassword)
.send(payload)
.expect(200);
expect(res.body.success).not.toBe(false);
return res;
}
module.exports.getAdminResponse = getAdminResponse;
module.exports.sendAdminRequest = sendAdminRequest;
module.exports.sendAdminPayload = sendAdminPayload;