Skip to content

Commit

Permalink
fix: Fix dispatch to return non-promise value
Browse files Browse the repository at this point in the history
  • Loading branch information
neet committed Jul 30, 2023
1 parent 4e997e0 commit 9fb38e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/adapters/action/dispatcher-http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class HttpActionDispatcher implements ActionDispatcher {
private readonly params: HttpActionDispatcherParams = {},
) {}

async dispatch<T>(action: Action): Promise<T> {
dispatch<T>(action: Action): T | Promise<T> {
const actionType = this.toPrimitiveAction(action.type);
const path = this.isPrimitiveAction(action.type)
? action.path
Expand All @@ -38,12 +38,11 @@ export class HttpActionDispatcher implements ActionDispatcher {
}
case "create": {
if (path === "/api/v2/media") {
const media = await this.http.post<mastodon.v1.MediaAttachment>(
path,
action.data,
meta,
);
return this.waitForMediaAttachment(media.id) as T;
return this.http
.post<mastodon.v1.MediaAttachment>(path, action.data, meta)
.then((media) => {
return this.waitForMediaAttachment(media.id) as T;
});
}
return this.http.post(path, action.data, meta);
}
Expand All @@ -54,7 +53,7 @@ export class HttpActionDispatcher implements ActionDispatcher {
return this.http.delete(path, action.data, meta);
}
case "list": {
return new PaginatorHttp(this.http, path, action.data);
return new PaginatorHttp(this.http, path, action.data) as T;

Check warning on line 56 in src/adapters/action/dispatcher-http.ts

View check run for this annotation

Codecov / codecov/patch

src/adapters/action/dispatcher-http.ts#L56

Added line #L56 was not covered by tests
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/rest/v1/timelines.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ import { type mastodon } from "../../../src";
import { waitForCondition } from "../../../test-utils/wait-for-condition";

describe("timeline", () => {
it("can iterate over timeline", () => {
return sessions.use(async (client) => {
let statuses: mastodon.v1.Status[] | undefined;
for await (const entry of client.rest.v1.timelines.public.list()) {
statuses = entry;
break;
}
expect(statuses).not.toBeUndefined();
});
});

it("returns home", () => {
return sessions.use(async (client) => {
const status = await client.rest.v1.statuses.create({
Expand Down

0 comments on commit 9fb38e7

Please sign in to comment.