11import { expect , it , jest } from '@jest/globals' ;
22import { type SendTelegram } from '../../src/web3telegram/sendTelegram.js' ;
3- import { getRandomAddress , TEST_CHAIN } from '../test-utils.js' ;
4- import {
5- WEB3TELEGRAM_DAPP_ADDRESS ,
6- WHITELIST_SMART_CONTRACT_ADDRESS ,
7- } from '../../src/config/config.js' ;
3+ import { getRandomAddress } from '../test-utils.js' ;
4+ import { CHAIN_CONFIG , CHAIN_IDS } from '../../src/config/config.js' ;
85import { mockAllForSendTelegram } from '../utils/mockAllForSendTelegram.js' ;
96
107jest . unstable_mockModule ( '../../src/utils/subgraphQuery.js' , ( ) => ( {
118 checkProtectedDataValidity : jest . fn ( ) ,
129} ) ) ;
1310
11+ jest . unstable_mockModule ( '../../src/utils/ipfs-service.js' , ( ) => ( {
12+ add : jest . fn ( ( ) => Promise . resolve ( 'QmSBoN71925mWJ6acehqDLQrrxihxX55EXrqHxpYja4HCG' ) ) ,
13+ get : jest . fn ( ( ) => Promise . resolve ( new ArrayBuffer ( 8 ) ) ) ,
14+ } ) ) ;
15+
1416describe ( 'sendTelegram' , ( ) => {
1517 let testedModule : any ;
1618 let sendTelegram : SendTelegram ;
@@ -33,10 +35,13 @@ describe('sendTelegram', () => {
3335
3436 await expect (
3537 sendTelegram ( {
36- // @ts -expect-error No need for graphQLClient here
37- graphQLClient : { } ,
38- // @ts -expect-error No need for iexec here
39- iexec : { } ,
38+ graphQLClient : { request : jest . fn ( ) } as any ,
39+ iexec : mockAllForSendTelegram ( ) as any ,
40+ workerpoolAddressOrEns : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . prodWorkerpoolAddress ,
41+ dappAddressOrENS : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . dappAddress ,
42+ dappWhitelistAddress : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . whitelistSmartContract ,
43+ ipfsNode : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . ipfsUploadUrl ,
44+ ipfsGateway : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . ipfsGateway ,
4045 senderName : 'AB' , // Trop court, déclenche l'erreur Yup
4146 ...sendTelegramParams ,
4247 } )
@@ -63,10 +68,13 @@ describe('sendTelegram', () => {
6368
6469 await expect (
6570 sendTelegram ( {
66- // @ts -expect-error No need for graphQLClient here
67- graphQLClient : { } ,
68- // @ts -expect-error No need for iexec here
69- iexec : { } ,
71+ graphQLClient : { request : jest . fn ( ) } as any ,
72+ iexec : mockAllForSendTelegram ( ) as any ,
73+ workerpoolAddressOrEns : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . prodWorkerpoolAddress ,
74+ dappAddressOrENS : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . dappAddress ,
75+ dappWhitelistAddress : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . whitelistSmartContract ,
76+ ipfsNode : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . ipfsUploadUrl ,
77+ ipfsGateway : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . ipfsGateway ,
7078 senderName : 'AB' , // Trop court, déclenche l'erreur Yup
7179 ...sendTelegramParams ,
7280 } )
@@ -93,10 +101,13 @@ describe('sendTelegram', () => {
93101
94102 await expect (
95103 sendTelegram ( {
96- // @ts -expect-error No need for graphQLClient here
97- graphQLClient : { } ,
98- // @ts -expect-error No need for iexec here
99- iexec : { } ,
104+ graphQLClient : { request : jest . fn ( ) } as any ,
105+ iexec : mockAllForSendTelegram ( ) as any ,
106+ workerpoolAddressOrEns : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . prodWorkerpoolAddress ,
107+ dappAddressOrENS : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . dappAddress ,
108+ dappWhitelistAddress : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . whitelistSmartContract ,
109+ ipfsNode : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . ipfsUploadUrl ,
110+ ipfsGateway : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . ipfsGateway ,
100111 ...sendTelegramParams ,
101112 } )
102113 ) . rejects . toMatchObject ( {
@@ -121,15 +132,16 @@ describe('sendTelegram', () => {
121132 } ;
122133
123134 await expect (
124- // --- WHEN
125135 sendTelegram ( {
126- // @ts -expect-error No need for graphQLClient here
127- graphQLClient : { } ,
128- // @ts -expect-error No need for iexec here
129- iexec : { } ,
136+ graphQLClient : { request : jest . fn ( ) } as any ,
137+ iexec : mockAllForSendTelegram ( ) as any ,
138+ workerpoolAddressOrEns : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . prodWorkerpoolAddress ,
139+ dappAddressOrENS : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . dappAddress ,
140+ dappWhitelistAddress : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . whitelistSmartContract ,
141+ ipfsNode : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . ipfsUploadUrl ,
142+ ipfsGateway : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . ipfsGateway ,
130143 ...sendTelegramParams ,
131144 } )
132- // --- THEN
133145 ) . rejects . toMatchObject ( {
134146 message : 'Failed to sendTelegram' ,
135147 cause : expect . objectContaining ( {
@@ -154,15 +166,16 @@ describe('sendTelegram', () => {
154166 } ;
155167
156168 await expect (
157- // --- WHEN
158169 sendTelegram ( {
159- // @ts -expect-error No need for graphQLClient here
160- graphQLClient : { } ,
161- // @ts -expect-error No need for iexec here
162- iexec : { } ,
170+ graphQLClient : { request : jest . fn ( ) } as any ,
171+ iexec : mockAllForSendTelegram ( ) as any ,
172+ workerpoolAddressOrEns : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . prodWorkerpoolAddress ,
173+ dappAddressOrENS : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . dappAddress ,
174+ dappWhitelistAddress : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . whitelistSmartContract ,
175+ ipfsNode : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . ipfsUploadUrl ,
176+ ipfsGateway : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . ipfsGateway ,
163177 ...sendTelegramParams ,
164178 } )
165- // --- THEN
166179 ) . rejects . toMatchObject ( {
167180 message : 'Failed to sendTelegram' ,
168181 cause : expect . objectContaining ( {
@@ -187,21 +200,19 @@ describe('sendTelegram', () => {
187200 checkProtectedDataValidity . mockResolvedValue ( true ) ;
188201
189202 const protectedData = getRandomAddress ( ) . toLowerCase ( ) ;
190- const iexec = mockAllForSendTelegram ( ) ;
203+ const iexec = mockAllForSendTelegram ( ) as any ;
191204
192205 const userAddress = await iexec . wallet . getAddress ( ) ;
193206
194207 // --- WHEN
195208 await sendTelegram ( {
196- // @ts -expect-error No need for graphQLClient here
197- graphQLClient : { } ,
198- // @ts -expect-error No need for iexec here
209+ graphQLClient : { request : jest . fn ( ) } as any ,
199210 iexec,
200- // // @ts -expect-error No need
201- // ipfsNode: "" ,
202- // ipfsGateway: this.ipfsGateway ,
203- dappAddressOrENS : WEB3TELEGRAM_DAPP_ADDRESS ,
204- dappWhitelistAddress : WHITELIST_SMART_CONTRACT_ADDRESS . toLowerCase ( ) ,
211+ workerpoolAddressOrEns : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . prodWorkerpoolAddress ,
212+ dappAddressOrENS : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . dappAddress ,
213+ dappWhitelistAddress : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . whitelistSmartContract ,
214+ ipfsNode : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . ipfsUploadUrl ,
215+ ipfsGateway : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . ipfsGateway ,
205216 telegramContent : 'e2e telegram content for test' ,
206217 protectedData,
207218 } ) ;
@@ -211,8 +222,8 @@ describe('sendTelegram', () => {
211222 expect ( iexec . orderbook . fetchWorkerpoolOrderbook ) . toHaveBeenNthCalledWith (
212223 1 ,
213224 {
214- workerpool : TEST_CHAIN . prodWorkerpool ,
215- app : WEB3TELEGRAM_DAPP_ADDRESS . toLowerCase ( ) ,
225+ workerpool : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . prodWorkerpoolAddress ,
226+ app : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . dappAddress . toLowerCase ( ) ,
216227 dataset : protectedData ,
217228 requester : userAddress ,
218229 isRequesterStrict : false ,
@@ -224,8 +235,8 @@ describe('sendTelegram', () => {
224235 expect ( iexec . orderbook . fetchWorkerpoolOrderbook ) . toHaveBeenNthCalledWith (
225236 2 ,
226237 {
227- workerpool : TEST_CHAIN . prodWorkerpool ,
228- app : WHITELIST_SMART_CONTRACT_ADDRESS . toLowerCase ( ) ,
238+ workerpool : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . prodWorkerpoolAddress ,
239+ app : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . whitelistSmartContract . toLowerCase ( ) ,
229240 dataset : protectedData ,
230241 requester : userAddress ,
231242 isRequesterStrict : false ,
@@ -237,8 +248,8 @@ describe('sendTelegram', () => {
237248 expect ( iexec . orderbook . fetchWorkerpoolOrderbook ) . toHaveBeenNthCalledWith (
238249 2 ,
239250 {
240- workerpool : TEST_CHAIN . prodWorkerpool ,
241- app : WHITELIST_SMART_CONTRACT_ADDRESS . toLowerCase ( ) ,
251+ workerpool : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . prodWorkerpoolAddress ,
252+ app : CHAIN_CONFIG [ CHAIN_IDS . BELLECOUR ] . whitelistSmartContract . toLowerCase ( ) ,
242253 dataset : protectedData ,
243254 requester : userAddress ,
244255 isRequesterStrict : false ,
0 commit comments