breakhours-transform/compare.test.js

55 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2024-10-03 11:55:18 +00:00
import { compareTimeIntervals } from './compare.js';
import chalk from 'chalk';
// Test 1: Dummy data with differences in break_hours
const jsonWithDifferences1 = [
{
"start_time": "12:15",
"end_time": "18:00",
"break_hours": "0.25"
}
];
const jsonWithDifferences2 = [
{
"start_time": "12:15",
"end_time": "18:00",
"break_hours": "0.50" // Different break_hours
}
];
// Test 2: Dummy data with no differences in break_hours
const jsonWithoutDifferences1 = [
{
"start_time": "12:15",
"end_time": "18:00",
"break_hours": "0.25"
}
];
const jsonWithoutDifferences2 = [
{
"start_time": "12:15",
"end_time": "18:00",
"break_hours": "0.25" // Same break_hours
}
];
// Function to run a single test with result expectations
function runTest(testName, json1, json2, shouldFindDifference) {
const result = compareTimeIntervals(json1, json2);
// Log the test name, result, and total number of differences found
if ((result.length > 0 && shouldFindDifference) || (result.length === 0 && !shouldFindDifference)) {
console.log(`Test: ${testName} - ${chalk.green('OK')}`);
console.log(`Total differences: ${result.length}`);
} else {
console.log(`Test: ${testName} - ${chalk.red('FAILED')}`);
console.log(`Total differences: ${result.length}`);
}
}
// Run tests
runTest("Test with Differences", jsonWithDifferences1, jsonWithDifferences2, true); // Should expect 1 difference, return OK
runTest("Test without Differences", jsonWithoutDifferences1, jsonWithoutDifferences2, false); // Should expect 0 differences, return OK