generated from well-known-components/template-server
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * wip * fix * fix * chore: emotes (#122) * chore: add emotes just duplicated all logic from wearables * chore: abstraction in definitions-fetcher * chore: abstract wearablesFetcher and emotesFetcher in itemsFetcher * chore: fix tests * fix: tests * chore: item-fetcher queries record * chore: 3rd party * chore: cleanup code * test: try new approach * test: cover third party wearables endpoint * minor fix --------- Co-authored-by: Hugo Arregui <[email protected]> Co-authored-by: Alejo Thomas Ortega <[email protected]>
- Loading branch information
1 parent
dd14300
commit cb0867d
Showing
4 changed files
with
402 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
test/integration/third-party-wearables-handler/with-multiple-providers.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { testWithComponents } from '../../components' | ||
import { generateThirdPartyWearables, getThirdPartyProviders } from '../../data/wearables' | ||
import Wallet from 'ethereumjs-wallet' | ||
import { createTheGraphComponentMock } from '../../mocks/the-graph-mock' | ||
|
||
testWithComponents(() => { | ||
const theGraphMock = createTheGraphComponentMock() | ||
const resolverResponse = getThirdPartyProviders() | ||
|
||
theGraphMock.thirdPartyRegistrySubgraph.query = jest.fn().mockResolvedValue(resolverResponse) | ||
return { | ||
theGraphComponent: theGraphMock | ||
} | ||
})('third-party-wearables-handler: GET /users/:address/third-party-wearables with multiple providers should', function ({ components }) { | ||
it('return wearables when found on a single provider', async () => { | ||
const { localFetch, fetch } = components | ||
const wearables = generateThirdPartyWearables(2) | ||
|
||
fetch.fetch = jest.fn().mockImplementation((url) => { | ||
if (url.includes('babydoge')) { | ||
return({ok: true, json: () => ({ | ||
assets: wearables | ||
})}) | ||
} else { | ||
return({ ok: true, json: () => ( { assets: [] } ) }) | ||
} | ||
}) | ||
|
||
const r = await localFetch.fetch(`/users/${Wallet.generate().getAddressString()}/third-party-wearables`) | ||
|
||
expect(r.status).toBe(200) | ||
expect(await r.json()).toEqual({ | ||
elements: convertToDataModel(wearables), | ||
totalAmount: 2, | ||
pageNum: 1, | ||
pageSize: 100 | ||
}) | ||
}) | ||
|
||
it('return wearables when found on multiple providers', async () => { | ||
const { localFetch, fetch } = components | ||
const wearables = generateThirdPartyWearables(6) | ||
|
||
fetch.fetch = jest.fn().mockImplementation((url) => { | ||
if (url.includes('babydoge')) { | ||
return({ok: true, json: () => ({ | ||
assets: wearables.slice(0, 2) | ||
})}) | ||
} | ||
|
||
if (url.includes('cryptoavatars')) { | ||
return({ok: true, json: () => ({ | ||
assets: wearables.slice(2, 4) | ||
})}) | ||
} | ||
|
||
if (url.includes('unxd')) { | ||
return({ok: true, json: () => ({ | ||
assets: wearables.slice(4, 6) | ||
})}) | ||
} | ||
}) | ||
|
||
const r = await localFetch.fetch(`/users/${Wallet.generate().getAddressString()}/third-party-wearables`) | ||
|
||
expect(r.status).toBe(200) | ||
expect(await r.json()).toEqual({ | ||
elements: convertToDataModel(wearables), | ||
totalAmount: 6, | ||
pageNum: 1, | ||
pageSize: 100 | ||
}) | ||
}) | ||
}) | ||
|
||
function convertToDataModel(wearables, definitions = undefined) { | ||
return wearables.map(wearable => { | ||
const definition = definitions?.find(def => def.id === wearable.urn.decentraland) | ||
const definitionData = definition?.metadata?.data | ||
|
||
return { | ||
amount: wearable.amount, | ||
individualData: [ | ||
{ | ||
id: wearable.id | ||
} | ||
], | ||
urn: wearable.urn.decentraland, | ||
...(definitions ? { | ||
definition: definitionData && { | ||
id: wearable.urn.decentraland, | ||
data: { | ||
...definitionData, | ||
representations: [{ contents: [{ key: definitionData.representations[0]?.contents[0] }] }] | ||
} | ||
} | ||
} : {}) | ||
} | ||
}) | ||
} |
Oops, something went wrong.