Data: update getKey helper function (#47548)

* build key conidering all url params

* add getKet test with multiple parents

* changelog
This commit is contained in:
Damián Suárez 2024-05-16 15:06:41 +01:00 committed by GitHub
parent a13013e9a5
commit 1f20bc5af1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 6 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: update
Data: update getKey helper function

View File

@ -51,6 +51,11 @@ describe( 'utils', () => {
expect( key ).toEqual( '5/3' );
} );
it( 'should get the key when a parents are provided', () => {
const key = getKey( 3, [ 200, 10 ] );
expect( key ).toEqual( '200/10/3' );
} );
it( 'should get the correct ID information when only an ID is given', () => {
const parsed = parseId( 3 );
expect( parsed.key ).toEqual( 3 );

View File

@ -54,12 +54,7 @@ export const getKey = ( query: IdQuery, urlParameters: IdType[] = [] ) => {
return id;
}
let prefix = '';
urlParameters.forEach( ( param ) => {
prefix = param + '/';
} );
return `${ prefix }${ id }`;
return urlParameters.join( '/' ) + '/' + id;
};
/**