@@ -7,6 +7,7 @@ import { environment } from 'src/environments/environment';
77import { TranslateModule , TranslateService } from '@ngx-translate/core' ;
88import { WEBSOCKET_PIN_PATH } from '../constants/api.constants' ;
99import { LoaderService } from './loader.service' ;
10+ import { Power } from '../interfaces/verifiable-credential' ;
1011
1112
1213//todo mock broadcast channel
@@ -415,8 +416,8 @@ describe('WebsocketService', () => {
415416 timeout : 60 ,
416417 credentialPreview : {
417418 subjectName : 'John Doe' ,
419+ power : [ { function : 'Administrar' , action : [ 'create' , 'update' ] } ] ,
418420 organization : 'Test Org' ,
419- issuer : 'Test Issuer' ,
420421 expirationDate : '2025-12-31' ,
421422 } ,
422423 } ) ,
@@ -670,4 +671,78 @@ describe('WebsocketService', () => {
670671 clearIntervalSpy . mockRestore ( ) ;
671672 } ) ) ;
672673
674+ it ( 'should map powers to human readable format with single power' , ( ) => {
675+ const powers = [
676+ { function : 'Administrar' , action : [ 'create' , 'update' ] }
677+ ] ;
678+
679+ const result = service [ 'mapPowersToHumanReadable' ] ( powers ) ;
680+
681+ expect ( translateMock . instant ) . toHaveBeenCalledWith ( 'vc-fields.power.administrar' ) ;
682+ expect ( translateMock . instant ) . toHaveBeenCalledWith ( 'vc-fields.power.create' ) ;
683+ expect ( translateMock . instant ) . toHaveBeenCalledWith ( 'vc-fields.power.update' ) ;
684+ expect ( result ) . toContain ( ':' ) ;
685+ } ) ;
686+
687+ it ( 'should map powers to human readable format with multiple powers' , ( ) => {
688+ const powers = [
689+ { function : 'Administrar' , action : [ 'crear' ] } ,
690+ { function : 'Gestionar' , action : [ 'borrar' , 'modificar' ] }
691+ ] ;
692+
693+ const result = service [ 'mapPowersToHumanReadable' ] ( powers ) ;
694+
695+ expect ( result ) . toContain ( '<br/>' ) ;
696+ expect ( translateMock . instant ) . toHaveBeenCalledWith ( 'vc-fields.power.administrar' ) ;
697+ expect ( translateMock . instant ) . toHaveBeenCalledWith ( 'vc-fields.power.gestionar' ) ;
698+ } ) ;
699+
700+ it ( 'should return empty string for empty powers array' , ( ) => {
701+ expect ( service [ 'mapPowersToHumanReadable' ] ( [ ] ) ) . toBe ( '' ) ;
702+ } ) ;
703+
704+ it ( 'should normalize key by removing special characters and converting to lowercase' , ( ) => {
705+ expect ( service [ 'normalizeKey' ] ( 'Administrar' ) ) . toBe ( 'administrar' ) ;
706+ expect ( service [ 'normalizeKey' ] ( 'Test Key-123' ) ) . toBe ( 'testkey123' ) ;
707+ expect ( service [ 'normalizeKey' ] ( 'Special@#$Chars' ) ) . toBe ( 'specialchars' ) ;
708+ expect ( service [ 'normalizeKey' ] ( ' spaces ' ) ) . toBe ( 'spaces' ) ;
709+ } ) ;
710+
711+ it ( 'should normalize key with null or undefined' , ( ) => {
712+ expect ( service [ 'normalizeKey' ] ( null ) ) . toBe ( '' ) ;
713+ expect ( service [ 'normalizeKey' ] ( undefined ) ) . toBe ( '' ) ;
714+ } ) ;
715+
716+ it ( 'should normalize key with numbers' , ( ) => {
717+ expect ( service [ 'normalizeKey' ] ( 123 ) ) . toBe ( '123' ) ;
718+ expect ( service [ 'normalizeKey' ] ( 0 ) ) . toBe ( '0' ) ;
719+ } ) ;
720+
721+ it ( 'should normalize action keys from array' , ( ) => {
722+ const actions = [ 'Crear' , 'Editar' , 'Borrar' ] ;
723+ const result = service [ 'normalizeActionKeys' ] ( actions ) ;
724+
725+ expect ( result ) . toEqual ( [ 'crear' , 'editar' , 'borrar' ] ) ;
726+ } ) ;
727+
728+ it ( 'should normalize action keys with special characters' , ( ) => {
729+ const actions = [ 'Test-Action' , 'Special@Char' , '123Number' ] ;
730+ const result = service [ 'normalizeActionKeys' ] ( actions ) ;
731+
732+ expect ( result ) . toEqual ( [ 'testaction' , 'specialchar' , '123number' ] ) ;
733+ } ) ;
734+
735+ it ( 'should return empty array for non-array action keys' , ( ) => {
736+ expect ( service [ 'normalizeActionKeys' ] ( null ) ) . toEqual ( [ ] ) ;
737+ expect ( service [ 'normalizeActionKeys' ] ( undefined ) ) . toEqual ( [ ] ) ;
738+ expect ( service [ 'normalizeActionKeys' ] ( 'not-array' ) ) . toEqual ( [ ] ) ;
739+ } ) ;
740+
741+ it ( 'should filter out empty strings from normalized action keys' , ( ) => {
742+ const actions = [ 'valid' , '' , ' ' , 'another' ] ;
743+ const result = service [ 'normalizeActionKeys' ] ( actions ) ;
744+
745+ expect ( result ) . toEqual ( [ 'valid' , 'another' ] ) ;
746+ } ) ;
747+
673748} ) ;
0 commit comments