2022-11-30 02:49:08 +03:00
|
|
|
var request = require('supertest');
|
|
|
|
request = request('http://127.0.0.1:8080');
|
|
|
|
|
|
|
|
const defaultAdminPassword = 'abc123';
|
|
|
|
|
2022-12-08 21:07:54 +03:00
|
|
|
async function getAdminResponse(endpoint, adminPassword = defaultAdminPassword) {
|
|
|
|
const url = '/api/admin/' + endpoint;
|
2022-11-30 02:50:00 +03:00
|
|
|
const res = request
|
2022-12-08 21:07:54 +03:00
|
|
|
.get(url)
|
2022-11-30 02:50:00 +03:00
|
|
|
.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-12-08 21:07:54 +03:00
|
|
|
async function sendAdminRequest(
|
2022-11-30 02:50:00 +03:00
|
|
|
endpoint,
|
|
|
|
value,
|
|
|
|
adminPassword = defaultAdminPassword
|
|
|
|
) {
|
2022-12-08 21:07:54 +03:00
|
|
|
const url = '/api/admin/' + endpoint;
|
2022-11-30 02:50:00 +03:00
|
|
|
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-12-08 21:07:54 +03:00
|
|
|
async function sendAdminPayload(
|
2022-11-30 02:50:00 +03:00
|
|
|
endpoint,
|
|
|
|
payload,
|
|
|
|
adminPassword = defaultAdminPassword
|
|
|
|
) {
|
2022-12-08 21:07:54 +03:00
|
|
|
const url = '/api/admin/' + endpoint;
|
2022-11-30 02:50:00 +03:00
|
|
|
const res = await request
|
|
|
|
.post(url)
|
|
|
|
.auth('admin', adminPassword)
|
|
|
|
.send(payload)
|
|
|
|
.expect(200);
|
|
|
|
|
2022-12-08 21:07:54 +03:00
|
|
|
expect(res.body.success).not.toBe(false);
|
2022-11-30 02:50:00 +03:00
|
|
|
|
|
|
|
return res;
|
2022-11-30 02:49:08 +03:00
|
|
|
}
|
|
|
|
|
2022-12-11 08:10:10 +03:00
|
|
|
async function failAdminRequest(
|
|
|
|
endpoint,
|
|
|
|
value,
|
|
|
|
adminPassword = defaultAdminPassword,
|
|
|
|
responseCode = 400
|
|
|
|
) {
|
|
|
|
const url = '/api/admin/' + endpoint;
|
|
|
|
const res = await request
|
|
|
|
.post(url)
|
|
|
|
.auth('admin', adminPassword)
|
|
|
|
.send({ value: value })
|
|
|
|
.expect(responseCode);
|
|
|
|
|
|
|
|
expect(res.body.success).toBe(false);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2022-12-08 21:07:54 +03:00
|
|
|
module.exports.getAdminResponse = getAdminResponse;
|
|
|
|
module.exports.sendAdminRequest = sendAdminRequest;
|
|
|
|
module.exports.sendAdminPayload = sendAdminPayload;
|
2022-12-11 08:10:10 +03:00
|
|
|
module.exports.failAdminRequest = failAdminRequest;
|
|
|
|
|