Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add query search param to collections by address #745

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading