SYNC: don't use random data in testing REST service

This commit is contained in:
SPRINX0\prochazka
2026-03-02 15:09:41 +01:00
committed by Diflow
parent 6efc720a45
commit 2072f0b5ba
5 changed files with 29 additions and 29 deletions
+2 -2
View File
@@ -20,8 +20,8 @@ function generateCategories(count) {
name: categoryNames[i],
slug: categoryNames[i].toLowerCase().replace(/[^a-z0-9]+/g, '-'),
description: `Category for ${categoryNames[i]} products`,
parentId: i > 3 ? Math.floor(Math.random() * 4) + 1 : null,
active: Math.random() > 0.1,
parentId: i > 3 ? (i % 4) + 1 : null,
active: i % 10 !== 0,
displayOrder: i + 1
});
}
+5 -5
View File
@@ -2,18 +2,18 @@
const orders = [];
let nextId = 1;
// Helper function to generate sample data
// Helper function to generate sample data (deterministic, no randomness)
function generateOrders(count) {
const statuses = ['pending', 'processing', 'shipped', 'delivered', 'cancelled'];
for (let i = 0; i < count; i++) {
orders.push({
id: nextId++,
customerId: Math.floor(Math.random() * 200) + 1,
customerId: (i * 7 + 3) % 200 + 1,
orderNumber: `ORD-${String(i + 1).padStart(8, '0')}`,
totalAmount: parseFloat((Math.random() * 5000 + 50).toFixed(2)),
status: statuses[Math.floor(Math.random() * statuses.length)],
orderDate: new Date(Date.now() - Math.floor(Math.random() * 180 * 24 * 60 * 60 * 1000)).toISOString()
totalAmount: parseFloat(((i * 97 + 23) % 5000 + 50).toFixed(2)),
status: statuses[i % statuses.length],
orderDate: new Date(1700000000000 - i * 3600000 * 24).toISOString()
});
}
}
+8 -8
View File
@@ -2,25 +2,25 @@
const products = [];
let nextId = 1;
// Helper function to generate sample data
// Helper function to generate sample data (deterministic, no randomness)
function generateProducts(count) {
const categories = ['Electronics', 'Clothing', 'Books', 'Home & Garden', 'Sports', 'Toys'];
const adjectives = ['Premium', 'Deluxe', 'Standard', 'Basic', 'Pro', 'Ultra'];
const nouns = ['Widget', 'Gadget', 'Tool', 'Device', 'Item', 'Product'];
for (let i = 0; i < count; i++) {
const adjective = adjectives[Math.floor(Math.random() * adjectives.length)];
const noun = nouns[Math.floor(Math.random() * nouns.length)];
const adjective = adjectives[i % adjectives.length];
const noun = nouns[(i * 3 + 1) % nouns.length];
products.push({
id: nextId++,
name: `${adjective} ${noun} ${i + 1}`,
description: `This is a high-quality ${adjective.toLowerCase()} ${noun.toLowerCase()} for your needs.`,
price: parseFloat((Math.random() * 1000 + 10).toFixed(2)),
category: categories[Math.floor(Math.random() * categories.length)],
inStock: Math.random() > 0.2,
quantity: Math.floor(Math.random() * 500),
price: parseFloat(((i * 47 + 13) % 1000 + 10).toFixed(2)),
category: categories[i % categories.length],
inStock: i % 5 !== 0,
quantity: (i * 37 + 7) % 500,
sku: `SKU-${String(i + 1).padStart(6, '0')}`,
createdAt: new Date(Date.now() - Math.floor(Math.random() * 365 * 24 * 60 * 60 * 1000)).toISOString()
createdAt: new Date(1700000000000 - i * 86400000).toISOString()
});
}
}
+7 -7
View File
@@ -20,14 +20,14 @@ function generateReviews(count) {
for (let i = 0; i < count; i++) {
reviews.push({
id: nextId++,
productId: Math.floor(Math.random() * 200) + 1,
userId: Math.floor(Math.random() * 200) + 1,
rating: Math.floor(Math.random() * 5) + 1,
productId: (i * 11 + 1) % 200 + 1,
userId: (i * 13 + 5) % 200 + 1,
rating: (i % 5) + 1,
title: `Review ${i + 1}`,
comment: reviewTexts[Math.floor(Math.random() * reviewTexts.length)],
verified: Math.random() > 0.3,
helpfulCount: Math.floor(Math.random() * 100),
createdAt: new Date(Date.now() - Math.floor(Math.random() * 365 * 24 * 60 * 60 * 1000)).toISOString()
comment: reviewTexts[i % reviewTexts.length],
verified: i % 4 !== 0,
helpfulCount: (i * 7 + 3) % 100,
createdAt: new Date(1700000000000 - i * 86400000).toISOString()
});
}
}
+7 -7
View File
@@ -2,23 +2,23 @@
const users = [];
let nextId = 1;
// Helper function to generate sample data
// Helper function to generate sample data (deterministic, no randomness)
function generateUsers(count) {
const firstNames = ['John', 'Jane', 'Bob', 'Alice', 'Charlie', 'Diana', 'Eve', 'Frank', 'Grace', 'Henry'];
const lastNames = ['Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Garcia', 'Miller', 'Davis', 'Rodriguez', 'Martinez'];
const domains = ['example.com', 'test.com', 'demo.com', 'sample.org'];
for (let i = 0; i < count; i++) {
const firstName = firstNames[Math.floor(Math.random() * firstNames.length)];
const lastName = lastNames[Math.floor(Math.random() * lastNames.length)];
const firstName = firstNames[i % firstNames.length];
const lastName = lastNames[i % lastNames.length];
users.push({
id: nextId++,
firstName,
lastName,
email: `${firstName.toLowerCase()}.${lastName.toLowerCase()}${i}@${domains[Math.floor(Math.random() * domains.length)]}`,
age: Math.floor(Math.random() * 50) + 18,
active: Math.random() > 0.3,
createdAt: new Date(Date.now() - Math.floor(Math.random() * 365 * 24 * 60 * 60 * 1000)).toISOString()
email: `${firstName.toLowerCase()}.${lastName.toLowerCase()}${i}@${domains[i % domains.length]}`,
age: (i % 50) + 18,
active: i % 4 !== 0,
createdAt: new Date(1700000000000 - i * 86400000).toISOString()
});
}
}