-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Refactor Mastodon specific logic with hook API
- Loading branch information
Showing
11 changed files
with
223 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import assert from "node:assert"; | ||
|
||
import { HttpHookMastodon } from "./hook-http-mastodon"; | ||
|
||
describe("hookHttpMastodon", () => { | ||
it("returns a new Request with method PATCH if the request is PUT and the URL ends with /api/v1/accounts/update_credentials", async () => { | ||
const request = new Request( | ||
"https://example.com/api/v1/accounts/update_credentials", | ||
{ method: "PUT" }, | ||
); | ||
const hook = new HttpHookMastodon(); | ||
const result = await hook.before(request); | ||
assert(result instanceof Request); | ||
expect(result).toBeInstanceOf(Request); | ||
expect(result.method).toBe("PATCH"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { type HttpHook } from "../../interfaces/hook"; | ||
|
||
export class HttpHookMastodon implements HttpHook { | ||
readonly type = "Http"; | ||
|
||
async before(request: Request): Promise<Request> { | ||
if ( | ||
request.method === "PUT" && | ||
request.url.endsWith("/api/v1/accounts/update_credentials") | ||
) { | ||
return new Request(request, { method: "PATCH" }); | ||
} | ||
return request; | ||
} | ||
|
||
async after(response: Response): Promise<Response> { | ||
return response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./hook-action-dispatcher-mastodon"; | ||
export * from "./hook-http-mastodon"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.