Skip to content

Commit

Permalink
fix: is owned check
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmahidalgo committed Aug 11, 2022
1 parent 560f2c8 commit 9f85697
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/Item/Item.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { dbItemMock } from '../../spec/mocks/items'
import { Item } from './Item.model'
import { ItemService } from './Item.service'
import { ItemAttributes } from './Item.types'

jest.mock('./Item.model')

describe('Item Service', () => {
let dbItem: ItemAttributes
describe('isOwnedOrManagedBy', () => {
const service = new ItemService()
beforeEach(() => {
dbItem = { ...dbItemMock, eth_address: '0xoriginalAddress' }
;(Item.findOne as jest.Mock).mockResolvedValueOnce(dbItem)
})

it('should return true when the owner is the sender', async () => {
expect(
await service.isOwnedOrManagedBy(dbItem.id, '0xoriginalAddress')
).toBe(true)
})

it('should return false when the sender is not the owner', async () => {
expect(
await service.isOwnedOrManagedBy(dbItem.id, '0xanotherAddress')
).toBe(false)
})
})
})
2 changes: 1 addition & 1 deletion src/Item/Item.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class ItemService {
ethAddress
)
} else {
return dbItem.eth_address === dbItem.eth_address
return ethAddress === dbItem.eth_address
}
}

Expand Down

0 comments on commit 9f85697

Please sign in to comment.