agmission/Development/server/scripts/validate_partner_schema.js

91 lines
3.6 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
/**
* Schema validation script - checks model definitions without DB connection
*
* Usage:
* node scripts/validate_partner_schema.js [--env <path>]
*
* Options:
* --env <path> Path to environment file (default: ./environment.env)
*/
'use strict';
const path = require('path');
// Parse command line arguments
const args = process.argv.slice(2);
let envFile = './environment.env';
for (let i = 0; i < args.length; i++) {
if (args[i] === '--env' && args[i + 1]) {
envFile = args[i + 1];
i++;
}
}
// Load environment variables
const envPath = path.resolve(process.cwd(), envFile);
console.log(`Loading environment from: ${envPath}`);
require('dotenv').config({ path: envPath });
console.log('🔍 Validating Partner Schema Definitions...\n');
// Check Partner model
try {
const { Partner, PartnerSystemUser } = require('../model/partner');
console.log('📋 Partner Schema Fields:');
const partnerFields = Object.keys(Partner.schema.paths);
console.log(' Partner fields:', partnerFields);
// Check for removed fields
const hasPartnerName = partnerFields.includes('partnerName');
const hasConfiguration = partnerFields.includes('configuration');
console.log(' ✅ partnerName field:', hasPartnerName ? 'FOUND (should be removed)' : 'NOT FOUND (correct)');
console.log(' ✅ configuration field:', hasConfiguration ? 'FOUND (should be removed)' : 'NOT FOUND (correct)');
console.log('\n📋 PartnerSystemUser Schema Fields:');
const systemUserFields = Object.keys(PartnerSystemUser.schema.paths);
console.log(' PartnerSystemUser fields:', systemUserFields);
// Check for field changes
const hasCustomer = systemUserFields.includes('customer');
const hasCustomerId = systemUserFields.includes('customerId');
const hasApplicatorId = systemUserFields.includes('applicatorId');
const hasOrganizationId = systemUserFields.includes('organizationId');
const hasAccessToken = systemUserFields.includes('accessToken');
const hasRefreshToken = systemUserFields.includes('refreshToken');
console.log(' ✅ customer field:', hasCustomer ? 'EXISTS (correct)' : 'MISSING');
console.log(' ✅ customerId field:', hasCustomerId ? 'FOUND (should be removed)' : 'NOT FOUND (correct)');
console.log(' ✅ applicatorId field:', hasApplicatorId ? 'FOUND (should be removed)' : 'NOT FOUND (correct)');
console.log(' ✅ organizationId field:', hasOrganizationId ? 'FOUND (should be removed)' : 'NOT FOUND (correct)');
console.log(' ✅ accessToken field:', hasAccessToken ? 'FOUND (should be removed)' : 'NOT FOUND (correct)');
console.log(' ✅ refreshToken field:', hasRefreshToken ? 'FOUND (should be removed)' : 'NOT FOUND (correct)');
console.log('\n🎯 Validation Results:');
const isPartnerValid = !hasPartnerName && !hasConfiguration;
const isSystemUserValid = hasCustomer && !hasCustomerId && !hasApplicatorId &&
!hasOrganizationId && !hasAccessToken && !hasRefreshToken;
if (isPartnerValid && isSystemUserValid) {
console.log(' ✅ All schema changes are CORRECT');
console.log(' ✅ Redundant fields have been removed');
console.log(' ✅ Field naming is consistent');
console.log('\n🎉 Schema validation PASSED!');
} else {
console.log(' ❌ Schema issues detected');
if (!isPartnerValid) console.log(' - Partner schema has redundant fields');
if (!isSystemUserValid) console.log(' - PartnerSystemUser schema has field issues');
console.log('\n⚠ Schema validation FAILED!');
}
} catch (error) {
console.error('❌ Schema validation failed:', error.message);
process.exit(1);
}