|
1 |
| -import { EmotePlayMode, GenderFilterOption } from '@dcl/schemas'; |
2 |
| -import { getItemsQuery } from './utils'; |
| 1 | +import { |
| 2 | + ChainId, |
| 3 | + EmoteCategory, |
| 4 | + EmotePlayMode, |
| 5 | + GenderFilterOption, |
| 6 | + ItemSortBy, |
| 7 | + Network, |
| 8 | + Rarity, |
| 9 | +} from '@dcl/schemas' |
| 10 | +import { ItemFragment, FragmentItemType } from './types' |
| 11 | +import { fromItemFragment, getItemsQuery } from './utils' |
3 | 12 |
|
4 | 13 | describe("#getItemsQuery", () => {
|
5 | 14 | describe("when minPrice is defined", () => {
|
@@ -92,4 +101,96 @@ describe("#getItemsQuery", () => {
|
92 | 101 | )
|
93 | 102 | })
|
94 | 103 | })
|
95 |
| -}); |
| 104 | + |
| 105 | + describe('when sortBy is ItemSortBy.RECENTLY_LISTED', () => { |
| 106 | + let query: string |
| 107 | + |
| 108 | + beforeEach(() => { |
| 109 | + query = getItemsQuery({ |
| 110 | + sortBy: ItemSortBy.RECENTLY_LISTED, |
| 111 | + }) |
| 112 | + }) |
| 113 | + |
| 114 | + it('should add firstListedAt_not: null where filter', () => { |
| 115 | + expect(query.includes('firstListedAt_not: null')).toBeTruthy() |
| 116 | + }) |
| 117 | + |
| 118 | + it('should add firstListedAt as orderBy', () => { |
| 119 | + expect(query.includes('orderBy: firstListedAt')).toBeTruthy() |
| 120 | + }) |
| 121 | + |
| 122 | + it('should add desc as orderDirection', () => { |
| 123 | + expect(query.includes('orderDirection: desc')).toBeTruthy() |
| 124 | + }) |
| 125 | + }) |
| 126 | +}) |
| 127 | + |
| 128 | +describe('#fromItemFragment', () => { |
| 129 | + let itemFragment: ItemFragment |
| 130 | + |
| 131 | + beforeEach(() => { |
| 132 | + itemFragment = { |
| 133 | + id: 'id', |
| 134 | + price: 'price', |
| 135 | + blockchainId: 'blockchainId', |
| 136 | + image: 'image', |
| 137 | + rarity: Rarity.COMMON, |
| 138 | + available: 'available', |
| 139 | + itemType: FragmentItemType.EMOTE_V1, |
| 140 | + collection: { |
| 141 | + id: 'collection', |
| 142 | + creator: 'creator', |
| 143 | + }, |
| 144 | + metadata: { |
| 145 | + wearable: null, |
| 146 | + emote: { |
| 147 | + category: EmoteCategory.DANCE, |
| 148 | + description: 'description', |
| 149 | + loop: false, |
| 150 | + name: 'name', |
| 151 | + }, |
| 152 | + }, |
| 153 | + searchWearableBodyShapes: null, |
| 154 | + searchEmoteBodyShapes: null, |
| 155 | + searchIsStoreMinter: false, |
| 156 | + createdAt: '100', |
| 157 | + updatedAt: '100', |
| 158 | + reviewedAt: '100', |
| 159 | + soldAt: '100', |
| 160 | + beneficiary: 'beneficiary', |
| 161 | + firstListedAt: null, |
| 162 | + } |
| 163 | + }) |
| 164 | + |
| 165 | + describe('when fragment firstListedAt is null', () => { |
| 166 | + beforeEach(() => { |
| 167 | + itemFragment.firstListedAt = null |
| 168 | + }) |
| 169 | + |
| 170 | + it('should return an Item with firstListedAt as null', () => { |
| 171 | + const collection = fromItemFragment( |
| 172 | + itemFragment, |
| 173 | + Network.MATIC, |
| 174 | + ChainId.MATIC_MUMBAI |
| 175 | + ) |
| 176 | + |
| 177 | + expect(collection.firstListedAt).toBeNull() |
| 178 | + }) |
| 179 | + }) |
| 180 | + |
| 181 | + describe('when fragment firstListedAt is "100"', () => { |
| 182 | + beforeEach(() => { |
| 183 | + itemFragment.firstListedAt = '100' |
| 184 | + }) |
| 185 | + |
| 186 | + it('should return a Collection with firstListedAt as 100000', () => { |
| 187 | + const collection = fromItemFragment( |
| 188 | + itemFragment, |
| 189 | + Network.MATIC, |
| 190 | + ChainId.MATIC_MUMBAI |
| 191 | + ) |
| 192 | + |
| 193 | + expect(collection.firstListedAt).toBe(100000) |
| 194 | + }) |
| 195 | + }) |
| 196 | +}) |
0 commit comments