Skip to content

Commit

Permalink
chore: Map owner accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
fzavalia committed Mar 16, 2022
1 parent d19f51b commit 8875db1
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 66 deletions.
9 changes: 8 additions & 1 deletion src/NFT/NFT.router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,14 @@ describe('when getting a single nft', () => {
totalPrice: 'total_price',
},
name: 'name',
owner: 'owner',
owner: {
address: 'address',
config: 'config',
profileImageUrl: 'profile_image_url',
user: {
username: 'username',
},
},
tokenId: 'token_id',
traits: [
{
Expand Down
113 changes: 50 additions & 63 deletions src/NFT/NFT.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { env } from 'decentraland-commons'
import fetch, { Response } from 'node-fetch'
import { NFTService } from './NFT.service'
import { NFT } from './NFT.types'

jest.mock('node-fetch')
jest.mock('decentraland-commons')
Expand All @@ -14,6 +15,7 @@ const mockApiKey = 'https://some-url.com/v1'
let service: NFTService
let requestInit: RequestInit
let mockExternalNFT: any
let mockMappedExternalNFT: NFT

beforeEach(() => {
mockEnv.get.mockReturnValueOnce(mockUrl)
Expand All @@ -34,7 +36,14 @@ beforeEach(() => {
background_color: 'background_color',
name: 'name',
external_link: 'external_link',
owner: 'owner',
owner: {
address: 'address',
config: 'config',
profile_image_url: 'profile_image_url',
user: {
username: 'username',
},
},
traits: [
{
display_type: 'display_type',
Expand All @@ -59,6 +68,44 @@ beforeEach(() => {
},
}

mockMappedExternalNFT = {
backgroundColor: 'background_color',
contract: {
description: 'description',
externalLink: 'external_link',
imageUrl: 'image_url',
name: 'name',
symbol: 'symbol',
},
externalLink: 'external_link',
imageUrl: 'image_url',
lastSale: {
eventType: 'event_type',
paymentToken: {
symbol: 'symbol',
},
quantity: 'quantity',
totalPrice: 'total_price',
},
name: 'name',
owner: {
address: 'address',
config: 'config',
profileImageUrl: 'profile_image_url',
user: {
username: 'username',
},
},
tokenId: 'token_id',
traits: [
{
displayType: 'display_type',
type: 'trait_type',
value: 'value',
},
],
}

jest.clearAllMocks()
})

Expand Down Expand Up @@ -161,38 +208,7 @@ describe('when getting a list of nfts', () => {

expect(data).toEqual({
next: 'next',
nfts: [
{
backgroundColor: 'background_color',
contract: {
description: 'description',
externalLink: 'external_link',
imageUrl: 'image_url',
name: 'name',
symbol: 'symbol',
},
externalLink: 'external_link',
imageUrl: 'image_url',
lastSale: {
eventType: 'event_type',
paymentToken: {
symbol: 'symbol',
},
quantity: 'quantity',
totalPrice: 'total_price',
},
name: 'name',
owner: 'owner',
tokenId: 'token_id',
traits: [
{
displayType: 'display_type',
type: 'trait_type',
value: 'value',
},
],
},
],
nfts: [mockMappedExternalNFT],
previous: 'previous',
})
})
Expand Down Expand Up @@ -238,35 +254,6 @@ describe('when getting an nft', () => {
tokenId: 'tokenId',
})

expect(nft).toEqual({
backgroundColor: 'background_color',
contract: {
description: 'description',
externalLink: 'external_link',
imageUrl: 'image_url',
name: 'name',
symbol: 'symbol',
},
externalLink: 'external_link',
imageUrl: 'image_url',
lastSale: {
eventType: 'event_type',
paymentToken: {
symbol: 'symbol',
},
quantity: 'quantity',
totalPrice: 'total_price',
},
name: 'name',
owner: 'owner',
tokenId: 'token_id',
traits: [
{
displayType: 'display_type',
type: 'trait_type',
value: 'value',
},
],
})
expect(nft).toEqual(mockMappedExternalNFT)
})
})
9 changes: 8 additions & 1 deletion src/NFT/NFT.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ export class NFTService {
}
}

const owner: NFT['owner'] = {
address: nft.owner.address,
config: nft.owner.config,
profileImageUrl: nft.owner.profile_image_url,
user: nft.owner.user,
}

const traits: NFT['traits'] = (nft.traits as any[]).map((trait) => ({
displayType: trait.display_type,
type: trait.trait_type,
Expand All @@ -152,7 +159,7 @@ export class NFTService {
backgroundColor: nft.background_color,
name: nft.name,
externalLink: nft.external_link,
owner: nft.owner,
owner,
traits,
lastSale,
contract,
Expand Down
9 changes: 8 additions & 1 deletion src/NFT/NFT.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ export type NFT = {
backgroundColor: string
name: string
externalLink: string
owner: string
owner: {
user: {
username: string
}
profileImageUrl: string
address: string
config: string
}
contract: {
name: string
symbol: string
Expand Down

0 comments on commit 8875db1

Please sign in to comment.