Files
2026-07-23 11:52:07 +05:30

83 lines
2.3 KiB
JavaScript

import http from 'http';
function request(options, postData) {
return new Promise((resolve, reject) => {
const req = http.request(options, (res) => {
let body = '';
res.on('data', (chunk) => body += chunk);
res.on('end', () => {
resolve({
statusCode: res.statusCode,
headers: res.headers,
body: body
});
});
});
req.on('error', reject);
if (postData) {
req.write(postData);
}
req.end();
});
}
async function run() {
try {
// 1. Login
const loginData = JSON.stringify({
email: 'superadmin@maskan.com',
password: 'Admin@123'
});
const loginRes = await request({
hostname: 'localhost',
port: 5000,
path: '/api/v1/auth/login',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(loginData)
}
}, loginData);
const loginJson = JSON.parse(loginRes.body);
const token = loginJson.data?.token || loginJson.token || loginJson.data?.accessToken;
// 2. Try to create family with valid relations
console.log('\nCreating family with valid relations...');
const familyData = JSON.stringify({
name: `Relation Test Family ${Date.now()}`,
code: `rel_test_${Date.now()}`,
description: 'test description',
status: 'draft',
category: 'd94f6141-cc9a-449c-99ec-057c7c410848',
attributes: ['af2e5e61-0b73-42d0-bcde-aa9b9fd5c03a'],
variantAxes: ['af2e5e61-0b73-42d0-bcde-aa9b9fd5c03a'],
channels: ['amazon'],
assetRequirements: ['dc18511e-a47b-4b03-8b01-d05adc9cd2a9'],
allowedBrands: ['4d19ccdb-8399-4d7e-ae40-1cee4d5865f3'],
allowedUnits: ['00bbc825-5cec-4d10-8986-64d97368b0e2']
});
const createRes = await request({
hostname: 'localhost',
port: 5000,
path: '/api/v1/families',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(familyData),
'Authorization': `Bearer ${token}`
}
}, familyData);
console.log('Response status:', createRes.statusCode);
console.log('Response body:', createRes.body);
} catch (error) {
console.error('Error running test:', error);
}
}
run();