Skip to content

Commit

Permalink
Packages[core-data]: Accept numeric values for the "include" property…
Browse files Browse the repository at this point in the history
… in getQueryParts (#40570)

* Packages[core-data]: Change "include" type in getQueryParts

Convert the value of the parameter include into a string when it's
a number.

* Add some units test
  • Loading branch information
mauriac authored Apr 29, 2022
1 parent 0b19b54 commit fa23944
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/core-data/src/queried-data/get-query-parts.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export function getQueryParts( query ) {

// Two requests with different include values cannot have same results.
if ( key === 'include' ) {
if ( typeof value === 'number' ) {
value = value.toString();
}
parts.include = (
getNormalizedCommaSeparable( value ) ?? []
).map( Number );
Expand Down
4 changes: 4 additions & 0 deletions packages/core-data/src/queried-data/test/get-query-parts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ describe( 'getQueryParts', () => {
} );

it( 'parses out `include` ID filtering', () => {
const first = getQueryParts( { include: '1' } );
const second = getQueryParts( { include: 1 } );
const parts = getQueryParts( { include: [ 1 ] } );

expect( first ).toEqual( second );
expect( second ).toEqual( parts );
expect( parts ).toEqual( {
context: 'default',
page: 1,
Expand Down

0 comments on commit fa23944

Please sign in to comment.