This repository was archived by the owner on Feb 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-models.js
More file actions
67 lines (56 loc) · 2.05 KB
/
test-models.js
File metadata and controls
67 lines (56 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require('dotenv').config();
const mongoose = require('mongoose');
const { mongodbUri } = require('./config/config');
// Import models
const User = require('./src/models/user.model');
const Redesign = require('./src/models/redesign.model');
const Trend = require('./src/models/trend.model');
async function testModels() {
console.log('Testing MongoDB connection and models...');
console.log(`MongoDB URI: ${mongodbUri}`);
try {
// Connect to MongoDB
await mongoose.connect(mongodbUri);
console.log('Successfully connected to MongoDB!');
// Test User model
console.log('\nTesting User model...');
const users = await User.find().limit(5);
console.log(`Found ${users.length} users`);
// Test Redesign model
console.log('\nTesting Redesign model...');
const redesigns = await Redesign.find().limit(5);
console.log(`Found ${redesigns.length} redesigns`);
// Test Trend model
console.log('\nTesting Trend model...');
const trends = await Trend.find().limit(5);
console.log(`Found ${trends.length} trends`);
// Create test data if collections are empty
if (trends.length === 0) {
console.log('\nCreating sample trend data...');
const sampleTrend = new Trend({
category: 'style',
name: 'Modern Minimalism',
description: 'Clean lines, neutral colors, and focus on functionality with minimal decoration.',
sources: [
{
name: 'Pinterest',
url: 'https://pinterest.com/trending/modern-minimalism',
date: new Date()
}
],
popularity: 85,
roomTypes: ['living_room', 'bedroom', 'home_office']
});
await sampleTrend.save();
console.log('Sample trend created successfully!');
}
console.log('\nAll models loaded successfully!');
} catch (error) {
console.error('Error during model testing:', error);
} finally {
// Close the connection
await mongoose.connection.close();
console.log('\nConnection closed.');
}
}
testModels();