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

feat: tp is published and is approved #378

Merged
merged 32 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d0f7e5d
feat: split curation in items/curations
nicosantangelo Dec 16, 2021
9e25a74
chore: param names
nicosantangelo Dec 20, 2021
bdbce66
feat: create virtual TPW collection curations
nicosantangelo Dec 20, 2021
8fd4a2d
feat: add is published to TPW collections (and a bunch of bugs)
nicosantangelo Dec 25, 2021
f63a0bd
fix: correctly check tpw collection publishes
nicosantangelo Dec 26, 2021
68e24f2
feat: groundwork for item isPublished/isApproved
nicosantangelo Dec 30, 2021
2b5fd3d
feat: consolidate items
nicosantangelo Dec 30, 2021
925db31
Merge branch 'feat/tpw-is-published' of github.com:decentraland/build…
nicosantangelo Dec 30, 2021
f2df8e3
feat: getItem
nicosantangelo Dec 31, 2021
74ffe17
feat: finish item and collection endpoints (missing tests)
nicosantangelo Jan 3, 2022
a4f6b73
fix: collection router specs
nicosantangelo Jan 4, 2022
578b68a
WIP
nicosantangelo Jan 4, 2022
23afbfc
WIP
nicosantangelo Jan 5, 2022
ea7c62d
feat: tests
nicosantangelo Jan 6, 2022
d38c5a6
chore: lint
nicosantangelo Jan 6, 2022
b5195e9
Merge branch 'master' into feat/tpw-is-published
nicosantangelo Jan 10, 2022
059935c
feat: tests
nicosantangelo Jan 10, 2022
cd46135
chore: lint
nicosantangelo Jan 10, 2022
c5c0700
feat: extract getCollectionItems
nicosantangelo Jan 11, 2022
67e70c6
feat: extract getCollection
nicosantangelo Jan 11, 2022
f862202
feat: remove eth_address and managers from TP elements
nicosantangelo Jan 11, 2022
97307de
chore: fix rebase mixup
nicosantangelo Jan 13, 2022
aafc5a7
feat: simpler tp consolidation
nicosantangelo Jan 13, 2022
f8a5a72
fix: script
nicosantangelo Jan 14, 2022
568dff5
fix: collection_id instead of id
nicosantangelo Jan 14, 2022
fd55b10
feat: remove repeated migrations. Renames
nicosantangelo Jan 18, 2022
9623160
feat: remove complexity for service call
nicosantangelo Jan 19, 2022
bdaf724
chore: test name
nicosantangelo Jan 19, 2022
20d81dd
feat: bridge feedback
nicosantangelo Jan 20, 2022
d7e9d1d
Merge branch 'master' into feat/tpw-is-published
nicosantangelo Jan 20, 2022
3417c6a
fix: rebase
nicosantangelo Jan 20, 2022
a537d57
fix: feedback
nicosantangelo Jan 24, 2022
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
10 changes: 10 additions & 0 deletions migrations/1639023421988_rename-curations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { MigrationBuilder } from 'node-pg-migrate'
import { CollectionCuration } from '../src/Curation/CollectionCuration'

export const up = (pgm: MigrationBuilder) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be already complete in #378

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't #378 this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! #379 right? I think this and the migration slipped thru the rebase

pgm.renameTable('curations', CollectionCuration.tableName)
}

export const down = (pgm: MigrationBuilder) => {
pgm.renameTable(CollectionCuration.tableName, 'curations')
}
34 changes: 34 additions & 0 deletions migrations/1639023686468_create-item-curations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { MigrationBuilder } from 'node-pg-migrate'
import { Collection } from '../src/Collection'
import { ItemCuration } from '../src/Curation/ItemCuration'

const tableName = ItemCuration.tableName

export const up = (pgm: MigrationBuilder) => {
pgm.createTable(
tableName,
{
id: { type: 'UUID', primaryKey: true, unique: true, notNull: true },
item_id: { type: 'UUID', notNull: true },
status: { type: 'CURATION_STATUS', notNull: true },
created_at: { type: 'TIMESTAMP', notNull: true },
updated_at: { type: 'TIMESTAMP', notNull: true },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not wrong, this has already been created in #378.

},
{
ifNotExists: true,
constraints: {
foreignKeys: {
references: Collection.tableName,
columns: 'item_id',
onDelete: 'CASCADE',
},
},
}
)

pgm.createIndex(tableName, 'item_id')
}

