216 lines
7.1 KiB
JavaScript
216 lines
7.1 KiB
JavaScript
// ========================================
|
|
// TESTS GÉNÉRÉS AUTOMATIQUEMENT - MissingKeywords
|
|
// Module: MissingKeywords.js
|
|
// Générés le: 2025-09-06T12:40:35.881Z
|
|
// ========================================
|
|
|
|
const assert = require('assert');
|
|
const { test, describe } = require('node:test');
|
|
const MissingKeywords = require('../../MissingKeywords.js');
|
|
const { AIContentValidator } = require('../validators/AIContentValidator');
|
|
|
|
describe('MissingKeywords - Tests automatiques', () => {
|
|
|
|
// Setup avant les tests
|
|
let testContext = {};
|
|
|
|
test('Module loading', () => {
|
|
assert.ok(MissingKeywords, 'Module should be loaded');
|
|
console.log('📦 Module MissingKeywords loaded successfully');
|
|
});
|
|
|
|
|
|
test('generateMissingKeywords - Content Generation', async () => {
|
|
const mockInput = ["test_value", { mc0: "test keyword", t0: "Test title" }];
|
|
|
|
try {
|
|
const result = await MissingKeywords.generateMissingKeywords(mockInput);
|
|
|
|
// Validations de base
|
|
assert.ok(result, 'Should return a result');
|
|
assert.ok(typeof result === 'string' || typeof result === 'object', 'Should return content');
|
|
|
|
// Validation IA si contenu texte
|
|
if (typeof result === 'string' && result.length > 50) {
|
|
const validation = await AIContentValidator.quickValidate(result, {
|
|
context: 'Generated content test'
|
|
});
|
|
assert.ok(validation.overall >= 40, 'Content quality should be acceptable');
|
|
}
|
|
|
|
console.log('✅ generateMissingKeywords: Content generated successfully');
|
|
|
|
} catch (error) {
|
|
console.error('❌ generateMissingKeywords: Generation failed:', error.message);
|
|
throw error;
|
|
}
|
|
});
|
|
|
|
test('callOpenAIForMissingKeywords - Async Operation', async () => {
|
|
const input = ["test_value", "Sample text for processing", { mc0: "test keyword", t0: "Test title" }];
|
|
|
|
try {
|
|
const startTime = Date.now();
|
|
const result = await MissingKeywords.callOpenAIForMissingKeywords(input);
|
|
const duration = Date.now() - startTime;
|
|
|
|
// Validations de base
|
|
assert.ok(result !== undefined, 'Should return a result');
|
|
assert.ok(duration < 30000, 'Should complete within 30 seconds');
|
|
|
|
console.log(`✅ callOpenAIForMissingKeywords: Completed in ${duration}ms`);
|
|
|
|
} catch (error) {
|
|
console.error('❌ callOpenAIForMissingKeywords: Async operation failed:', error.message);
|
|
throw error;
|
|
}
|
|
});
|
|
|
|
test('analyzeAvailableContext - Basic Function', () => {
|
|
const input = ["test_value", { mc0: "test keyword", t0: "Test title" }];
|
|
|
|
try {
|
|
const result = MissingKeywords.analyzeAvailableContext(input);
|
|
|
|
// Validations de base
|
|
assert.ok(result !== undefined, 'Should return a result');
|
|
assert.ok(typeof result !== 'undefined', 'Result should be defined');
|
|
|
|
console.log('✅ analyzeAvailableContext: Function executed successfully');
|
|
|
|
} catch (error) {
|
|
console.error('❌ analyzeAvailableContext: Function failed:', error.message);
|
|
throw error;
|
|
}
|
|
});
|
|
|
|
test('getElementContext - Basic Function', () => {
|
|
const input = ["test_value", "test_value", { mc0: "test keyword", t0: "Test title" }];
|
|
|
|
try {
|
|
const result = MissingKeywords.getElementContext(input);
|
|
|
|
// Validations de base
|
|
assert.ok(result !== undefined, 'Should return a result');
|
|
assert.ok(typeof result !== 'undefined', 'Result should be defined');
|
|
|
|
console.log('✅ getElementContext: Function executed successfully');
|
|
|
|
} catch (error) {
|
|
console.error('❌ getElementContext: Function failed:', error.message);
|
|
throw error;
|
|
}
|
|
});
|
|
|
|
test('parseMissingKeywordsResponse - Basic Function', () => {
|
|
const input = ["test_value", "test_value"];
|
|
|
|
try {
|
|
const result = MissingKeywords.parseMissingKeywordsResponse(input);
|
|
|
|
// Validations de base
|
|
assert.ok(result !== undefined, 'Should return a result');
|
|
assert.ok(typeof result !== 'undefined', 'Result should be defined');
|
|
|
|
console.log('✅ parseMissingKeywordsResponse: Function executed successfully');
|
|
|
|
} catch (error) {
|
|
console.error('❌ parseMissingKeywordsResponse: Function failed:', error.message);
|
|
throw error;
|
|
}
|
|
});
|
|
|
|
test('updateElementsWithKeywords - Basic Function', () => {
|
|
const input = ["test_value", "test_value"];
|
|
|
|
try {
|
|
const result = MissingKeywords.updateElementsWithKeywords(input);
|
|
|
|
// Validations de base
|
|
assert.ok(result !== undefined, 'Should return a result');
|
|
assert.ok(typeof result !== 'undefined', 'Result should be defined');
|
|
|
|
console.log('✅ updateElementsWithKeywords: Function executed successfully');
|
|
|
|
} catch (error) {
|
|
console.error('❌ updateElementsWithKeywords: Function failed:', error.message);
|
|
throw error;
|
|
}
|
|
});
|
|
|
|
test('if - Basic Function', () => {
|
|
const input = undefined;
|
|
|
|
try {
|
|
const result = MissingKeywords.if(input);
|
|
|
|
// Validations de base
|
|
assert.ok(result !== undefined, 'Should return a result');
|
|
assert.ok(typeof result !== 'undefined', 'Result should be defined');
|
|
|
|
console.log('✅ if: Function executed successfully');
|
|
|
|
} catch (error) {
|
|
console.error('❌ if: Function failed:', error.message);
|
|
throw error;
|
|
}
|
|
});
|
|
|
|
test('catch - Basic Function', () => {
|
|
const input = undefined;
|
|
|
|
try {
|
|
const result = MissingKeywords.catch(input);
|
|
|
|
// Validations de base
|
|
assert.ok(result !== undefined, 'Should return a result');
|
|
assert.ok(typeof result !== 'undefined', 'Result should be defined');
|
|
|
|
console.log('✅ catch: Function executed successfully');
|
|
|
|
} catch (error) {
|
|
console.error('❌ catch: Function failed:', error.message);
|
|
throw error;
|
|
}
|
|
});
|
|
|
|
test('map - Basic Function', () => {
|
|
const input = undefined;
|
|
|
|
try {
|
|
const result = MissingKeywords.map(input);
|
|
|
|
// Validations de base
|
|
assert.ok(result !== undefined, 'Should return a result');
|
|
assert.ok(typeof result !== 'undefined', 'Result should be defined');
|
|
|
|
console.log('✅ map: Function executed successfully');
|
|
|
|
} catch (error) {
|
|
console.error('❌ map: Function failed:', error.message);
|
|
throw error;
|
|
}
|
|
});
|
|
|
|
test('Export - generateMissingKeywords', () => {
|
|
assert.ok(MissingKeywords.generateMissingKeywords !== undefined, 'Export generateMissingKeywords should be available');
|
|
console.log('✅ Export generateMissingKeywords: Available');
|
|
});
|
|
|
|
|
|
// Test d'intégration général
|
|
test('Integration - Module health check', async () => {
|
|
try {
|
|
// Vérification exports
|
|
const exports = Object.keys(MissingKeywords);
|
|
assert.ok(exports.length > 0, 'Module should export functions');
|
|
|
|
console.log(`✅ MissingKeywords: ${exports.length} exports available`);
|
|
console.log('📋 Exports:', exports.join(', '));
|
|
|
|
} catch (error) {
|
|
console.error('❌ Integration test failed:', error.message);
|
|
throw error;
|
|
}
|
|
});
|
|
}); |