Skip to content

Commit

Permalink
feat: return third party collections with owner
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosantangelo committed Oct 29, 2021
1 parent 6f927d0 commit ebbcc36
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Collection/Collection.router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ describe('Collection router', () => {
},
{
...toResultCollection(thirdPartyDbCollection),
owner: wallet.address,
urn: `urn:decentraland:ropsten:collections-thirdparty:${thirdPartyDbCollection.third_party_id}:${thirdPartyDbCollection.urn_suffix}`,
},
],
Expand Down
48 changes: 48 additions & 0 deletions src/Collection/Collection.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { env } from 'decentraland-commons'
import { collectionAttributesMock } from '../../spec/mocks/collections'
import { wallet } from '../../spec/utils'
import { thirdPartyAPI } from '../ethereum/api/thirdParty'
import { Collection } from './Collection.model'
import { CollectionAttributes } from './Collection.types'
import { CollectionService } from './Collection.service'

jest.mock('../ethereum/api/thirdParty')
Expand Down Expand Up @@ -108,4 +112,48 @@ describe('Collection service', () => {
})
})
})

describe('when getting the database TPW collections', () => {
const service = new CollectionService()

describe('when the graph has no third party records', () => {
beforeEach(() => {
;(thirdPartyAPI.fetchThirdPartyIds as jest.Mock).mockReturnValueOnce([])
})

it('should return an empty array', async () => {
expect(await service.getDbTPWCollections(wallet.address)).toEqual([])
})
})

describe('when the graph third party records', () => {
let thirdPartyDbCollection: CollectionAttributes

beforeEach(() => {
thirdPartyDbCollection = {
...collectionAttributesMock,
urn_suffix: 'thesuffix',
third_party_id: 'some:third-party-id',
}
;(thirdPartyAPI.fetchThirdPartyIds as jest.Mock).mockReturnValueOnce([
thirdPartyDbCollection.id,
])
;(Collection.findByThirdPartyIds as jest.Mock).mockReturnValueOnce([
thirdPartyDbCollection,
])
})

it('should the db collection with the added owner', async () => {
expect(await service.getDbTPWCollections(wallet.address)).toEqual([
{
...thirdPartyDbCollection,
owner: wallet.address,
},
])
expect(Collection.findByThirdPartyIds).toHaveBeenCalledWith([
thirdPartyDbCollection.id,
])
})
})
})
})
14 changes: 11 additions & 3 deletions src/Collection/Collection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,16 @@ export class CollectionService {

async getDbTPWCollections(address: string): Promise<CollectionAttributes[]> {
const thirdPartyIds = await thirdPartyAPI.fetchThirdPartyIds(address)
return thirdPartyIds.length > 0
? Collection.findByThirdPartyIds(thirdPartyIds)
: []
if (thirdPartyIds.length <= 0) {
return []
}

const dbThridPartyCollections = await Collection.findByThirdPartyIds(
thirdPartyIds
)
return dbThridPartyCollections.map((collection) => ({
...collection,
owner: address,
}))
}
}

0 comments on commit ebbcc36

Please sign in to comment.