Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove old third party items fetch #475

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 1 addition & 29 deletions spec/mocks/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { constants } from 'ethers'
import { Rarity, ThirdPartyWearable } from '@dcl/schemas'
import { v4 as uuidv4 } from 'uuid'
import {
ItemFragment,
ThirdPartyItemFragment,
ThirdPartyItemMetadataType,
ItemFragment
} from '../../src/ethereum/api/fragments'
import { Bridge } from '../../src/ethereum/api/Bridge'
import {
Expand Down Expand Up @@ -188,32 +186,6 @@ export const itemFragmentMock = {
contentHash: '',
}

export const thirdPartyItemFragmentMock: ThirdPartyItemFragment = {
urn: buildTPItemURN(
dbTPCollectionMock.third_party_id,
dbTPCollectionMock.urn_suffix,
dbTPItemMock.urn_suffix
),
blockchainItemId: '1',
contentHash: '',
isApproved: true,
metadata: {
type: ThirdPartyItemMetadataType.third_party_v1,
itemWearable: {
name: 'Fragment Name',
description: null,
category: null,
bodyShapes: null,
},
},
thirdParty: {
id: dbTPCollectionMock.third_party_id,
},
reviewedAt: toUnixTimestamp(dbTPCollectionMock.reviewed_at!),
updatedAt: toUnixTimestamp(dbTPCollectionMock.updated_at),
createdAt: toUnixTimestamp(dbTPCollectionMock.created_at),
}

export function convertItemDatesToISO<T extends ItemAttributes | FullItem>(
item: T
): Omit<T, 'reviewed_at' | 'created_at' | 'updated_at'> & {
Expand Down
8 changes: 2 additions & 6 deletions spec/mocks/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import {
I18N,
} from '@dcl/schemas'
import { dbCollectionMock } from './collections'
import {
dbItemMock,
itemFragmentMock,
thirdPartyItemFragmentMock,
} from './items'
import { dbItemMock, itemFragmentMock } from './items'

export const wearableMock: StandardWearable = {
id: itemFragmentMock.urn,
Expand All @@ -34,7 +30,7 @@ export const wearableMock: StandardWearable = {

export const tpWearableMock: ThirdPartyWearable = {
...wearableMock,
id: thirdPartyItemFragmentMock.urn,
id: dbCollectionMock.contract_address + '-' + dbItemMock.blockchain_item_id,
merkleProof: {
proof: [],
index: 0,
Expand Down
50 changes: 1 addition & 49 deletions src/Curation/Curation.router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { ExpressApp } from '../common/ExpressApp'
import {
collectionFragmentMock,
dbCollectionMock,
dbTPCollectionMock,
} from '../../spec/mocks/collections'
import { dbItemMock, thirdPartyItemFragmentMock } from '../../spec/mocks/items'
import { dbItemMock } from '../../spec/mocks/items'
import { thirdPartyAPI } from '../ethereum/api/thirdParty'
import { collectionAPI } from '../ethereum/api/collection'
import { toUnixTimestamp } from '../utils/parse'
import { Collection } from '../Collection'
import { Item, ItemAttributes } from '../Item'
import { isCommitteeMember } from '../Committee'
Expand Down Expand Up @@ -92,52 +90,6 @@ describe('when handling a request', () => {
).rejects.toThrowError('Collection is not a third party collection')
})
})

describe('when it is fetching items from a managed TP collection', () => {
let fetchItemsByCollectionSpy: jest.SpyInstance<
ReturnType<typeof thirdPartyAPI['fetchItemsByCollection']>
>

beforeEach(() => {
mockServiceWithAccess(CollectionCuration, true)

jest
.spyOn(Collection, 'findOne')
.mockResolvedValueOnce(dbTPCollectionMock)

fetchItemsByCollectionSpy = fetchItemsByCollectionSpy = jest
.spyOn(thirdPartyAPI, 'fetchItemsByCollection')
.mockResolvedValueOnce([
{ ...thirdPartyItemFragmentMock }, // approved
{ ...thirdPartyItemFragmentMock }, // approved
{
...thirdPartyItemFragmentMock,
isApproved: false,
reviewedAt: toUnixTimestamp(new Date()),
}, // rejected
{ ...thirdPartyItemFragmentMock, isApproved: false }, // under review
{ ...thirdPartyItemFragmentMock, isApproved: false }, // under review
])
})

it('should fetch the items for the collection id and its third party id', async () => {
await router.getCollectionCurationItemStats(req)
expect(fetchItemsByCollectionSpy).toHaveBeenCalledWith(
dbTPCollectionMock.third_party_id,
req.params.id
)
})

it('should use the fetched items to count and return an object with the values', async () => {
const stats = await router.getCollectionCurationItemStats(req)
expect(stats).toEqual({
total: 5,
approved: 2,
rejected: 1,
needsReview: 2,
})
})
})
})

describe('when trying to obtain a list of collection curations', () => {
Expand Down
31 changes: 6 additions & 25 deletions src/Curation/Curation.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { HTTPError, STATUS_CODES } from '../common/HTTPError'
import { withAuthentication, AuthRequest } from '../middleware'
import { isCommitteeMember } from '../Committee'
import { collectionAPI } from '../ethereum/api/collection'
import { thirdPartyAPI } from '../ethereum/api/thirdParty'
import { getValidator } from '../utils/validator'
import { Collection, CollectionService } from '../Collection'
import { NonExistentItemError, UnpublishedItemError } from '../Item/Item.errors'
Expand Down Expand Up @@ -146,32 +145,14 @@ export class CurationRouter extends Router {
)
}

// TODO: This request could be huge. The method should work, as it's fetching page after page of items but this endpoint should probably be paginated.
const publishedItems = await thirdPartyAPI.fetchItemsByCollection(
collection.third_party_id,
collectionId
)

const total = publishedItems.length
let approved = 0
let rejected = 0
let needsReview = 0

for (const item of publishedItems) {
if (item.isApproved) {
approved += 1
} else if (item.createdAt === item.reviewedAt) {
needsReview += 1
} else {
rejected += 1
}
}
// This endpoint will return 0 on any stats until we implement it
// for the current TP implementation.

return {
total,
approved,
rejected,
needsReview,
total: 0,
approved: 0,
rejected: 0,
needsReview: 0,
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/Item/Item.router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
dbItemMock,
dbTPItemMock,
itemFragmentMock,
thirdPartyItemFragmentMock,
ResultItem,
toResultItem,
toResultTPItem,
Expand Down Expand Up @@ -109,7 +108,6 @@ describe('Item router', () => {
}
tpWearable = {
...tpWearableMock,
id: thirdPartyItemFragmentMock.urn,
}
dbItemNotPublished = {
...dbItem,
Expand Down Expand Up @@ -303,9 +301,6 @@ describe('Item router', () => {
;(thirdPartyAPI.fetchThirdPartiesByManager as jest.Mock).mockResolvedValueOnce(
[thirdPartyFragmentMock]
)
;(thirdPartyAPI.fetchItemsByThirdParties as jest.Mock).mockResolvedValueOnce(
[thirdPartyItemFragmentMock]
)
;(collectionAPI.fetchItemsByAuthorizedUser as jest.Mock).mockResolvedValueOnce(
[itemFragment]
)
Expand Down
54 changes: 0 additions & 54 deletions src/ethereum/api/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,6 @@ export const thirdPartyFragment = () => gql`
}
`

export const thirdPartyItemFragment = () => gql`
fragment thirdPartyItemFragment on Item {
urn
blockchainItemId
contentHash
isApproved
reviewedAt
updatedAt
createdAt
metadata {
itemWearable {
name
description
category
bodyShapes
}
}
thirdParty {
id
}
}
`

export const accountFragment = () => gql`
fragment accountFragment on Account {
id
Expand Down Expand Up @@ -170,37 +147,11 @@ export type ThirdPartyFragment = {
metadata: ThirdPartyMetadata
}

type ThirdPartyItemWearableMetadata = {
name: string | null
description: string | null
category: WearableCategory | null
bodyShapes: BodyShape[] | null
}

export type ThirdPartyItemFragment = {
urn: string
blockchainItemId: string
contentHash: string
isApproved: boolean
reviewedAt: string
updatedAt: string
createdAt: string
metadata: ThirdPartyItemMetadata
thirdParty: {
id: string
}
}

export type ThirdPartyMetadata = {
type: ThirdPartyMetadataType
thirdParty: { name: string; description: string } | null
}

type ThirdPartyItemMetadata = {
type: ThirdPartyItemMetadataType | undefined
itemWearable: ThirdPartyItemWearableMetadata
}

export enum ThirdPartyMetadataType {
THIRD_PARTY_V1 = 'third_party_v1',
}
Expand All @@ -210,11 +161,6 @@ export enum ThirdPartyItemMetadataType {
item_wearable_v1 = 'item_wearable_v1',
}

enum BodyShape {
BaseMale,
BaseFemale,
}

export type AccountFragment = {
id: string
address: string
Expand Down
Loading