Skip to content

Commit

Permalink
fix: Forbit moving orphan items to published collections
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmahidalgo committed Jun 27, 2022
1 parent eca2613 commit 81b80aa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/Item/Item.router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,32 @@ describe('Item router', () => {
})
})

describe('and the item is orphan and is being moved into the collection', () => {
beforeEach(() => {
mockItem.findOne.mockResolvedValueOnce({
...itemToUpsert,
collection_id: null,
})
})

it('should fail with can not add the item to a published collection message', async () => {
const response = await server
.put(buildURL(url))
.send({
item: { ...itemToUpsert, collection_id: collectionMock.id },
})
.set(createAuthHeaders('put', url))
.expect(STATUS_CODES.conflict)

expect(response.body).toEqual({
data: { id: itemToUpsert.id },
error:
"The collection that contains this item has been already published. The item can't be inserted.",
ok: false,
})
})
})

describe('and the item is being removed from the collection', () => {
beforeEach(() => {
mockItem.findOne.mockResolvedValueOnce(itemToUpsert)
Expand Down
4 changes: 2 additions & 2 deletions src/Item/Item.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ export class ItemService {
))

if (isDbCollectionPublished) {
// Prohibits adding new items to a published collection
if (!dbItem) {
// Prohibits adding new items or moving orphan ones to a published collection
if (!dbItem || !dbItem.collection_id) {
throw new DCLItemAlreadyPublishedError(
item.id,
dbCollection.contract_address!,
Expand Down

0 comments on commit 81b80aa

Please sign in to comment.