From 2f219cc60175bbf8713082ee2ecf8e0d146df818 Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Wed, 11 Dec 2024 15:48:57 +0100 Subject: [PATCH 1/3] fix: missing emote body_shapes --- src/adapters/items/index.ts | 4 ++-- src/ports/items/queries.ts | 3 ++- src/ports/items/types.ts | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/adapters/items/index.ts b/src/adapters/items/index.ts index 919b250..45f241c 100644 --- a/src/adapters/items/index.ts +++ b/src/adapters/items/index.ts @@ -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, @@ -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, diff --git a/src/ports/items/queries.ts b/src/ports/items/queries.ts index 70d7a79..b6d070a 100644 --- a/src/ports/items/queries.ts +++ b/src/ports/items/queries.ts @@ -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, diff --git a/src/ports/items/types.ts b/src/ports/items/types.ts index 1d26c87..5953d5f 100644 --- a/src/ports/items/types.ts +++ b/src/ports/items/types.ts @@ -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 From fa6c636e69d2a6a0df85137b2c6936e80a82f718 Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Wed, 11 Dec 2024 15:52:55 +0100 Subject: [PATCH 2/3] fix: tests --- test/unit/items-adapters.spec.ts | 16 ++++++++-------- test/unit/trades-utils.spec.ts | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/unit/items-adapters.spec.ts b/test/unit/items-adapters.spec.ts index e7f0ff3..0472053 100644 --- a/test/unit/items-adapters.spec.ts +++ b/test/unit/items-adapters.spec.ts @@ -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, @@ -79,7 +79,7 @@ describe('fromDBItemToItem', () => { dbItem = { ...dbItem, item_type: ItemType.WEARABLE_V1, - body_shapes: [BodyShape.MALE], + wearable_body_shapes: [BodyShape.MALE], emote_category: undefined, wearable_category: WearableCategory.BODY_SHAPE, description: 'A wearable item', @@ -110,7 +110,7 @@ describe('fromDBItemToItem', () => { tradeExpiresAt: dbItem.trade_expires_at?.getTime(), data: { wearable: { - bodyShapes: dbItem.body_shapes, + bodyShapes: dbItem.wearable_body_shapes, category: dbItem.wearable_category as WearableCategory, description: dbItem.description || '', rarity: dbItem.rarity, @@ -151,7 +151,7 @@ describe('fromDBItemToItem', () => { tradeExpiresAt: dbItem.trade_expires_at?.getTime(), data: { emote: { - bodyShapes: dbItem.body_shapes, + bodyShapes: dbItem.wearable_body_shapes, category: dbItem.emote_category as EmoteCategory, description: dbItem.description || '', rarity: dbItem.rarity, @@ -174,7 +174,7 @@ describe('getDataFromDBItem', () => { dbItem = { ...dbItem, item_type: ItemType.WEARABLE_V1, - body_shapes: [BodyShape.FEMALE], + wearable_body_shapes: [BodyShape.FEMALE], wearable_category: WearableCategory.UPPER_BODY, description: 'A wearable item', rarity: Rarity.RARE, @@ -183,7 +183,7 @@ describe('getDataFromDBItem', () => { const result = getDataFromDBItem(dbItem) expect(result).toEqual({ wearable: { - bodyShapes: dbItem.body_shapes, + bodyShapes: dbItem.wearable_body_shapes, category: dbItem.wearable_category, description: dbItem.description, rarity: dbItem.rarity, @@ -196,7 +196,7 @@ describe('getDataFromDBItem', () => { dbItem = { ...dbItem, 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, @@ -207,7 +207,7 @@ describe('getDataFromDBItem', () => { const result = getDataFromDBItem(dbItem) expect(result).toEqual({ emote: { - bodyShapes: dbItem.body_shapes, + bodyShapes: dbItem.wearable_body_shapes, category: dbItem.emote_category, description: dbItem.description, rarity: dbItem.rarity, diff --git a/test/unit/trades-utils.spec.ts b/test/unit/trades-utils.spec.ts index c4e60a7..fd7478f 100644 --- a/test/unit/trades-utils.spec.ts +++ b/test/unit/trades-utils.spec.ts @@ -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, From aee2c5120fe9788b4bcdecc0c1257f80400e6bf3 Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Wed, 11 Dec 2024 16:02:46 +0100 Subject: [PATCH 3/3] fix: tests --- test/unit/items-adapters.spec.ts | 285 +++++++++++++++++-------------- 1 file changed, 159 insertions(+), 126 deletions(-) diff --git a/test/unit/items-adapters.spec.ts b/test/unit/items-adapters.spec.ts index 0472053..674e0d4 100644 --- a/test/unit/items-adapters.spec.ts +++ b/test/unit/items-adapters.spec.ts @@ -75,146 +75,179 @@ describe('getCategoryFromDBItem', () => { }) describe('fromDBItemToItem', () => { - it('should convert DBItem to Item for wearable items', () => { - 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 - } - - 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.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 + 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.wearable_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, - wearable_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.wearable_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, - wearable_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.wearable_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 + } + }) + }) }) })