Skip to content

Commit

Permalink
feat: add query search param to collections by address (#745)
Browse files Browse the repository at this point in the history
  • Loading branch information
meelrossi committed May 3, 2024
1 parent 80ee66e commit 2c41ccf
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
43 changes: 43 additions & 0 deletions src/Collection/Collection.router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,49 @@ describe('Collection router', () => {
})
})
})

describe('and sending search query param', () => {
let search: string

beforeEach(() => {
search = 'text'
;(Collection.findAll as jest.Mock).mockReturnValueOnce([
{ ...dbCollection, collection_count: 1 },
])
;(Collection.findByThirdPartyIds as jest.Mock).mockReturnValueOnce([])
;(thirdPartyAPI.fetchThirdPartiesByManager as jest.Mock).mockReturnValueOnce(
[]
)
})

it('should respond with pagination data and should have call the findAll method with the right params', () => {
return server
.get(buildURL(`${url}?q=${search}`))
.set(createAuthHeaders('get', url))
.expect(200)
.then((response: any) => {
expect(response.body).toEqual({
data: [
{
...resultingCollectionAttributes,
urn: `${tpUrnPrefix}:${dbCollection.contract_address}`,
},
],
ok: true,
})
expect(Collection.findAll).toHaveBeenCalledWith({
address: wallet.address,
limit: undefined,
offset: undefined,
sort: CollectionSort.CREATED_AT_DESC,
thirdPartyIds: [],
remoteIds: [],
q: "text",
isPublished: undefined
})
})
})
})
})

describe('when retrieving a single collection', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/Collection/Collection.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export class CollectionRouter extends Router {
req: AuthRequest
): Promise<PaginatedResponse<FullCollection> | FullCollection[]> => {
const { page, limit } = getPaginationParams(req)
const { is_published, sort } = req.query
const { is_published, sort, q } = req.query
const eth_address = server.extractFromReq(req, 'address')
const auth_address = req.auth.ethAddress

Expand All @@ -342,6 +342,7 @@ export class CollectionRouter extends Router {

const allCollectionsWithCount = await this.service.getCollections(
{
q: q as string,
offset: page && limit ? getOffset(page, limit) : undefined,
limit,
address: eth_address,
Expand Down

0 comments on commit 2c41ccf

Please sign in to comment.