import { FNS } from '..' import setup from '../tests/setup' import { FNSJSError } from '../utils/errors' let fnsInstance: FNS beforeAll(async () => { ;({ fnsInstance } = await setup()) }) describe('batch', () => { it('should batch calls together', async () => { const result = await fnsInstance.batch( fnsInstance.getText.batch('with-profile.ftm', 'description'), fnsInstance.getAddr.batch('with-profile.ftm'), fnsInstance.getName.batch('0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC'), ) expect(result).toBeTruthy() if (result) { expect(result[0]).toBe('Hello2') expect(result[1]).toBe('0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC') expect(result[2]).toMatchObject({ name: 'with-profile.ftm', match: true, }) } }) it('should batch a single call', async () => { const result = await fnsInstance.batch( fnsInstance.getText.batch('with-profile.ftm', 'description'), ) expect(result).toBeTruthy() if (result) { expect(result[0]).toBe('Hello2') } }) describe('errors', () => { beforeAll(() => { process.env.NEXT_PUBLIC_FNSJS_DEBUG = 'on' localStorage.setItem('fnsjs-debug', 'FNSJSSubgraphError') }) afterAll(() => { process.env.NEXT_PUBLIC_FNSJS_DEBUG = '' localStorage.removeItem('fnsjs-debug') }) it('should throw a single error if there is an indexing error', async () => { try { await fnsInstance.batch( fnsInstance.getText.batch('with-profile.ftm', 'description'), fnsInstance.getOwner.batch('expired.ftm', { skipGraph: false }), fnsInstance.getName.batch( '0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC', ), ) expect(true).toBe(false) } catch (e) { expect(e).toBeInstanceOf(FNSJSError) const error = e as FNSJSError expect(error.name).toBe('FNSJSSubgraphError') const result = error.data as any[] expect(result[0]).toBe('Hello2') expect(result[1]).toEqual({ expired: true, owner: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8', ownershipLevel: 'registrar', }) expect(result[2]).toMatchObject({ name: 'with-profile.ftm', match: true, }) } }) }) })