-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tests): Add tests for WebSocket and Proxy API
- Loading branch information
Showing
270 changed files
with
3,337 additions
and
2,213 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
{ | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { createRestClient, type mastodon } from 'masto'; | ||
import { createRestClient, type mastodon } from "masto"; | ||
|
||
const masto = createRestClient({ | ||
url: 'https://example.com', | ||
accessToken: 'YOUR TOKEN', | ||
url: "https://example.com", | ||
accessToken: "YOUR TOKEN", | ||
}); | ||
|
||
const s: mastodon.v1.Status = await masto.v1.statuses.create({ | ||
status: 'Hello from #mastojs!', | ||
visibility: 'public', | ||
status: "Hello from #mastojs!", | ||
visibility: "public", | ||
}); | ||
|
||
console.log(s); |
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import { createRestClient } from 'masto'; | ||
import { createRestClient } from "masto"; | ||
|
||
const masto = createRestClient({ | ||
url: 'https://example.com', | ||
accessToken: 'TOKEN', | ||
url: "https://example.com", | ||
accessToken: "TOKEN", | ||
}); | ||
|
||
// Fetching reports | ||
const reports = await masto.v1.admin.reports.list(); | ||
|
||
// Disable an account of the 1st report | ||
await masto.v1.admin.accounts.$select(reports[0].account.id).action.create({ | ||
type: 'disable', | ||
type: "disable", | ||
reportId: reports[0].id, | ||
text: 'Your account has been disabled', | ||
text: "Your account has been disabled", | ||
}); |
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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import { createRestClient } from 'masto'; | ||
import { createRestClient } from "masto"; | ||
|
||
const masto = createRestClient({ | ||
url: 'https://example.com', | ||
url: "https://example.com", | ||
}); | ||
|
||
const app = await masto.v1.apps.create({ | ||
clientName: 'My app', | ||
redirectUris: 'urn:ietf:wg:oauth:2.0:oob', | ||
scopes: 'read write', | ||
website: 'example.com', | ||
clientName: "My app", | ||
redirectUris: "urn:ietf:wg:oauth:2.0:oob", | ||
scopes: "read write", | ||
website: "example.com", | ||
}); | ||
|
||
console.log(app); |
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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import fs from 'node:fs/promises'; | ||
import fs from "node:fs/promises"; | ||
|
||
import { createRestClient } from '../src'; | ||
import { createRestClient } from "../src"; | ||
|
||
const masto = createRestClient({ | ||
url: 'https://example.com', | ||
accessToken: 'YOUR TOKEN', | ||
url: "https://example.com", | ||
accessToken: "YOUR TOKEN", | ||
}); | ||
|
||
const newProfile = await masto.v1.accounts.updateCredentials.update({ | ||
displayName: 'Fluffy elephant friend', | ||
note: 'Hi fediverse!', | ||
const newProfile = await masto.v1.accounts.updateCredentials({ | ||
displayName: "Fluffy elephant friend", | ||
note: "Hi fediverse!", | ||
// See `create-new-status-with-image.ts` example for this field. | ||
avatar: new Blob([await fs.readFile('../some_image.png')]), | ||
avatar: new Blob([await fs.readFile("../some_image.png")]), | ||
}); | ||
|
||
console.log(newProfile); |
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,66 @@ | ||
import { httpGet, HttpMockImpl, httpPost } from "../../__mocks__"; | ||
import { MastoHttpError, MastoTimeoutError } from "../errors"; | ||
import { HttpActionDispatcher } from "./dispatcher-http"; | ||
|
||
describe("DispatcherHttp", () => { | ||
afterEach(() => { | ||
httpGet.mockClear(); | ||
httpPost.mockClear(); | ||
}); | ||
|
||
it("waits for media attachment to be created", async () => { | ||
const dispatcher = new HttpActionDispatcher(new HttpMockImpl()); | ||
|
||
httpPost.mockResolvedValueOnce({ id: "1" }); | ||
|
||
httpGet | ||
.mockRejectedValueOnce(new MastoHttpError(404, "Not Found")) | ||
.mockRejectedValueOnce(new MastoHttpError(404, "Not Found")) | ||
.mockResolvedValueOnce({ id: "1", url: "https://example.com" }); | ||
|
||
const media = await dispatcher.dispatch({ | ||
type: "create", | ||
path: "/api/v2/media", | ||
data: undefined, | ||
meta: {}, | ||
}); | ||
|
||
expect(media).toHaveProperty("id", "1"); | ||
expect(media).toHaveProperty("url", "https://example.com"); | ||
expect(httpGet).toHaveBeenCalledTimes(3); | ||
}); | ||
|
||
it("throws an error if media processing did not finish", async () => { | ||
const dispatcher = new HttpActionDispatcher(new HttpMockImpl(), { | ||
mediaTimeout: 1, | ||
}); | ||
|
||
httpPost.mockResolvedValueOnce({ id: "1" }); | ||
httpGet.mockRejectedValue(new MastoHttpError(404, "Not Found")); | ||
|
||
const promise = dispatcher.dispatch({ | ||
type: "create", | ||
path: "/api/v2/media", | ||
data: undefined, | ||
meta: {}, | ||
}); | ||
|
||
await expect(promise).rejects.toBeInstanceOf(MastoTimeoutError); | ||
}); | ||
|
||
it("rethrows errors for media processing", async () => { | ||
const dispatcher = new HttpActionDispatcher(new HttpMockImpl()); | ||
|
||
httpPost.mockResolvedValueOnce({ id: "1" }); | ||
httpGet.mockRejectedValueOnce(new Error("Unknown error")); | ||
|
||
const promise = dispatcher.dispatch({ | ||
type: "create", | ||
path: "/api/v2/media", | ||
data: undefined, | ||
meta: {}, | ||
}); | ||
|
||
await expect(promise).rejects.toBeInstanceOf(Error); | ||
}); | ||
}); |
Oops, something went wrong.