@@ -188,118 +188,31 @@ describe("createBaseReport", () => {
188188} ) ;
189189
190190// Tests for CHECK_INFO
191- describe ( "CHECK_INFO" , ( ) => {
192- test ( "contains A002" , ( ) => {
193- expect ( "A002" in checkup . CHECK_INFO ) . toBe ( true ) ;
194- expect ( checkup . CHECK_INFO . A002 ) . toBe ( "Postgres major version" ) ;
195- } ) ;
196-
197- test ( "contains A003" , ( ) => {
198- expect ( "A003" in checkup . CHECK_INFO ) . toBe ( true ) ;
199- expect ( checkup . CHECK_INFO . A003 ) . toBe ( "Postgres settings" ) ;
200- } ) ;
201-
202- test ( "contains A013" , ( ) => {
203- expect ( "A013" in checkup . CHECK_INFO ) . toBe ( true ) ;
204- expect ( checkup . CHECK_INFO . A013 ) . toBe ( "Postgres minor version" ) ;
205- } ) ;
206-
207- test ( "contains A004" , ( ) => {
208- expect ( "A004" in checkup . CHECK_INFO ) . toBe ( true ) ;
209- expect ( checkup . CHECK_INFO . A004 ) . toBe ( "Cluster information" ) ;
210- } ) ;
211-
212- test ( "contains A007" , ( ) => {
213- expect ( "A007" in checkup . CHECK_INFO ) . toBe ( true ) ;
214- expect ( checkup . CHECK_INFO . A007 ) . toBe ( "Altered settings" ) ;
215- } ) ;
216-
217- test ( "contains H001" , ( ) => {
218- expect ( "H001" in checkup . CHECK_INFO ) . toBe ( true ) ;
219- expect ( checkup . CHECK_INFO . H001 ) . toBe ( "Invalid indexes" ) ;
220- } ) ;
221-
222- test ( "contains H002" , ( ) => {
223- expect ( "H002" in checkup . CHECK_INFO ) . toBe ( true ) ;
224- expect ( checkup . CHECK_INFO . H002 ) . toBe ( "Unused indexes" ) ;
225- } ) ;
226-
227- test ( "contains H004" , ( ) => {
228- expect ( "H004" in checkup . CHECK_INFO ) . toBe ( true ) ;
229- expect ( checkup . CHECK_INFO . H004 ) . toBe ( "Redundant indexes" ) ;
230- } ) ;
231-
232- test ( "contains D004" , ( ) => {
233- expect ( "D004" in checkup . CHECK_INFO ) . toBe ( true ) ;
234- expect ( checkup . CHECK_INFO . D004 ) . toBe ( "pg_stat_statements and pg_stat_kcache settings" ) ;
235- } ) ;
236-
237- test ( "contains F001" , ( ) => {
238- expect ( "F001" in checkup . CHECK_INFO ) . toBe ( true ) ;
239- expect ( checkup . CHECK_INFO . F001 ) . toBe ( "Autovacuum: current settings" ) ;
240- } ) ;
241-
242- test ( "contains G001" , ( ) => {
243- expect ( "G001" in checkup . CHECK_INFO ) . toBe ( true ) ;
244- expect ( checkup . CHECK_INFO . G001 ) . toBe ( "Memory-related settings" ) ;
245- } ) ;
246- } ) ;
247-
248- // Tests for REPORT_GENERATORS
249- describe ( "REPORT_GENERATORS" , ( ) => {
250- test ( "has generator for A002" , ( ) => {
251- expect ( "A002" in checkup . REPORT_GENERATORS ) . toBe ( true ) ;
252- expect ( typeof checkup . REPORT_GENERATORS . A002 ) . toBe ( "function" ) ;
253- } ) ;
254-
255- test ( "has generator for A003" , ( ) => {
256- expect ( "A003" in checkup . REPORT_GENERATORS ) . toBe ( true ) ;
257- expect ( typeof checkup . REPORT_GENERATORS . A003 ) . toBe ( "function" ) ;
258- } ) ;
259-
260- test ( "has generator for A013" , ( ) => {
261- expect ( "A013" in checkup . REPORT_GENERATORS ) . toBe ( true ) ;
262- expect ( typeof checkup . REPORT_GENERATORS . A013 ) . toBe ( "function" ) ;
263- } ) ;
264-
265- test ( "has generator for A004" , ( ) => {
266- expect ( "A004" in checkup . REPORT_GENERATORS ) . toBe ( true ) ;
267- expect ( typeof checkup . REPORT_GENERATORS . A004 ) . toBe ( "function" ) ;
268- } ) ;
269-
270- test ( "has generator for A007" , ( ) => {
271- expect ( "A007" in checkup . REPORT_GENERATORS ) . toBe ( true ) ;
272- expect ( typeof checkup . REPORT_GENERATORS . A007 ) . toBe ( "function" ) ;
273- } ) ;
274-
275- test ( "has generator for H001" , ( ) => {
276- expect ( "H001" in checkup . REPORT_GENERATORS ) . toBe ( true ) ;
277- expect ( typeof checkup . REPORT_GENERATORS . H001 ) . toBe ( "function" ) ;
278- } ) ;
279-
280- test ( "has generator for H002" , ( ) => {
281- expect ( "H002" in checkup . REPORT_GENERATORS ) . toBe ( true ) ;
282- expect ( typeof checkup . REPORT_GENERATORS . H002 ) . toBe ( "function" ) ;
283- } ) ;
284-
285- test ( "has generator for H004" , ( ) => {
286- expect ( "H004" in checkup . REPORT_GENERATORS ) . toBe ( true ) ;
287- expect ( typeof checkup . REPORT_GENERATORS . H004 ) . toBe ( "function" ) ;
288- } ) ;
289-
290- test ( "has generator for D004" , ( ) => {
291- expect ( "D004" in checkup . REPORT_GENERATORS ) . toBe ( true ) ;
292- expect ( typeof checkup . REPORT_GENERATORS . D004 ) . toBe ( "function" ) ;
293- } ) ;
191+ describe ( "CHECK_INFO and REPORT_GENERATORS" , ( ) => {
192+ const expectedChecks : Record < string , string > = {
193+ A002 : "Postgres major version" ,
194+ A003 : "Postgres settings" ,
195+ A004 : "Cluster information" ,
196+ A007 : "Altered settings" ,
197+ A013 : "Postgres minor version" ,
198+ D004 : "pg_stat_statements and pg_stat_kcache settings" ,
199+ F001 : "Autovacuum: current settings" ,
200+ G001 : "Memory-related settings" ,
201+ H001 : "Invalid indexes" ,
202+ H002 : "Unused indexes" ,
203+ H004 : "Redundant indexes" ,
204+ } ;
294205
295- test ( "has generator for F001" , ( ) => {
296- expect ( "F001" in checkup . REPORT_GENERATORS ) . toBe ( true ) ;
297- expect ( typeof checkup . REPORT_GENERATORS . F001 ) . toBe ( "function" ) ;
206+ test ( "CHECK_INFO contains all expected checks with correct descriptions" , ( ) => {
207+ for ( const [ checkId , description ] of Object . entries ( expectedChecks ) ) {
208+ expect ( checkup . CHECK_INFO [ checkId ] ) . toBe ( description ) ;
209+ }
298210 } ) ;
299211
300- test ( "has generator for G001" , ( ) => {
301- expect ( "G001" in checkup . REPORT_GENERATORS ) . toBe ( true ) ;
302- expect ( typeof checkup . REPORT_GENERATORS . G001 ) . toBe ( "function" ) ;
212+ test ( "REPORT_GENERATORS has function for each check" , ( ) => {
213+ for ( const checkId of Object . keys ( expectedChecks ) ) {
214+ expect ( typeof checkup . REPORT_GENERATORS [ checkId ] ) . toBe ( "function" ) ;
215+ }
303216 } ) ;
304217
305218 test ( "REPORT_GENERATORS and CHECK_INFO have same keys" , ( ) => {
@@ -720,35 +633,7 @@ describe("H001 - Invalid indexes", () => {
720633 expect ( dbData . database_size_pretty ) . toBeTruthy ( ) ;
721634 expect ( report . results [ "test-node" ] . postgres_version ) . toBeTruthy ( ) ;
722635 } ) ;
723-
724- test ( "generateH001 has correct top-level structure" , async ( ) => {
725- const mockClient = createMockClient (
726- [
727- { name : "server_version" , setting : "16.3" } ,
728- { name : "server_version_num" , setting : "160003" } ,
729- ] ,
730- [ ] ,
731- {
732- invalidIndexesRows : [
733- { schema_name : "public" , table_name : "orders" , index_name : "orders_status_idx" , relation_name : "orders" , index_size_bytes : "2097152" , supports_fk : false } ,
734- ] ,
735- }
736- ) ;
737-
738- const report = await checkup . generateH001 ( mockClient as any , "test-node" ) ;
739-
740- // Verify top-level structure matches schema expectations
741- expect ( report . checkId ) . toBe ( "H001" ) ;
742- expect ( report . checkTitle ) . toBe ( "Invalid indexes" ) ;
743- expect ( typeof report . timestamptz ) . toBe ( "string" ) ;
744- expect ( report . nodes . primary ) . toBe ( "test-node" ) ;
745- expect ( Array . isArray ( report . nodes . standbys ) ) . toBe ( true ) ;
746- expect ( "test-node" in report . results ) . toBe ( true ) ;
747- expect ( report . results [ "test-node" ] . postgres_version ) . toBeTruthy ( ) ;
748- // Data is now keyed by database name
749- expect ( "testdb" in report . results [ "test-node" ] . data ) . toBe ( true ) ;
750- expect ( ( report . results [ "test-node" ] . data as any ) [ "testdb" ] . invalid_indexes ) . toBeTruthy ( ) ;
751- } ) ;
636+ // Top-level structure tests removed - covered by schema-validation.test.ts
752637} ) ;
753638
754639// Tests for H002 (Unused indexes)
@@ -821,45 +706,7 @@ describe("H002 - Unused indexes", () => {
821706 expect ( dbData . stats_reset ) . toBeTruthy ( ) ;
822707 expect ( report . results [ "test-node" ] . postgres_version ) . toBeTruthy ( ) ;
823708 } ) ;
824-
825- test ( "generateH002 has correct top-level structure" , async ( ) => {
826- const mockClient = createMockClient (
827- [
828- { name : "server_version" , setting : "16.3" } ,
829- { name : "server_version_num" , setting : "160003" } ,
830- ] ,
831- [ ] ,
832- {
833- unusedIndexesRows : [
834- {
835- schema_name : "public" ,
836- table_name : "logs" ,
837- index_name : "logs_created_idx" ,
838- index_definition : "CREATE INDEX logs_created_idx ON public.logs USING btree (created_at)" ,
839- reason : "Never Used Indexes" ,
840- index_size_bytes : "8388608" ,
841- idx_scan : "0" ,
842- idx_is_btree : true ,
843- supports_fk : false ,
844- } ,
845- ] ,
846- }
847- ) ;
848-
849- const report = await checkup . generateH002 ( mockClient as any , "test-node" ) ;
850-
851- // Verify top-level structure matches schema expectations
852- expect ( report . checkId ) . toBe ( "H002" ) ;
853- expect ( report . checkTitle ) . toBe ( "Unused indexes" ) ;
854- expect ( typeof report . timestamptz ) . toBe ( "string" ) ;
855- expect ( report . nodes . primary ) . toBe ( "test-node" ) ;
856- expect ( Array . isArray ( report . nodes . standbys ) ) . toBe ( true ) ;
857- expect ( "test-node" in report . results ) . toBe ( true ) ;
858- expect ( report . results [ "test-node" ] . postgres_version ) . toBeTruthy ( ) ;
859- // Data is now keyed by database name
860- expect ( "testdb" in report . results [ "test-node" ] . data ) . toBe ( true ) ;
861- expect ( ( report . results [ "test-node" ] . data as any ) [ "testdb" ] . unused_indexes ) . toBeTruthy ( ) ;
862- } ) ;
709+ // Top-level structure tests removed - covered by schema-validation.test.ts
863710} ) ;
864711
865712// Tests for H004 (Redundant indexes)
@@ -949,50 +796,7 @@ describe("H004 - Redundant indexes", () => {
949796 expect ( dbData . database_size_bytes ) . toBeTruthy ( ) ;
950797 expect ( report . results [ "test-node" ] . postgres_version ) . toBeTruthy ( ) ;
951798 } ) ;
952-
953- test ( "generateH004 has correct top-level structure" , async ( ) => {
954- const mockClient = createMockClient (
955- [
956- { name : "server_version" , setting : "16.3" } ,
957- { name : "server_version_num" , setting : "160003" } ,
958- ] ,
959- [ ] ,
960- {
961- redundantIndexesRows : [
962- {
963- schema_name : "public" ,
964- table_name : "products" ,
965- index_name : "products_category_idx" ,
966- relation_name : "products" ,
967- access_method : "btree" ,
968- reason : "public.products_category_name_idx" ,
969- index_size_bytes : "4194304" ,
970- table_size_bytes : "33554432" ,
971- index_usage : "5" ,
972- supports_fk : false ,
973- index_definition : "CREATE INDEX products_category_idx ON public.products USING btree (category)" ,
974- redundant_to_json : JSON . stringify ( [
975- { index_name : "public.products_category_name_idx" , index_definition : "CREATE INDEX products_category_name_idx ON public.products USING btree (category, name)" , index_size_bytes : 2097152 }
976- ] ) ,
977- } ,
978- ] ,
979- }
980- ) ;
981-
982- const report = await checkup . generateH004 ( mockClient as any , "test-node" ) ;
983-
984- // Verify top-level structure matches schema expectations
985- expect ( report . checkId ) . toBe ( "H004" ) ;
986- expect ( report . checkTitle ) . toBe ( "Redundant indexes" ) ;
987- expect ( typeof report . timestamptz ) . toBe ( "string" ) ;
988- expect ( report . nodes . primary ) . toBe ( "test-node" ) ;
989- expect ( Array . isArray ( report . nodes . standbys ) ) . toBe ( true ) ;
990- expect ( "test-node" in report . results ) . toBe ( true ) ;
991- expect ( report . results [ "test-node" ] . postgres_version ) . toBeTruthy ( ) ;
992- // Data is now keyed by database name
993- expect ( "testdb" in report . results [ "test-node" ] . data ) . toBe ( true ) ;
994- expect ( ( report . results [ "test-node" ] . data as any ) [ "testdb" ] . redundant_indexes ) . toBeTruthy ( ) ;
995- } ) ;
799+ // Top-level structure tests removed - covered by schema-validation.test.ts
996800} ) ;
997801
998802// CLI tests
0 commit comments