export const down = (pgm: MigrationBuilder) => {
pgm.dropTable(tableName, {})
}
54 changes: 40 additions & 14 deletions spec/mocks/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ import { omit } from 'decentraland-commons/dist/utils'
import {
CollectionAttributes,
FullCollection,
ThirdPartyCollectionAttributes,
} from '../../src/Collection/Collection.types'
import {
CollectionFragment,
ThirdPartyFragment,
ThirdPartyMetadataType,
} from '../../src/ethereum/api/fragments'
import { toUnixTimestamp } from '../../src/utils/parse'
import { wallet } from './wallet'
import { CollectionFragment } from '../../src/ethereum/api/fragments'

export const collectionAttributesMock: CollectionAttributes = {
export const dbCollectionMock: CollectionAttributes = {
id: uuidv4(),
name: 'Test',
urn_suffix: null,
eth_address: wallet.address,
salt: '',
contract_address: '0x02b6bD2420cCADC38726BD34BB7f5c52B3F4F3ff',
Expand All @@ -20,28 +25,49 @@ export const collectionAttributesMock: CollectionAttributes = {
managers: [],
forum_link: null,
lock: null,
urn_suffix: null,
third_party_id: null,
reviewed_at: new Date(),
created_at: new Date(),
updated_at: new Date(),
}

export const collectionFragment: Omit<
export const dbTPCollectionMock: ThirdPartyCollectionAttributes = {
...dbCollectionMock,
eth_address: '',
contract_address: '',
urn_suffix: 'collection-id',
third_party_id:
'urn:decentraland:mumbai:collections-thirdparty:third-party-id',
}

export const collectionFragmentMock: Omit<
CollectionFragment,
'reviewedAt' | 'updatedAt' | 'createdAt'
> & { reviewedAt: string | null; updatedAt: string; createdAt: string } = {
id: 'string',
creator: collectionAttributesMock.eth_address,
owner: collectionAttributesMock.eth_address,
name: collectionAttributesMock.name,
isApproved: collectionAttributesMock.is_approved,
minters: collectionAttributesMock.minters,
managers: collectionAttributesMock.managers,
reviewedAt: collectionAttributesMock.reviewed_at
? collectionAttributesMock.reviewed_at.toISOString()
creator: dbCollectionMock.eth_address,
owner: dbCollectionMock.eth_address,
name: dbCollectionMock.name,
isApproved: dbCollectionMock.is_approved,
minters: dbCollectionMock.minters,
managers: dbCollectionMock.managers,
reviewedAt: dbCollectionMock.reviewed_at
? toUnixTimestamp(dbCollectionMock.reviewed_at)
: null,
updatedAt: collectionAttributesMock.updated_at.toISOString(),
createdAt: collectionAttributesMock.created_at.toISOString(),
updatedAt: toUnixTimestamp(dbCollectionMock.updated_at),
createdAt: toUnixTimestamp(dbCollectionMock.created_at),
}

export const thirdPartyFragmentMock: ThirdPartyFragment = {
id: dbTPCollectionMock.third_party_id,
managers: [wallet.address],
maxItems: '10',
totalItems: '1',
metadata: {
type: ThirdPartyMetadataType.THIRD_PARTY_V1,
thirdParty: null,
},
}

export type ResultCollection = Omit<
Expand Down
62 changes: 47 additions & 15 deletions spec/mocks/items.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { v4 as uuidv4 } from 'uuid'
import { Wearable } from '../../src/ethereum/api/peer'
import { ItemFragment } from '../../src/ethereum/api/fragments'
import {
ItemFragment,
ThirdPartyItemFragment,
ThirdPartyItemMetadataType,
} from '../../src/ethereum/api/fragments'
import {
FullItem,
ItemAttributes,
ItemRarity,
ItemType,
ThirdPartyItemAttributes,
} from '../../src/Item/Item.types'
import { dbCollectionMock, dbTPCollectionMock } from './collections'
import { toUnixTimestamp } from '../../src/utils/parse'
import { buildTPItemURN } from '../../src/Item/utils'
import { CollectionAttributes } from '../../src/Collection'
import { collectionAttributesMock } from './collections'
import { isTPCollection } from '../../src/Collection/utils'

export type ResultItem = Omit<FullItem, 'created_at' | 'updated_at'> & {
Expand Down Expand Up @@ -61,7 +67,7 @@ export const dbItemMock: ItemAttributes = {
description: '',
thumbnail: '',
eth_address: '',
collection_id: collectionAttributesMock.id,
collection_id: dbCollectionMock.id,
blockchain_item_id: '0',
price: '',
beneficiary: '',
Expand All @@ -86,36 +92,62 @@ export const dbItemMock: ItemAttributes = {
updated_at: new Date(),
}

export const itemURNMock = `urn:decentraland:ropsten:collections-v2:${collectionAttributesMock.contract_address}:${dbItemMock.blockchain_item_id}`
export const dbTPItemMock: ThirdPartyItemAttributes = {
...dbItemMock,
urn_suffix: '1',
}

export const itemFragmentMock = {
id:
collectionAttributesMock.contract_address +
'-' +
dbItemMock.blockchain_item_id,
id: dbCollectionMock.contract_address + '-' + dbItemMock.blockchain_item_id,
blockchainId: '0',
urn: itemURNMock,
urn: `urn:decentraland:ropsten:collections-v2:${dbCollectionMock.contract_address}:${dbItemMock.blockchain_item_id}`,
totalSupply: '1',
price: dbItemMock.price!.toString(),
beneficiary: 'aBeneficiary',
minters: [],
managers: [],
collection: {
id: collectionAttributesMock.id,
id: dbCollectionMock.id,
creator: 'aCreator',
owner: 'anOwner',
name: collectionAttributesMock.name,
isApproved: collectionAttributesMock.is_approved,
name: dbCollectionMock.name,
isApproved: dbCollectionMock.is_approved,
minters: [],
managers: [],
reviewedAt: collectionAttributesMock.reviewed_at!.toISOString(),
updatedAt: collectionAttributesMock.updated_at.toISOString(),
createdAt: collectionAttributesMock.created_at.toISOString(),
reviewedAt: toUnixTimestamp(dbCollectionMock.reviewed_at!),
updatedAt: toUnixTimestamp(dbCollectionMock.updated_at),
createdAt: toUnixTimestamp(dbCollectionMock.created_at),
},
metadata: {},
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
19 changes: 9 additions & 10 deletions spec/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import { Ownable } from '../src/Ownable/Ownable'
import { Item } from '../src/Item/Item.model'
import { thirdPartyAPI } from '../src/ethereum/api/thirdParty'
import { wallet } from './mocks/wallet'
import { collectionAttributesMock } from './mocks/collections'
import { dbCollectionMock } from './mocks/collections'
import { dbItemMock } from './mocks/items'
import { ThirdPartyItemsFragment } from '../src/ethereum/api/fragments'

export function buildURL(
uri: string,
Expand Down Expand Up @@ -118,7 +117,7 @@ export function mockCollectionAuthorizationMiddleware(
isAuthorized = true
) {
const collectionToReturn = {
...collectionAttributesMock,
...dbCollectionMock,
urn_suffix: isThirdParty ? 'third-party-collection-id' : null,
third_party_id: isThirdParty ? 'third-party-id' : null,
eth_address: ethAddress,
Expand Down Expand Up @@ -297,8 +296,8 @@ export function mockIsCollectionPublished(
}

/**
* Mocks the "fetchThirdPartyCollectionItems" method of the thirdPartyAPI module.
* This mock requires the thirdPartyAPI.fetchThirdPartyCollectionItems method to be mocked first.
* Mocks the "isPublished" method of the thirdPartyAPI module.
* This mock requires the thirdPartyAPI.isPublished method to be mocked first.
*
* @param thirdPartyId - The third party id to mock the response for.
* @param collectionUrnSuffix - The collection urn suffix to mock the response for.
Expand All @@ -309,13 +308,13 @@ export function mockThirdPartyCollectionWithItems(
collectionUrnSuffix: string,
hasItems: boolean
): void {
if (!(thirdPartyAPI.fetchThirdPartyCollectionItems as jest.Mock).mock) {
if (!(thirdPartyAPI.isPublished as jest.Mock).mock) {
LautaroPetaccio marked this conversation as resolved.
Show resolved Hide resolved
throw new Error(
"thirdPartyAPI.fetchThirdPartyCollectionItems should be mocked to mock the fetchThirdPartyCollectionItems method but it isn't"
"thirdPartyAPI.isPublished should be mocked to mock the isPublished method but it isn't"
)
}
;(thirdPartyAPI.fetchThirdPartyCollectionItems as jest.MockedFunction<
typeof thirdPartyAPI.fetchThirdPartyCollectionItems
;(thirdPartyAPI.isPublished as jest.MockedFunction<
typeof thirdPartyAPI.isPublished
>).mockImplementationOnce((tpId, collectionURN) => {
if (tpId !== thirdPartyId || collectionURN !== collectionUrnSuffix) {
return Promise.reject(
Expand All @@ -324,6 +323,6 @@ export function mockThirdPartyCollectionWithItems(
)
)
}
return Promise.resolve(hasItems ? [{} as ThirdPartyItemsFragment] : [])
return Promise.resolve(hasItems)
})
}
1 change: 1 addition & 0 deletions src/Collection/Collection.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class Collection extends Model<CollectionAttributes> {
SELECT count(*) as count
FROM ${raw(this.tableName)}
WHERE id != ${id}
AND third_party_id IS NULL
AND urn_suffix IS NULL
AND LOWER(name) = ${name.toLowerCase()}`)

Expand Down
Loading