Data: update getKey helper function (#47548)
* build key conidering all url params * add getKet test with multiple parents * changelog
This commit is contained in:
parent
a13013e9a5
commit
1f20bc5af1
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: update
|
||||
|
||||
Data: update getKey helper function
|
|
@ -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 );
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue