diff --git a/src/lib/getDataFromExternalSources.test.ts b/src/lib/getDataFromExternalSources.test.ts index 2c3992e9..b2d710e2 100644 --- a/src/lib/getDataFromExternalSources.test.ts +++ b/src/lib/getDataFromExternalSources.test.ts @@ -15,11 +15,13 @@ /* eslint-disable no-unused-expressions */ import { expect } from 'chai'; +import * as sinon from 'sinon'; import { ERC725JSONSchema } from '../types/ERC725JSONSchema'; import { getDataFromExternalSources } from './getDataFromExternalSources'; import { DecodeDataOutput } from '../types/decodeData'; +import { keccak256 } from 'web3-utils'; const IPFS_GATEWAY_MOCK = 'https://mock-ipfs.mock/ipfs/'; @@ -62,13 +64,15 @@ describe('getDataFromExternalSources', () => { valueContent: 'VerifiableURI', }; + const jsonResult = { LSP3Profile: { name: 'Test', description: 'Cool' } }; + const dataFromChain: DecodeDataOutput[] = [ { name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', value: { verification: { - data: '0xdb864ed42104cee179785036cb4ff1183ebc57e5532ae766ad8533fa48acfbb3', + data: keccak256(JSON.stringify(jsonResult)), method: 'keccak256(utf8)', }, url: 'ipfs://QmdMGUxuQsm1U9Qs8oJSn5PfY4B1apGG75YBRxQPybtRVm', @@ -76,110 +80,25 @@ describe('getDataFromExternalSources', () => { }, ]; - const result = await getDataFromExternalSources( - [schema], - dataFromChain, - 'https://api.universalprofile.cloud/ipfs/', - ); + const fetchStub = sinon.stub(global, 'fetch'); + try { + fetchStub.onCall(0).returns( + Promise.resolve( + new Response(JSON.stringify(jsonResult), { + headers: { 'content-type': 'application/json' }, + }), + ), + ); - expect(result).to.deep.equal([ - { - name: 'LSP3Profile', - key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', - value: { - LSP3Profile: { - name: 'test', - description: '', - tags: ['profile'], - links: [], - profileImage: [ - { - width: 1024, - height: 709, - verification: { - method: 'keccak256(bytes)', - data: '0x6a0a28680d65b69f5696859be7e0fcebbbcf0df47f1f767926de35402c7d525c', - }, - url: 'ipfs://QmVUYyft3j2JVrG4RzDe1Qx7K5gNtJGFhrExHQFeiRXz1C', - }, - { - width: 640, - height: 443, - verification: { - method: 'keccak256(bytes)', - data: '0x7cd399f2a2552aa5cd21b1584a98db3efa39c701c311c38a60c680343cfa6d82', - }, - url: 'ipfs://QmeU8FUZC9F1qMYmcWyBhfGqaf7g3kLzGb4xBpoCfyVLZW', - }, - { - width: 320, - height: 221, - verification: { - method: 'keccak256(bytes)', - data: '0x272d2e57ae1710ac7c5e3d1c9f9d24f48954ad43d0e821f8bd041a4734e309a5', - }, - url: 'ipfs://QmdViKPWYhZv7u86z7HBTgAkTAwEkNSRi1VkYEU8K5yUsH', - }, - { - width: 180, - height: 124, - verification: { - method: 'keccak256(bytes)', - data: '0x1a464ff7e0eff05da98ed309a25195d8666b6211a5dfa2214865c3fd50ead810', - }, - url: 'ipfs://QmXZUCW6MqCNfYJEFsi54Vkj6PRrUoiPjzTuA2mWtas3RJ', - }, - ], - backgroundImage: [ - { - width: 1800, - height: 1012, - verification: { - method: 'keccak256(bytes)', - data: '0x3f6be73b35d348fb8f0b87a47d8c8b6b9db8858ee044cb13734cdfe5d28031d8', - }, - url: 'ipfs://QmfLCPmL31f31RRB4R7yoTg3Hsk5PjrWyS3ZaaYyhRPT4n', - }, - { - width: 1024, - height: 576, - verification: { - method: 'keccak256(bytes)', - data: '0xcb57ed802bcd7dc4964395a609b3a0f557c5f46a602b28b058b9587bb77bb54f', - }, - url: 'ipfs://QmPoPEaoGNVYhiMTwBWp6XzLPRXyuLjZWnuMobdCbfqsU9', - }, - { - width: 640, - height: 360, - verification: { - method: 'keccak256(bytes)', - data: '0x57e8039288c3e1a7f891c839e03805984ab36524b710656f072492c1c8ebd967', - }, - url: 'ipfs://QmU3pDA4eDNPMeARsJXxKaZsMC5MgFLgzGQccnydbU9WLV', - }, - { - width: 320, - height: 180, - verification: { - method: 'keccak256(bytes)', - data: '0x2bebf9baac33d719bbd3b481b1af468701409ad7578f84be04e8f7563d5a1509', - }, - url: 'ipfs://QmcKtenPsRvrqZJQ1gLCdUFkex4i9DGp7RFvucb9nbkzsz', - }, - { - width: 180, - height: 101, - verification: { - method: 'keccak256(bytes)', - data: '0xe32154c03c892d7c41c91220b8757ec5b7847eb2dd91413f7238b0c25f55b475', - }, - url: 'ipfs://QmU7ueJ467E9HRahaqQmSPhvkTkMhCLXRxV45P4kmMk6vm', - }, - ], - }, - }, - }, - ]); + const [{ value: result }] = await getDataFromExternalSources( + [schema], + dataFromChain, + IPFS_GATEWAY_MOCK, + ); + + expect(result).to.deep.equal(jsonResult); + } finally { + fetchStub.restore(); + } }); });