@@ -2,9 +2,9 @@ import React, { useEffect, useState } from 'react'
22import { renderHook , waitFor } from '@testing-library/react'
33import { generateTestingUtils } from 'eth-testing'
44import { appConfig } from '../config'
5- import { Catalog , AuthToken , SubscriptionsAndServicesDDOs , DDO } from '../../src'
5+ import { Catalog , AuthToken , SubscriptionsAndServicesDDOs , SubscriptionsAndDatasetsDDOs , DDO } from '../../src'
66import jwt from 'jsonwebtoken'
7- import { ddo , ddo2 , ddo3 , walletAddress , nevermined } from '../mockups'
7+ import { ddo , ddo2 , ddo3 , ddo4 , ddo5 , walletAddress , nevermined } from '../mockups'
88import { faker } from '@faker-js/faker'
99
1010jest . mock ( '@nevermined-io/sdk' , ( ) => ( {
@@ -716,4 +716,118 @@ describe('Nevermined account', () => {
716716 expect ( result . current ) . toStrictEqual ( [ ddo2 , ddo3 ] )
717717 } )
718718 } )
719+
720+ it ( 'should get all the subscriptions published and datasets by the address passed' , async ( ) => {
721+ const { result } = renderHook (
722+ ( ) => {
723+ const { account, isLoadingSDK, updateSDK } = Catalog . useNevermined ( )
724+ const [ subscriptions , setSubscriptions ] = useState < SubscriptionsAndDatasetsDDOs [ ] > ( [ ] )
725+
726+ useEffect ( ( ) => {
727+ if ( isLoadingSDK ) {
728+ appConfig . web3Provider = testingUtils . getProvider ( )
729+ updateSDK ( appConfig )
730+ return
731+ }
732+
733+ ( async ( ) => {
734+ try {
735+ const result = await account . getPublishedSubscriptionsAndDatasets ( walletAddress )
736+
737+ setSubscriptions ( [ ...result ] )
738+ } catch ( error : any ) {
739+ console . error ( error . message )
740+ }
741+ } ) ( )
742+ } , [ isLoadingSDK ] )
743+
744+ return subscriptions
745+ } ,
746+ {
747+ wrapper : wrapperProvider
748+ }
749+ )
750+
751+ await waitFor ( ( ) => {
752+ expect ( result . current ) . toStrictEqual ( [ {
753+ subscription : ddo ,
754+ datasets : [ ddo4 , ddo5 ]
755+ } ] )
756+ } )
757+ } )
758+
759+ it ( 'should get all the subscriptions purchased and datasets by the address passed' , async ( ) => {
760+ const { result } = renderHook (
761+ ( ) => {
762+ const { account, isLoadingSDK, updateSDK } = Catalog . useNevermined ( )
763+ const [ subscriptions , setSubscriptions ] = useState < SubscriptionsAndDatasetsDDOs [ ] > ( [ ] )
764+
765+ useEffect ( ( ) => {
766+ if ( isLoadingSDK ) {
767+ appConfig . web3Provider = testingUtils . getProvider ( )
768+ updateSDK ( appConfig )
769+ return
770+ }
771+
772+ ( async ( ) => {
773+ try {
774+ const result = await account . getPublishedSubscriptionsAndDatasets ( walletAddress )
775+
776+ setSubscriptions ( [ ...result ] )
777+ } catch ( error : any ) {
778+ console . error ( error . message )
779+ }
780+ } ) ( )
781+ } , [ isLoadingSDK ] )
782+
783+ return subscriptions
784+ } ,
785+ {
786+ wrapper : wrapperProvider
787+ }
788+ )
789+
790+ await waitFor ( ( ) => {
791+ expect ( result . current ) . toStrictEqual ( [ {
792+ subscription : ddo ,
793+ datasets : [ ddo4 , ddo5 ]
794+ } ] )
795+ } )
796+ } )
797+
798+ it ( 'should get all the datasets associated to the subscription id passed' , async ( ) => {
799+ const { result } = renderHook (
800+ ( ) => {
801+ const { account, isLoadingSDK, updateSDK } = Catalog . useNevermined ( )
802+ const [ datasets , setDatasets ] = useState < DDO [ ] > ( [ ] )
803+
804+ useEffect ( ( ) => {
805+ if ( isLoadingSDK ) {
806+ appConfig . web3Provider = testingUtils . getProvider ( )
807+ updateSDK ( appConfig )
808+ return
809+ }
810+
811+ ( async ( ) => {
812+ try {
813+ const result = await account . getAssociatedDatasets ( ddo . id )
814+
815+ setDatasets ( [ ...result ] )
816+ } catch ( error : any ) {
817+ console . error ( error . message )
818+ }
819+ } ) ( )
820+ } , [ isLoadingSDK ] )
821+
822+ return datasets
823+ } ,
824+ {
825+ wrapper : wrapperProvider
826+ }
827+ )
828+
829+ await waitFor ( ( ) => {
830+ expect ( result . current ) . toStrictEqual ( [ ddo4 , ddo5 ] )
831+ } )
832+ } )
719833} )
0 commit comments