Skip to content

Commit

Permalink
Merge pull request #206 from decentraland/fix/emote-body-shapes
Browse files Browse the repository at this point in the history
fix: missing emote body_shapes
  • Loading branch information
juanmahidalgo authored Dec 11, 2024
2 parents 0e333b3 + aee2c51 commit 557cde9
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 132 deletions.
4 changes: 2 additions & 2 deletions src/adapters/items/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function getDataFromDBItem(dbItem: DBItem): Item['data'] {
) {
return {
wearable: {
bodyShapes: dbItem.body_shapes,
bodyShapes: dbItem.wearable_body_shapes || [], // if it's wearable, the field will be defined
category: dbItem.wearable_category as WearableCategory,
description: dbItem.description || '',
rarity: dbItem.rarity,
Expand All @@ -33,7 +33,7 @@ export function getDataFromDBItem(dbItem: DBItem): Item['data'] {

return {
emote: {
bodyShapes: dbItem.body_shapes,
bodyShapes: dbItem.emote_body_shapes || [], // if it's emote, the field will be defined
category: dbItem.emote_category as EmoteCategory,
description: dbItem.description || '',
rarity: dbItem.rarity,
Expand Down
3 changes: 2 additions & 1 deletion src/ports/items/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export function getItemsQuery(filters: ItemFilters = {}) {
item.search_is_store_minter,
trades.id as trade_id,
coalesce(wearable.name, emote.name) as name,
wearable.body_shapes,
wearable.body_shapes as wearable_body_shapes,
emote.body_shapes as emote_body_shapes,
wearable.category as wearable_category,
emote.category as emote_category,
item.item_type,
Expand Down
3 changes: 2 additions & 1 deletion src/ports/items/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export type DBItem = {
sold_at: number
urn: string
name: string
body_shapes: BodyShape[]
wearable_body_shapes?: BodyShape[]
emote_body_shapes?: BodyShape[]
description?: string
isSmart?: boolean
loop?: boolean
Expand Down
287 changes: 160 additions & 127 deletions test/unit/items-adapters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ beforeEach(() => {
trade_id: '12',
wearable_category: WearableCategory.BODY_SHAPE,
item_type: ItemType.EMOTE_V1,
body_shapes: [BodyShape.MALE],
wearable_body_shapes: [BodyShape.MALE],
emote_category: EmoteCategory.DANCE,
description: 'An emote item',
rarity: Rarity.COMMON,
Expand Down Expand Up @@ -75,146 +75,179 @@ describe('getCategoryFromDBItem', () => {
})

describe('fromDBItemToItem', () => {
it('should convert DBItem to Item for wearable items', () => {
dbItem = {
...dbItem,
item_type: ItemType.WEARABLE_V1,
body_shapes: [BodyShape.MALE],
emote_category: undefined,
wearable_category: WearableCategory.BODY_SHAPE,
description: 'A wearable item',
rarity: Rarity.COMMON
}

const result = fromDBItemToItem(dbItem)
describe('and it is a wearable', () => {
beforeEach(() => {
dbItem = {
...dbItem,
item_type: ItemType.WEARABLE_V1,
wearable_body_shapes: [BodyShape.MALE],
emote_category: undefined,
wearable_category: WearableCategory.BODY_SHAPE,
description: 'A wearable item',
rarity: Rarity.COMMON
}
})
it('should convert DBItem to Item for wearable items', () => {
const result = fromDBItemToItem(dbItem)

expect(result).toEqual({
id: dbItem.id,
name: dbItem.name,
thumbnail: dbItem.image,
url: dbItem.uri,
category: NFTCategory.WEARABLE,
contractAddress: dbItem.contract_address,
itemId: dbItem.item_id,
rarity: dbItem.rarity,
price: dbItem.trade_price,
available: dbItem.available,
isOnSale: false,
creator: dbItem.creator,
beneficiary: dbItem.trade_beneficiary,
createdAt: dbItem.created_at,
updatedAt: dbItem.updated_at,
reviewedAt: dbItem.reviewed_at,
soldAt: dbItem.sold_at,
tradeId: dbItem.trade_id,
tradeExpiresAt: dbItem.trade_expires_at?.getTime(),
data: {
wearable: {
bodyShapes: dbItem.body_shapes,
category: dbItem.wearable_category as WearableCategory,
description: dbItem.description || '',
rarity: dbItem.rarity,
isSmart: dbItem.item_type === ItemType.SMART_WEARABLE_V1
}
},
network: getNetwork(dbItem.network),
chainId: getNetworkChainId(dbItem.network),
urn: dbItem.urn,
firstListedAt: dbItem.first_listed_at?.getTime(),
picks: { count: 0 },
utility: dbItem.utility
expect(result).toEqual({
id: dbItem.id,
name: dbItem.name,
thumbnail: dbItem.image,
url: dbItem.uri,
category: NFTCategory.WEARABLE,
contractAddress: dbItem.contract_address,
itemId: dbItem.item_id,
rarity: dbItem.rarity,
price: dbItem.trade_price,
available: dbItem.available,
isOnSale: false,
creator: dbItem.creator,
beneficiary: dbItem.trade_beneficiary,
createdAt: dbItem.created_at,
updatedAt: dbItem.updated_at,
reviewedAt: dbItem.reviewed_at,
soldAt: dbItem.sold_at,
tradeId: dbItem.trade_id,
tradeExpiresAt: dbItem.trade_expires_at?.getTime(),
data: {
wearable: {
bodyShapes: dbItem.wearable_body_shapes,
category: dbItem.wearable_category as WearableCategory,
description: dbItem.description || '',
rarity: dbItem.rarity,
isSmart: dbItem.item_type === ItemType.SMART_WEARABLE_V1
}
},
network: getNetwork(dbItem.network),
chainId: getNetworkChainId(dbItem.network),
urn: dbItem.urn,
firstListedAt: dbItem.first_listed_at?.getTime(),
picks: { count: 0 },
utility: dbItem.utility
})
})
})

it('should convert DBItem to Item for emote items', () => {
const result = fromDBItemToItem(dbItem)
describe('and it is an emote', () => {
beforeEach(() => {
dbItem = {
...dbItem,
item_type: ItemType.EMOTE_V1,
emote_body_shapes: [BodyShape.MALE]
}
})

expect(result).toEqual({
id: dbItem.id,
name: dbItem.name,
thumbnail: dbItem.image,
url: dbItem.uri,
category: NFTCategory.EMOTE,
contractAddress: dbItem.contract_address,
itemId: dbItem.item_id,
rarity: dbItem.rarity,
price: dbItem.trade_price,
available: dbItem.available,
isOnSale: false,
tradeId: dbItem.trade_id,
creator: dbItem.creator,
beneficiary: dbItem.trade_beneficiary,
createdAt: dbItem.created_at,
updatedAt: dbItem.updated_at,
reviewedAt: dbItem.reviewed_at,
soldAt: dbItem.sold_at,
tradeExpiresAt: dbItem.trade_expires_at?.getTime(),
data: {
emote: {
bodyShapes: dbItem.body_shapes,
category: dbItem.emote_category as EmoteCategory,
description: dbItem.description || '',
rarity: dbItem.rarity,
loop: dbItem.loop || false,
hasSound: dbItem.has_sound || false,
hasGeometry: dbItem.has_geometry || false
}
},
network: getNetwork(dbItem.network),
chainId: getNetworkChainId(dbItem.network),
urn: dbItem.urn,
firstListedAt: dbItem.first_listed_at?.getTime(),
picks: { count: 0 },
utility: dbItem.utility
it('should convert DBItem to Item for emote items', () => {
const result = fromDBItemToItem(dbItem)

expect(result).toEqual({
id: dbItem.id,
name: dbItem.name,
thumbnail: dbItem.image,
url: dbItem.uri,
category: NFTCategory.EMOTE,
contractAddress: dbItem.contract_address,
itemId: dbItem.item_id,
rarity: dbItem.rarity,
price: dbItem.trade_price,
available: dbItem.available,
isOnSale: false,
tradeId: dbItem.trade_id,
creator: dbItem.creator,
beneficiary: dbItem.trade_beneficiary,
createdAt: dbItem.created_at,
updatedAt: dbItem.updated_at,
reviewedAt: dbItem.reviewed_at,
soldAt: dbItem.sold_at,
tradeExpiresAt: dbItem.trade_expires_at?.getTime(),
data: {
emote: {
bodyShapes: dbItem.emote_body_shapes,
category: dbItem.emote_category as EmoteCategory,
description: dbItem.description || '',
rarity: dbItem.rarity,
loop: dbItem.loop || false,
hasSound: dbItem.has_sound || false,
hasGeometry: dbItem.has_geometry || false
}
},
network: getNetwork(dbItem.network),
chainId: getNetworkChainId(dbItem.network),
urn: dbItem.urn,
firstListedAt: dbItem.first_listed_at?.getTime(),
picks: { count: 0 },
utility: dbItem.utility
})
})
})
})
describe('getDataFromDBItem', () => {
it('should return wearable data for wearable items', () => {
dbItem = {
...dbItem,
item_type: ItemType.WEARABLE_V1,
body_shapes: [BodyShape.FEMALE],
wearable_category: WearableCategory.UPPER_BODY,
description: 'A wearable item',
rarity: Rarity.RARE,
isSmart: false
}
const result = getDataFromDBItem(dbItem)
expect(result).toEqual({
wearable: {
bodyShapes: dbItem.body_shapes,
category: dbItem.wearable_category,
description: dbItem.description,
rarity: dbItem.rarity,
isSmart: dbItem.isSmart
describe('and is a wearable', () => {
beforeEach(() => {
dbItem = {
...dbItem,
item_type: ItemType.WEARABLE_V1,
wearable_body_shapes: [BodyShape.FEMALE],
wearable_category: WearableCategory.UPPER_BODY,
description: 'A wearable item',
rarity: Rarity.RARE,
isSmart: false
}
})
it('should return wearable data for wearable items', () => {
const result = getDataFromDBItem(dbItem)
expect(result).toEqual({
wearable: {
bodyShapes: dbItem.wearable_body_shapes,
category: dbItem.wearable_category,
description: dbItem.description,
rarity: dbItem.rarity,
isSmart: dbItem.isSmart
}
})
})
})

it('should return emote data for emote items', () => {
dbItem = {
...dbItem,
item_type: ItemType.EMOTE_V1,
body_shapes: [BodyShape.MALE],
emote_category: EmoteCategory.DANCE,
description: 'An emote item',
rarity: Rarity.COMMON,
loop: true,
has_sound: true,
has_geometry: false
}
const result = getDataFromDBItem(dbItem)
expect(result).toEqual({
emote: {
bodyShapes: dbItem.body_shapes,
category: dbItem.emote_category,
description: dbItem.description,
rarity: dbItem.rarity,
loop: dbItem.loop,
hasSound: dbItem.has_sound,
hasGeometry: dbItem.has_geometry
describe('and it is an emote', () => {
beforeEach(() => {
dbItem = {
...dbItem,
item_type: ItemType.EMOTE_V1,
emote_body_shapes: [BodyShape.MALE],
emote_category: EmoteCategory.DANCE,
description: 'An emote item',
rarity: Rarity.COMMON,
loop: true,
has_sound: true,
has_geometry: false
}
})

it('should return emote data for emote items', () => {
dbItem = {
...dbItem,
item_type: ItemType.EMOTE_V1,
emote_body_shapes: [BodyShape.MALE],
emote_category: EmoteCategory.DANCE,
description: 'An emote item',
rarity: Rarity.COMMON,
loop: true,
has_sound: true,
has_geometry: false
}
const result = getDataFromDBItem(dbItem)
expect(result).toEqual({
emote: {
bodyShapes: dbItem.emote_body_shapes,
category: dbItem.emote_category,
description: dbItem.description,
rarity: dbItem.rarity,
loop: dbItem.loop,
hasSound: dbItem.has_sound,
hasGeometry: dbItem.has_geometry
}
})
})
})
})
2 changes: 1 addition & 1 deletion test/unit/trades-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe('when calling getNotificationEventForTrade function', () => {
}
dbItem = {
count: 1,
body_shapes: [],
wearable_body_shapes: [],
first_listed_at: new Date(),
search_is_store_minter: false,
network: SquidNetwork.ETHEREUM,
Expand Down

0 comments on commit 557cde9

Please sign in to comment.