Skip to content

Commit

Permalink
chore: rename method and update test
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmahidalgo committed Apr 12, 2022
1 parent 5e6084e commit a163a11
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Item/Item.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class Item extends Model<ItemAttributes> {

// PAGINATED QUERIES

static findAllItemsByAddress(
static findItemsByAddress(
address: string,
thirdPartyIds: string[],
parmas: {
Expand Down
15 changes: 8 additions & 7 deletions src/Item/Item.router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ describe('Item router', () => {
let allAddressItems: ItemAttributes[]
beforeEach(() => {
allAddressItems = [dbItem, dbItemNotPublished, dbTPItem]
;(Item.findAllItemsByAddress as jest.Mock).mockResolvedValueOnce(
;(Item.findItemsByAddress as jest.Mock).mockResolvedValueOnce(
allAddressItems.map((item) => ({
...item,
total_count: allAddressItems.length,
Expand Down Expand Up @@ -345,7 +345,7 @@ describe('Item router', () => {
],
ok: true,
})
expect(Item.findAllItemsByAddress).toHaveBeenCalledWith(
expect(Item.findItemsByAddress).toHaveBeenCalledWith(
wallet.address,
[thirdPartyFragmentMock.id],
{
Expand All @@ -358,14 +358,15 @@ describe('Item router', () => {
})
})

describe('and pagination params are passed', () => {
describe('and pagination & collectionId params are passed', () => {
let baseUrl: string
let page: number
let limit: number
let collectionId: string
beforeEach(() => {
;(page = 1), (limit = 1)
;(page = 1), (limit = 1), (collectionId = 'null')
baseUrl = `/${wallet.address}/items`
url = `${baseUrl}?limit=${limit}&page=${page}`
url = `${baseUrl}?limit=${limit}&page=${page}&collectionId=${collectionId}`
})
it('should call the find method with the pagination params', () => {
return server
Expand Down Expand Up @@ -393,13 +394,13 @@ describe('Item router', () => {
},
ok: true,
})
expect(Item.findAllItemsByAddress).toHaveBeenCalledWith(
expect(Item.findItemsByAddress).toHaveBeenCalledWith(
wallet.address,
[thirdPartyFragmentMock.id],
{
limit,
offset: page - 1, // it's the offset
collectionId: undefined,
collectionId,
}
)
})
Expand Down
2 changes: 1 addition & 1 deletion src/Item/Item.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class ItemService {

const thirdPartyIds = thirdParties.map((thirdParty) => thirdParty.id)

return Item.findAllItemsByAddress(address, thirdPartyIds, params)
return Item.findItemsByAddress(address, thirdPartyIds, params)
}

/**
Expand Down

0 comments on commit a163a11

Please sign in to comment.