import { FNS } from '..' import setup from '../tests/setup' import { FNSJSError } from '../utils/errors' import { ReturnData } from './getHistory' let fnsInstance: FNS let revert: Awaited>['revert'] beforeAll(async () => { ;({ fnsInstance, revert } = await setup()) }) afterAll(async () => { await revert() }) describe('getHistory', () => { it('should return null for a non-existent name', async () => { const result = await fnsInstance.getHistory('test123123cool.ftm') expect(result).toBeUndefined() }) it('should return the history of a name', async () => { const result = await fnsInstance.getHistory('with-profile.ftm') expect(result).toBeTruthy() if (result) { expect(result).toHaveProperty('domain') expect(result).toHaveProperty('resolver') expect(result).toHaveProperty('registration') } }) it('should return the history of a wrapped name', async () => { const result = await fnsInstance.getHistory('wrapped.ftm') expect(result).toBeTruthy() if (result) { expect(result).toHaveProperty('domain') expect(result).toHaveProperty('resolver') expect(result).toHaveProperty('registration') } }) it('should return the history of a subname', async () => { const result = await fnsInstance.getHistory( 'test.wrapped-with-subnames.ftm', ) expect(result).toBeTruthy() if (result) { expect(result).toHaveProperty('domain') expect(result).toHaveProperty('resolver') expect(result).not.toHaveProperty('registration') } }) 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 an error with no data', async () => { try { await fnsInstance.getHistory('with-profile.ftm') expect(true).toBeFalsy() } catch (e) { expect(e).toBeInstanceOf(FNSJSError) const error = e as FNSJSError expect(error.data).toBeUndefined() } }) }) })