55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
const https = require('https');
|
|
|
|
const agent = new https.Agent({ rejectUnauthorized: false });
|
|
|
|
const makeRequest = (path, data) => {
|
|
return new Promise((resolve, reject) => {
|
|
const payload = JSON.stringify(data);
|
|
const req = https.request({
|
|
hostname: '127.0.0.1',
|
|
port: 6969,
|
|
path: path,
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Content-Length': Buffer.byteLength(payload)
|
|
},
|
|
agent
|
|
}, (res) => {
|
|
let body = '';
|
|
res.on('data', chunk => body += chunk);
|
|
res.on('end', () => resolve({ status: res.statusCode, body }));
|
|
});
|
|
|
|
req.on('error', reject);
|
|
req.write(payload);
|
|
req.end();
|
|
});
|
|
};
|
|
|
|
async function testFlow() {
|
|
console.log("Registering new user...");
|
|
const regRes = await makeRequest('/launcher/profile/register', {
|
|
username: 'newuser123',
|
|
password: 'newpass123',
|
|
edition: 'Standard'
|
|
});
|
|
console.log("Registration:", regRes);
|
|
|
|
console.log("Logging in with new user...");
|
|
const loginRes = await makeRequest('/launcher/profile/login', {
|
|
username: 'newuser123',
|
|
password: 'newpass123'
|
|
});
|
|
console.log("Login:", loginRes);
|
|
const sessionId = loginRes.body;
|
|
|
|
console.log("Fetching profile info...");
|
|
const infoRes = await makeRequest('/launcher/profile/info', {
|
|
username: 'newuser123'
|
|
});
|
|
console.log("Info:", infoRes);
|
|
}
|
|
|
|
testFlow().catch(console.error);
|