Skip to content

Commit

Permalink
fix: Fix search API to return paginator
Browse files Browse the repository at this point in the history
  • Loading branch information
neet committed Dec 26, 2023
1 parent e886410 commit 2691c27
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/mastodon/rest/v1/search-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ export interface SearchParams extends DefaultPaginationParams {
}

export interface SearchRepository {
/**
* @deprecated Use `list` instead
*/
fetch(params: SearchParams, meta?: HttpMetaParams): Search;

/**
* Search, but hashtags is an array of strings instead of an array of Tag.
* @param params Parameters
* @return Results
* @see https://docs.joinmastodon.org/methods/search/
*/
fetch(
list(
params: SearchParams,
meta?: HttpMetaParams,
): Paginator<Search, SearchParams>;
Expand Down
7 changes: 6 additions & 1 deletion src/mastodon/rest/v2/search-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ export interface SearchParams extends DefaultPaginationParams {
}

export interface SearchRepository {
/**
* @deprecated Use `list` instead
*/
fetch(params: SearchParams, meta?: HttpMetaParams): Search;

/**
* Perform a search
* @param params Parameters
* @return Results
* @see https://docs.joinmastodon.org/methods/search/
*/
fetch(
list(
params: SearchParams,
meta?: HttpMetaParams,
): Paginator<Search, SearchParams>;
Expand Down
18 changes: 17 additions & 1 deletion tests/rest/v2/search.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
it("searches", async () => {
await using session = await sessions.acquire();
const results = await session.rest.v2.search.fetch({
const results = await session.rest.v2.search.list({
q: "mastodon",
});

Expand All @@ -10,3 +10,19 @@ it("searches", async () => {
hashtags: expect.any(Array),
});
});

it("can be iterated over", async () => {
await using session = await sessions.acquire();
const results = session.rest.v2.search.list({
q: "mastodon",
});

const p1 = await results.next();

expect(typeof p1.done).toBe("boolean");
expect(p1.value).toMatchObject({
accounts: expect.any(Array),
statuses: expect.any(Array),
hashtags: expect.any(Array),
});
});

0 comments on commit 2691c27

Please sign in to comment.