@@ -16,6 +16,7 @@ import { ValidationException } from '../../../src/exceptions/custom-exceptions/v
1616import { ValidationError } from 'class-validator' ;
1717import { Cacher } from '../../../src/helpers/cache/cacher.js' ;
1818import { WinstonLogger } from '../../../src/entities/logging/winston-logger.js' ;
19+ import { CreateTableCategoryDto } from '../../../src/entities/table-categories/dto/create-table-category.dto.js' ;
1920
2021const mockFactory = new MockFactory ( ) ;
2122let app : INestApplication ;
@@ -273,7 +274,7 @@ test.serial(`${currentTest} should return created connection properties with tab
273274 updateConnectionPropertiesROWithoutCategories . default_showing_table ,
274275 updatedConnectionPropertiesWithOutCategories . default_showing_table ,
275276 ) ;
276- t . is ( updateConnectionPropertiesROWithoutCategories . table_categories . length , 0 ) ;
277+ t . is ( updateConnectionPropertiesROWithoutCategories . table_categories . length , 1 ) ;
277278 } catch ( e ) {
278279 throw e ;
279280 }
@@ -623,9 +624,93 @@ test.serial(`${currentTest} should return updated connection properties`, async
623624 }
624625} ) ;
625626
626- // test.serial(`${currentTest} `, async (t) => {
627- // try {
628- // } catch (e) {
629- // throw e;
630- // }
631- // });
627+ test . serial (
628+ `${ currentTest } should keep created table categories if the exists return updated connection properties` ,
629+ async ( t ) => {
630+ try {
631+ const { newConnection2, newConnectionToTestDB, updateConnection, newGroup1, newConnection } = getTestData ( ) ;
632+ const { token } = await registerUserAndReturnUserInfo ( app ) ;
633+ const secondHiddenTableName = `${ faker . lorem . words ( 1 ) } _${ faker . string . uuid ( ) } ` ;
634+ await resetPostgresTestDB ( secondHiddenTableName ) ;
635+
636+ const createConnectionResponse = await request ( app . getHttpServer ( ) )
637+ . post ( '/connection' )
638+ . send ( newConnection )
639+ . set ( 'Cookie' , token )
640+ . set ( 'Content-Type' , 'application/json' )
641+ . set ( 'Accept' , 'application/json' ) ;
642+ const createConnectionRO = JSON . parse ( createConnectionResponse . text ) ;
643+ t . is ( createConnectionResponse . status , 201 ) ;
644+
645+ const createConnectionPropertiesResponse = await request ( app . getHttpServer ( ) )
646+ . post ( `/connection/properties/${ createConnectionRO . id } ` )
647+ . send ( newConnectionProperties )
648+ . set ( 'Cookie' , token )
649+ . set ( 'Content-Type' , 'application/json' )
650+ . set ( 'Accept' , 'application/json' ) ;
651+ const createConnectionPropertiesRO = JSON . parse ( createConnectionPropertiesResponse . text ) ;
652+ t . is ( createConnectionPropertiesResponse . status , 201 ) ;
653+ t . is ( createConnectionPropertiesRO . hidden_tables [ 0 ] , newConnectionProperties . hidden_tables [ 0 ] ) ;
654+ t . is ( createConnectionPropertiesRO . connectionId , createConnectionRO . id ) ;
655+
656+ const categoriesDTO : Array < CreateTableCategoryDto > = [
657+ {
658+ category_name : 'Category 1' ,
659+ category_color : '#FF5733' ,
660+ tables : [ testTableName ] ,
661+ category_id : 'cat-001' ,
662+ } ,
663+ ] ;
664+
665+ const createTableCategoriesResponse = await request ( app . getHttpServer ( ) )
666+ . put ( `/table-categories/${ createConnectionRO . id } ` )
667+ . send ( categoriesDTO )
668+ . set ( 'Cookie' , token )
669+ . set ( 'Content-Type' , 'application/json' )
670+ . set ( 'Accept' , 'application/json' ) ;
671+
672+ const createTableCategoriesRO = JSON . parse ( createTableCategoriesResponse . text ) ;
673+
674+ t . is ( createTableCategoriesResponse . status , 200 ) ;
675+
676+ const propertiesCopy = JSON . parse ( JSON . stringify ( newConnectionProperties ) ) ;
677+ propertiesCopy . hidden_tables = [ testTableName , secondHiddenTableName ] ;
678+
679+ const updateConnectionPropertiesResponse = await request ( app . getHttpServer ( ) )
680+ . put ( `/connection/properties/${ createConnectionRO . id } ` )
681+ . send ( propertiesCopy )
682+ . set ( 'Cookie' , token )
683+ . set ( 'Content-Type' , 'application/json' )
684+ . set ( 'Accept' , 'application/json' ) ;
685+
686+ t . is ( updateConnectionPropertiesResponse . status , 200 ) ;
687+
688+ const updateConnectionPropertiesRO = JSON . parse ( updateConnectionPropertiesResponse . text ) ;
689+ t . is ( updateConnectionPropertiesRO . hidden_tables . length , 2 ) ;
690+ t . is ( updateConnectionPropertiesRO . hidden_tables . includes ( testTableName ) , true ) ;
691+ t . is ( updateConnectionPropertiesRO . hidden_tables . includes ( secondHiddenTableName ) , true ) ;
692+ t . is ( updateConnectionPropertiesRO . connectionId , createConnectionRO . id ) ;
693+ t . is ( updateConnectionPropertiesRO . table_categories . length , 1 ) ;
694+ t . is ( updateConnectionPropertiesRO . table_categories [ 0 ] . category_name , 'Category 1' ) ;
695+ t . is ( updateConnectionPropertiesRO . table_categories [ 0 ] . tables . length , 1 ) ;
696+ t . is ( updateConnectionPropertiesRO . table_categories [ 0 ] . tables [ 0 ] , testTableName ) ;
697+
698+ const findTableCategoriesResponse = await request ( app . getHttpServer ( ) )
699+ . get ( `/table-categories/${ createConnectionRO . id } ` )
700+ . set ( 'Cookie' , token )
701+ . set ( 'Content-Type' , 'application/json' )
702+ . set ( 'Accept' , 'application/json' ) ;
703+
704+ const findTableCategoriesRO = JSON . parse ( findTableCategoriesResponse . text ) ;
705+
706+ t . is ( findTableCategoriesResponse . status , 200 ) ;
707+
708+ t . is ( findTableCategoriesRO . length , 1 ) ;
709+ t . is ( findTableCategoriesRO [ 0 ] . category_name , 'Category 1' ) ;
710+ t . is ( findTableCategoriesRO [ 0 ] . tables . length , 1 ) ;
711+ t . is ( findTableCategoriesRO [ 0 ] . tables [ 0 ] , testTableName ) ;
712+ } catch ( e ) {
713+ throw e ;
714+ }
715+ } ,
716+ ) ;
0 commit comments