11import { CacheProvider } from '@data-client/react' ;
22import { DataProvider as ExternalDataProvider } from '@data-client/react/redux' ;
3- import { schema , RestEndpoint , PolymorphicInterface } from '@data-client/rest' ;
3+ import {
4+ schema ,
5+ RestEndpoint ,
6+ PolymorphicInterface ,
7+ RestGenerics ,
8+ Entity ,
9+ } from '@data-client/rest' ;
410import { resource } from '@data-client/rest' ;
511import {
612 IDEntity ,
@@ -10,6 +16,7 @@ import {
1016 SecondUnion ,
1117} from '__tests__/new' ;
1218import nock from 'nock' ;
19+ import qs from 'qs' ;
1320
1421import { makeRenderDataClient , act } from '../../../test' ;
1522import { useSuspense } from '../hooks' ;
@@ -19,6 +26,12 @@ import {
1926 valuesFixture ,
2027} from '../test-fixtures' ;
2128
29+ class QSEndpoint < O extends RestGenerics = any > extends RestEndpoint < O > {
30+ searchToString ( searchParams : any ) {
31+ return qs . stringify ( searchParams ) ;
32+ }
33+ }
34+
2235class Todo extends IDEntity {
2336 userId = 0 ;
2437 title = '' ;
@@ -607,6 +620,64 @@ describe.each([
607620 ] ) ;
608621 } ) ;
609622
623+ it ( 'should update on get for nested args change' , async ( ) => {
624+ const filtersA = {
625+ search : {
626+ type : 'Coupon' ,
627+ } ,
628+ } ;
629+ const filtersB = {
630+ search : {
631+ type : 'Cashback' ,
632+ } ,
633+ } ;
634+ class Offer extends Entity {
635+ id = '' ;
636+ text = '' ;
637+ }
638+ const OfferResource = resource ( {
639+ Endpoint : QSEndpoint ,
640+ schema : Offer ,
641+ searchParams : filtersA ,
642+ path : '/offers/:id' ,
643+ paginationField : 'page' ,
644+ } ) ;
645+
646+ const { result, rerender } = renderDataClient (
647+ ( { filters } ) => {
648+ return useSuspense ( OfferResource . getList , filters ) ;
649+ } ,
650+ {
651+ initialProps : { filters : filtersA } ,
652+ initialFixtures : [
653+ {
654+ endpoint : OfferResource . getList ,
655+ args : [ filtersA ] ,
656+ response : [
657+ { id : '5' , text : 'hi' } ,
658+ { id : '2' , text : 'next' } ,
659+ ] ,
660+ } ,
661+ {
662+ endpoint : OfferResource . getList ,
663+ args : [ filtersB ] ,
664+ response : [
665+ { id : '10' , text : 'second' } ,
666+ { id : '11' , text : 'page' } ,
667+ ] ,
668+ } ,
669+ ] ,
670+ } ,
671+ ) ;
672+ expect ( result . current ) . toMatchSnapshot ( ) ;
673+ console . log ( result . current ) ;
674+ const firstResult = result . current ;
675+ rerender ( { filters : filtersB } ) ;
676+ console . log ( result . current ) ;
677+ expect ( result . current ) . not . toEqual ( firstResult ) ;
678+ expect ( result . current ) . toMatchSnapshot ( ) ;
679+ } ) ;
680+
610681 it ( 'should update on get for a paginated resource with searchParams' , async ( ) => {
611682 mynock . get ( `/article` ) . reply ( 200 , paginatedFirstPage ) ;
612683 mynock . get ( `/article?userId=2` ) . reply ( 200 , paginatedFirstPage ) ;
0 commit comments