Skip to content

Commit

Permalink
feat: Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cyaiox committed Nov 29, 2024
1 parent 8aab203 commit f211911
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/Item/Item.router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ describe('Item router', () => {
beneficiary: itemFragment.beneficiary,
collection_id: dbItem.collection_id,
blockchain_item_id: dbItem.blockchain_item_id,
urn: itemFragmentMock.urn,
urn: itemFragment.urn,
eth_address: itemFragment.collection.creator,
},
ok: true,
})
Expand Down Expand Up @@ -280,7 +281,8 @@ describe('Item router', () => {
{
...resultingItem,
beneficiary: itemFragment.beneficiary,
urn: itemFragmentMock.urn,
urn: itemFragment.urn,
eth_address: itemFragment.collection.creator,
},
resultItemNotPublished,
resultingTPItem,
Expand Down Expand Up @@ -348,7 +350,8 @@ describe('Item router', () => {
beneficiary: itemFragment.beneficiary,
collection_id: dbItem.collection_id,
blockchain_item_id: dbItem.blockchain_item_id,
urn: itemFragmentMock.urn,
urn: itemFragment.urn,
eth_address: itemFragment.collection.creator,
},
resultItemNotPublished,
],
Expand Down Expand Up @@ -403,7 +406,8 @@ describe('Item router', () => {
beneficiary: itemFragment.beneficiary,
collection_id: dbItem.collection_id,
blockchain_item_id: dbItem.blockchain_item_id,
urn: itemFragmentMock.urn,
urn: itemFragment.urn,
eth_address: itemFragment.collection.creator,
},
resultItemNotPublished,
resultingTPItem,
Expand Down Expand Up @@ -453,7 +457,8 @@ describe('Item router', () => {
beneficiary: itemFragment.beneficiary,
collection_id: dbItem.collection_id,
blockchain_item_id: dbItem.blockchain_item_id,
urn: itemFragmentMock.urn,
urn: itemFragment.urn,
eth_address: itemFragment.collection.creator,
},
resultItemNotPublished,
resultingTPItem,
Expand Down Expand Up @@ -516,7 +521,8 @@ describe('Item router', () => {
beneficiary: itemFragment.beneficiary,
collection_id: dbItem.collection_id,
blockchain_item_id: dbItem.blockchain_item_id,
urn: itemFragmentMock.urn,
urn: itemFragment.urn,
eth_address: itemFragment.collection.creator,
},
resultItemNotPublished,
],
Expand Down Expand Up @@ -567,6 +573,7 @@ describe('Item router', () => {
collection_id: dbItem.collection_id,
blockchain_item_id: dbItem.blockchain_item_id,
urn: itemFragmentMock.urn,
eth_address: itemFragmentMock.collection.creator,
},
resultItemNotPublished,
],
Expand Down Expand Up @@ -1418,6 +1425,8 @@ describe('Item router', () => {
})

describe('and is being moved into a published collection', () => {
let mockCollectionApi: jest.Mock

beforeEach(() => {
mockItem.findOne.mockReset()
mockItem.findOne.mockResolvedValueOnce({
Expand All @@ -1427,7 +1436,7 @@ describe('Item router', () => {
mockCollection.findByIds
.mockResolvedValueOnce([{ ...dbCollectionMock, item_count: 1 }])
.mockResolvedValueOnce([{ ...dbCollectionMock, item_count: 1 }])
;(collectionAPI.fetchCollection as jest.Mock).mockImplementationOnce(
mockCollectionApi = (collectionAPI.fetchCollection as jest.Mock).mockImplementation(
() =>
Promise.resolve({
...itemFragment.collection,
Expand All @@ -1437,6 +1446,10 @@ describe('Item router', () => {
mockOwnableCanUpsert(Item, itemToUpsert.id, wallet.address, true)
})

afterEach(() => {
mockCollectionApi.mockClear()
})

it('should fail with can not add the item to a published collection message', async () => {
const response = await server
.put(buildURL(url))
Expand Down Expand Up @@ -2081,8 +2094,8 @@ describe('Item router', () => {
data: {
...Bridge.toFullItem(dbItem),
local_content_hash: expect.any(String),
eth_address: ethAddress,
beneficiary: 'aBeneficiary',
eth_address: itemFragment.collection.creator,
beneficiary: itemFragment.beneficiary,
in_catalyst: true,
is_published: true,
urn: wearable.id,
Expand Down Expand Up @@ -2222,7 +2235,7 @@ describe('Item router', () => {
is_published: true,
urn: wearable.id,
local_content_hash: expect.any(String),
eth_address: wallet.address,
eth_address: itemFragment.collection.creator,
created_at: dbItem.created_at.toISOString(),
updated_at: currentDate.toISOString(),
},
Expand Down
13 changes: 13 additions & 0 deletions src/Item/Item.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
dbCollectionMock as baseDbCollectionMock,
dbTPCollectionMock as baseDbTPCollectionMock,
thirdPartyFragmentMock,
} from '../../spec/mocks/collections'
import {
dbItemMock,
Expand All @@ -19,6 +20,7 @@ import { CollectionService } from '../Collection/Collection.service'
import { Bridge } from '../ethereum/api/Bridge'
import { collectionAPI } from '../ethereum/api/collection'
import { peerAPI } from '../ethereum/api/peer'
import { thirdPartyAPI } from '../ethereum/api/thirdParty'
import {
ItemCantBeMovedFromCollectionError,
MaximunAmountOfTagsReachedError,
Expand All @@ -32,7 +34,12 @@ import { VIDEO_PATH } from './utils'
jest.mock('../ethereum/api/collection')
jest.mock('../Collection/Collection.model')
jest.mock('../ethereum/api/peer')
jest.mock('../ethereum/api/thirdParty')
jest.mock('./Item.model')
jest.mock('../Curation/ItemCuration/ItemCuration.model')
jest.mock('../ThirdParty/VirtualThirdParty.model')

const thirdPartyAPIMock = thirdPartyAPI as jest.Mocked<typeof thirdPartyAPI>

describe('Item Service', () => {
let dbItem: ItemAttributes
Expand Down Expand Up @@ -91,6 +98,9 @@ describe('Item Service', () => {
ids.includes(collection.id)
)
)
thirdPartyAPIMock.fetchThirdParty.mockResolvedValueOnce(
thirdPartyFragmentMock
)
})

it('should throw the ItemCantBeMovedFromCollectionError error', () => {
Expand All @@ -113,6 +123,9 @@ describe('Item Service', () => {
ids.includes(collection.id)
)
)
thirdPartyAPIMock.fetchThirdParty.mockResolvedValueOnce(
thirdPartyFragmentMock
)
})

it('should throw the ItemCantBeMovedFromCollectionError error', () => {
Expand Down

0 comments on commit f211911

Please sign in to comment.