Skip to content

Commit 4dbccbc

Browse files
committed
fix: Handle skipPolling option properly
1 parent 1744996 commit 4dbccbc

7 files changed

Lines changed: 30 additions & 4 deletions

File tree

β€Žsrc/adapters/action/dispatcher-http-hook-mastodon.spec.tsβ€Ž

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,26 @@ describe("DispatcherHttp", () => {
8080

8181
await expect(promise).rejects.toBeInstanceOf(Error);
8282
});
83+
84+
it("skips media polling if `skipPolling` is passed", async () => {
85+
const http = new HttpMockImpl();
86+
const dispatcher = new HttpActionDispatcher(
87+
http,
88+
new HttpActionDispatcherHookMastodon(http),
89+
);
90+
91+
httpPost.mockResolvedValueOnce({ id: "1" });
92+
93+
const media = await dispatcher.dispatch({
94+
type: "create",
95+
path: "/api/v2/media",
96+
data: {
97+
skipPolling: true,
98+
},
99+
meta: {},
100+
});
101+
102+
expect(media).toHaveProperty("id", "1");
103+
expect(httpGet).toHaveBeenCalledTimes(0);
104+
});
83105
});

β€Žsrc/adapters/action/dispatcher-http-hook-mastodon.tsβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
type HttpMetaParams,
99
} from "../../interfaces";
1010
import { type mastodon } from "../../mastodon";
11-
import { sleep } from "../../utils";
11+
import { isRecord, sleep } from "../../utils";
1212
import { MastoHttpError, MastoTimeoutError } from "../errors";
1313
import { type HttpAction, type HttpActionType } from "./dispatcher-http";
1414

@@ -105,6 +105,9 @@ export class HttpActionDispatcherHookMastodon
105105
afterDispatch(action: AnyAction, result: unknown): unknown {
106106
if (action.type === "create" && action.path === "/api/v2/media") {
107107
const media = result as mastodon.v1.MediaAttachment;
108+
if (isRecord(action.data) && action.data?.skipPolling === true) {
109+
return media;
110+
}
108111
return waitForMediaAttachment(media.id, this.mediaTimeout, this.http);
109112
}
110113

β€Žsrc/adapters/serializers/flatten-record.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isRecord } from "./is-record";
1+
import { isRecord } from "../../utils";
22

33
export const flattenRecord = (
44
object: unknown,

β€Žsrc/adapters/serializers/rails-query-string.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isRecord } from "./is-record";
1+
import { isRecord } from "../../utils";
22

33
const flatten = (object: unknown, parent = ""): [string, unknown][] => {
44
if (Array.isArray(object)) {

β€Žsrc/adapters/serializers/transform-keys.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isRecord } from "./is-record";
1+
import { isRecord } from "../../utils";
22

33
const _transformKeys = <T>(
44
data: unknown,

β€Žsrc/utils/index.tsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from "./sleep";
2+
export * from "./is-record";
23
export * from "./noop";
34
export * from "./exponential-backoff";
45
export * from "./promise-with-resolvers";

0 commit comments

Comments
Β (0)