2022-11-30 02:49:08 +03:00
|
|
|
var request = require('supertest');
|
|
|
|
request = request('http://127.0.0.1:8080');
|
|
|
|
|
|
|
|
const defaultAdminPassword = 'abc123';
|
|
|
|
|
|
|
|
async function getAdminConfig(adminPassword = defaultAdminPassword) {
|
2022-11-30 02:50:00 +03:00
|
|
|
const res = request
|
|
|
|
.get('/api/admin/serverconfig')
|
|
|
|
.auth('admin', adminPassword)
|
|
|
|
.expect(200);
|
2022-11-30 02:49:08 +03:00
|
|
|
|
2022-11-30 02:50:00 +03:00
|
|
|
return res;
|
2022-11-30 02:49:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
async function getAdminStatus(adminPassword = defaultAdminPassword) {
|
2022-11-30 02:50:00 +03:00
|
|
|
const res = request
|
|
|
|
.get('/api/admin/status')
|
|
|
|
.auth('admin', adminPassword)
|
|
|
|
.expect(200);
|
2022-11-30 02:49:08 +03:00
|
|
|
|
2022-11-30 02:50:00 +03:00
|
|
|
return res;
|
2022-11-30 02:49:08 +03:00
|
|
|
}
|
|
|
|
|
2022-11-30 02:50:00 +03:00
|
|
|
async function sendConfigChangeRequest(
|
|
|
|
endpoint,
|
|
|
|
value,
|
|
|
|
adminPassword = defaultAdminPassword
|
|
|
|
) {
|
|
|
|
const url = '/api/admin/config/' + endpoint;
|
|
|
|
const res = await request
|
|
|
|
.post(url)
|
|
|
|
.auth('admin', adminPassword)
|
|
|
|
.send({ value: value })
|
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
expect(res.body.success).toBe(true);
|
|
|
|
return res;
|
2022-11-30 02:49:08 +03:00
|
|
|
}
|
|
|
|
|
2022-11-30 02:50:00 +03:00
|
|
|
async function sendConfigChangePayload(
|
|
|
|
endpoint,
|
|
|
|
payload,
|
|
|
|
adminPassword = defaultAdminPassword
|
|
|
|
) {
|
|
|
|
const url = '/api/admin/config/' + endpoint;
|
|
|
|
const res = await request
|
|
|
|
.post(url)
|
|
|
|
.auth('admin', adminPassword)
|
|
|
|
.send(payload)
|
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
expect(res.body.success).toBe(true);
|
|
|
|
|
|
|
|
return res;
|
2022-11-30 02:49:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.getAdminConfig = getAdminConfig;
|
|
|
|
module.exports.getAdminStatus = getAdminStatus;
|
|
|
|
module.exports.sendConfigChangeRequest = sendConfigChangeRequest;
|
|
|
|
module.exports.sendConfigChangePayload = sendConfigChangePayload;
|