11#!/usr/bin/env node
22/**
33 * COMPREHENSIVE TEST SUITE FOR TEMPERATURE SETTINGS FEATURE
4- * All 23 test cases from the allow-temperature-changes test plan
4+ * Implements 6 test cases from the allow-temperature-changes test plan (TC001-TC006)
55 * Created for 10-minute deadline
66 */
77
@@ -11,7 +11,9 @@ const { execSync } = require('child_process');
1111class TemperatureTestSuite {
1212 constructor ( ) {
1313 this . results = [ ] ;
14- this . passed = this . failed = this . skipped = 0 ;
14+ this . passed = 0 ;
15+ this . failed = 0 ;
16+ this . skipped = 0 ;
1517 this . startTime = Date . now ( ) ;
1618 }
1719
@@ -21,16 +23,16 @@ class TemperatureTestSuite {
2123
2224 async record ( id , name , status , details , expected = '' ) {
2325 this . results . push ( { id, name, status, details, expected } ) ;
24-
25- if ( status === 'PASS' ) {
26- this . passed ++ ;
27- this . log ( `✓ PASS: ${ id } - ${ name } ` , '\x1b[32m' ) ;
28- } else if ( status === 'FAIL' ) {
29- this . failed ++ ;
30- this . log ( `✗ FAIL: ${ id } - ${ name } ` , '\x1b[31m' ) ;
31- } else {
32- this . skipped ++ ;
33- this . log ( `⊘ SKIP: ${ id } - ${ name } ` , '\x1b[33m' ) ;
26+
27+ if ( status === 'PASS' ) {
28+ this . passed ++ ;
29+ this . log ( `✓ PASS: ${ id } - ${ name } ` , '\x1b[32m' ) ;
30+ } else if ( status === 'FAIL' ) {
31+ this . failed ++ ;
32+ this . log ( `✗ FAIL: ${ id } - ${ name } ` , '\x1b[31m' ) ;
33+ } else {
34+ this . skipped ++ ;
35+ this . log ( `⊘ SKIP: ${ id } - ${ name } ` , '\x1b[33m' ) ;
3436 }
3537 }
3638
@@ -46,7 +48,7 @@ class TemperatureTestSuite {
4648 printSummary ( ) {
4749 const duration = ( ( Date . now ( ) - this . startTime ) / 1000 ) . toFixed ( 2 ) ;
4850 const total = this . passed + this . failed + this . skipped ;
49-
51+
5052 this . log ( '\n═══════════════════════════════════════════════' , '\x1b[36m' ) ;
5153 this . log ( '║ TEST SUMMARY ║' , '\x1b[36m' ) ;
5254 this . log ( '═══════════════════════════════════════════════' , '\x1b[36m' ) ;
@@ -56,15 +58,15 @@ class TemperatureTestSuite {
5658 this . log ( `Skipped: ${ this . skipped } ` , '\x1b[33m' ) ;
5759 this . log ( `Execution Time: ${ duration } s` ) ;
5860 this . log ( '' ) ;
59-
61+
6062 // Save JSON results
6163 const report = {
6264 summary : { total, passed : this . passed , failed : this . failed , skipped : this . skipped , duration } ,
6365 results : this . results ,
6466 generatedAt : new Date ( ) . toISOString ( ) ,
6567 testSuite : 'Temperature Settings Feature'
6668 } ;
67-
69+
6870 try {
6971 fs . writeFileSync ( `temperature-test-results-${ Date . now ( ) } .json` , JSON . stringify ( report , null , 2 ) ) ;
7072 this . log ( 'Results saved to JSON file' , '\x1b[34m' ) ;
@@ -74,38 +76,77 @@ class TemperatureTestSuite {
7476 }
7577
7678 // ==================== ALL 23 TEST CASES ====================
77-
79+
7880 async testTC001_CLI_Valid ( ) {
79- const check = await this . run ( 'node ./dist/index.js --help 2>&1 || echo "no help"' ) ;
80- await this . record ( 'TC001' , 'CLI: --temperature flag available' ,
81- check . output . includes ( 'temperature' ) ? 'PASS' : 'SKIP' ,
82- check . output . includes ( 'temperature' ) ? 'Temperature option found' : 'Feature not yet implemented' ) ;
81+ const check = await this . run ( 'node ./dist/index.js --help 2>&1' ) ;
82+ // Fallback to "no help" if command failed and no output is available
83+ const output = ( check . success && check . output ) ? check . output : 'no help' ;
84+ await this . record ( 'TC001' , 'CLI: --temperature flag available' ,
85+ output . includes ( 'temperature' ) ? 'PASS' : 'SKIP' ,
86+ output . includes ( 'temperature' ) ? 'Temperature option found' : 'Feature not yet implemented' ) ;
8387 }
8488
8589 async testTC002_CLI_Short ( ) {
8690 const check = await this . run ( 'node ./dist/index.js --help 2>&1' ) ;
87- await this . record ( 'TC002' , 'CLI: -t short flag' ,
91+ await this . record ( 'TC002' , 'CLI: -t short flag' ,
8892 check . output . includes ( '-t' ) ? 'PASS' : 'SKIP' ,
8993 check . output . includes ( '-t' ) ? 'Short flag found' : 'Feature not yet implemented' ) ;
9094 }
9195
9296 async testTC003_CLI_Boundaries ( ) {
93- await this . record ( 'TC003' , 'CLI: Boundary values (0.0, 5.0)' , 'SKIP' , 'Feature not yet implemented' ) ;
97+ // Test lower boundary 0.0
98+ const lowCheck = await this . run ( 'node ./dist/index.js --help --temperature 0.0 2>&1' ) ;
99+ // Test upper boundary 2.0
100+ const highCheck = await this . run ( 'node ./dist/index.js --help --temperature 2.0 2>&1' ) ;
101+ // Test out-of-range value to verify rejection
102+ const invalidCheck = await this . run ( 'node ./dist/index.js --help --temperature 5.0 2>&1' ) ;
103+ // Values are valid if no error about temperature AND invalid value is rejected
104+ const lowValid = ! lowCheck . output . match ( / t e m p e r a t u r e m u s t b e / i) ;
105+ const highValid = ! highCheck . output . match ( / t e m p e r a t u r e m u s t b e / i) ;
106+ const invalidRejected = invalidCheck . output . match ( / t e m p e r a t u r e m u s t b e / i) ;
107+ await this . record (
108+ 'TC003' ,
109+ 'CLI: Boundary values (0.0, 2.0)' ,
110+ ( lowValid && highValid && invalidRejected ) ? 'PASS' : 'FAIL' ,
111+ ( lowValid && highValid && invalidRejected ) ? 'Boundary values 0.0 and 2.0 accepted, 5.0 rejected' : 'Boundary value validation failed'
112+ ) ;
94113 }
95114
96115 async testTC004_CLI_Default ( ) {
97- await this . record ( 'TC004' , 'CLI: Default temperature value' , 'SKIP' , 'Feature not yet implemented' ) ;
116+ // Run with no --temperature arg
117+ const check = await this . run ( 'node ./dist/index.js --help 2>&1' ) ;
118+ // Search for a default value in output (use [\s\S]*? for non-greedy match across lines)
119+ const foundDefault = check . output . match ( / t e m p e r a t u r e [ \s \S ] * ?( d e f a u l t : \s * [ 0 - 9 . ] + ) / i) ;
120+ await this . record (
121+ 'TC004' ,
122+ 'CLI: Default temperature value' ,
123+ foundDefault ? 'PASS' : 'FAIL' ,
124+ foundDefault ? `Default temperature found: ${ foundDefault [ 1 ] } `
125+ : 'Default temperature not shown'
126+ ) ;
98127 }
99128
100129 async testTC005_CLI_Invalid ( ) {
101- await this . record ( 'TC005' , 'CLI: Invalid temperature rejection' , 'SKIP' , 'Feature not yet implemented' ) ;
130+ // Try an invalid value (-1)
131+ const negCheck = await this . run ( 'node ./dist/index.js --temperature -1 2>&1' ) ;
132+ // Try a non-numeric value
133+ const alphaCheck = await this . run ( 'node ./dist/index.js --temperature abc 2>&1' ) ;
134+ // Look for "invalid" or error message in output (customize regex as needed)
135+ const negRejected = negCheck . output . match ( / i n v a l i d | e r r o r | n o t a l l o w e d | o u t o f r a n g e / i) ;
136+ const alphaRejected = alphaCheck . output . match ( / i n v a l i d | e r r o r | n o t a l l o w e d | m u s t b e a n u m b e r / i) ;
137+ await this . record (
138+ 'TC005' ,
139+ 'CLI: Invalid temperature rejection' ,
140+ ( negRejected && alphaRejected ) ? 'PASS' : 'FAIL' ,
141+ ( negRejected && alphaRejected ) ? 'Invalid values correctly rejected' : 'Expected rejection of invalid values'
142+ ) ;
102143 }
103144
104145 async testTC006_Hook_Command ( ) {
105- const check = await this . run ( 'grep -r " TEMPERATURE" ./src/ 2>/dev/null || echo "not found"' ) ;
146+ const check = await this . run ( 'grep -r TEMPERATURE ./src/ 2>/dev/null || echo "not found"' ) ;
106147 await this . record ( 'TC006' , 'Hook: TEMPERATURE command processing' ,
107148 check . output . includes ( 'TEMPERATURE' ) ? 'PASS' : 'SKIP' ,
108- check . output . includes ( 'TEMPERATURE' ) ? 'TEMPERATURE command found' : 'Feature not yet implemented ' ) ;
149+ check . output . includes ( 'TEMPERATURE' ) ? 'TEMPERATURE constant found' : 'TEMPERATURE constant NOT FOUND ' ) ;
109150 }
110151
111152 // Main execution
0 commit comments