Skip to content

Commit

Permalink
chore: Refactor test assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
neet committed Oct 15, 2024
1 parent 129e8b0 commit cf42534
Show file tree
Hide file tree
Showing 22 changed files with 45 additions and 86 deletions.
5 changes: 0 additions & 5 deletions test-utils/async-next-tick.ts

This file was deleted.

37 changes: 0 additions & 37 deletions test-utils/jest-extend-expect.ts

This file was deleted.

6 changes: 4 additions & 2 deletions test-utils/jest-setup-after-env.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import "./jest-polyfills";
import "./jest-extend-expect";

import { createRestAPIClient } from "../src";
import { SessionPoolImpl } from "./pools";

jest.retryTimes(3);
if (process.env.CI) {
jest.retryTimes(3);
}

jest.setTimeout(1000 * 60);

globalThis.admin = createRestAPIClient({
Expand Down
2 changes: 1 addition & 1 deletion test-utils/pools/session-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class SessionPoolImpl implements Pool<Session> {
if (token == undefined) {
// eslint-disable-next-line no-console
console.warn(
`Session ${session.id} (${session.acct}) is already released`,
`Session ${session.id} (${session.account.acct}) is already released`,
);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions test-utils/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {

export interface Session {
readonly id: string;
readonly acct: string;
readonly account: mastodon.v1.Account;
readonly rest: mastodon.rest.Client;
readonly ws: mastodon.streaming.Client;
readonly [Symbol.asyncDispose]: () => Promise<void>;
Expand All @@ -32,7 +32,7 @@ export const createSession = async (

return Object.freeze({
id: account.id,
acct: account.acct,
account,
rest,
ws,
[Symbol.asyncDispose]: dispose,
Expand Down
6 changes: 3 additions & 3 deletions tests/rest/v1/accounts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ describe("account", () => {
.$select(status.account.id)
.statuses.list();

expect(statuses).toContainId(status.id);
expect(statuses).toContainEqual(status);
});

it("searches", async () => {
Expand Down Expand Up @@ -284,7 +284,7 @@ describe("account", () => {
const tags = await client.rest.v1.accounts
.$select(client.id)
.featuredTags.list();
expect(tags).toContainId(featuredTag.id);
expect(tags).toContainEqual(featuredTag);

await client.rest.v1.featuredTags.$select(featuredTag.id).remove();
});
Expand All @@ -308,7 +308,7 @@ describe("account", () => {
it("lookup", async () => {
await using client = await sessions.acquire();
const account = await client.rest.v1.accounts.lookup({
acct: client.acct,
acct: client.account.acct,
});
expect(account.id).toBe(client.id);
});
Expand Down
4 changes: 2 additions & 2 deletions tests/rest/v1/admin/canonical-email-blocks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ describe("canonical-email-blocks", () => {
const result = await admin.v1.admin.canonicalEmailBlocks.test({
email: "test@example.com",
});
expect(result).toContainId(canonicalEmailBlock.id);
expect(result).toContainEqual(canonicalEmailBlock);

const canonicalEmailBlocks =
await admin.v1.admin.canonicalEmailBlocks.list();
expect(canonicalEmailBlocks).toContainId(canonicalEmailBlock.id);
expect(canonicalEmailBlocks).toContainEqual(canonicalEmailBlock);
} finally {
await admin.v1.admin.canonicalEmailBlocks
.$select(canonicalEmailBlock.id)
Expand Down
2 changes: 1 addition & 1 deletion tests/rest/v1/admin/domain-allows.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ it("handles domain allows", async () => {
expect(domainAllow.domain).toMatch(/example.domain.to.allow.com/);

const list = await admin.v1.admin.domainAllows.list();
expect(list).toContainId(domainAllow.id);
expect(list).toContainEqual(domainAllow);
} finally {
await admin.v1.admin.domainAllows.$select(domainAllow.id).remove();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/rest/v1/admin/domain-blocks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ it("handles domain blocks", async () => {
expect(domainBlock.rejectMedia).toBe(false);

const list = await admin.v1.admin.domainBlocks.list();
expect(list).toContainId(domainBlock.id);
expect(list).toContainEqual(domainBlock);
} finally {
await admin.v1.admin.domainBlocks.$select(domainBlock.id).remove();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/rest/v1/admin/email-domain-blocks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ it("handle email domain block", async () => {
expect(emailDomainBlock.domain).toMatch(/example.domain.to.block.com/);

const list = await admin.v1.admin.emailDomainBlocks.list();
expect(list).toContainId(emailDomainBlock.id);
expect(list).toContainEqual(emailDomainBlock);
} finally {
await admin.v1.admin.emailDomainBlocks
.$select(emailDomainBlock.id)
Expand Down
2 changes: 1 addition & 1 deletion tests/rest/v1/admin/ip-blocks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ it("handles ip blocks", async () => {
expect(ipBlock.severity).toBe("sign_up_requires_approval");

const list = await admin.v1.admin.ipBlocks.list();
expect(list).toContainId(ipBlock.id);
expect(list).toContainEqual(ipBlock);
} finally {
await admin.v1.admin.ipBlocks.$select(ipBlock.id).remove();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/rest/v1/bookmarks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe("bookmarks", () => {
try {
await client.rest.v1.statuses.$select(status.id).bookmark();
const bookmarks = await client.rest.v1.bookmarks.list();
expect(bookmarks).toContainId(status.id);
expect(bookmarks).toContainEqual(status);
} finally {
await client.rest.v1.statuses.$select(status.id).unbookmark();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/rest/v1/conversations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("conversations", () => {
await bob.rest.v1.accounts.$select(alice.id).follow();

const status = await bob.rest.v1.statuses.create({
status: `@${alice.acct} Hi alice`,
status: `@${alice.account.acct} Hi alice`,
visibility: "direct",
});

Expand Down
2 changes: 1 addition & 1 deletion tests/rest/v1/favourites.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ it("list favourites", async () => {
try {
await client.rest.v1.statuses.$select(status.id).favourite();
const statuses = await client.rest.v1.favourites.list();
expect(statuses).toContainId(status.id);
expect(statuses).toContainEqual(status);
} finally {
await client.rest.v1.statuses.$select(status.id).remove();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/rest/v1/filters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ it("lists filters", async () => {
expect(filter.context).toEqual(["home", "notifications"]);

const filters = await client.rest.v1.filters.list();
expect(filters).toContainId(filter.id);
expect(filters).toContainEqual(filter);
} finally {
await client.rest.v1.filters.$select(filter.id).remove();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/rest/v1/lists.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ it("mutates a list", async () => {
list = await alice.rest.v1.lists.$select(list.id).fetch();

const lists = await alice.rest.v1.lists.list();
expect(lists).toContainId(list.id);
expect(lists).toContainEqual(list);

await alice.rest.v1.lists
.$select(list.id)
.accounts.create({ accountIds: [bob.id] });

const accounts = await alice.rest.v1.lists.$select(list.id).accounts.list();
expect(accounts).toContainId(bob.id);
expect(accounts).toContainEqual(bob);
} finally {
await alice.rest.v1.lists
.$select(list.id)
Expand Down
10 changes: 5 additions & 5 deletions tests/rest/v1/notifications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ it("handles notifications", async () => {
await using alice = await sessions.acquire();
await using bob = await sessions.acquire();
const status = await bob.rest.v1.statuses.create({
status: `@${alice.acct} Hello`,
status: `@${alice.account.acct} Hello`,
});

try {
Expand All @@ -28,7 +28,7 @@ it("handles notifications", async () => {
await alice.rest.v1.notifications.$select(notification.id).dismiss();

notifications = await alice.rest.v1.notifications.list();
expect(notifications).not.toContainId(notification.id);
expect(notifications).not.toContainEqual(notification);
} finally {
await alice.rest.v1.notifications.clear();
await bob.rest.v1.statuses.$select(status.id).remove();
Expand All @@ -40,13 +40,13 @@ it("clear notifications", async () => {
await using bob = await sessions.acquire();

const s1 = await bob.rest.v1.statuses.create({
status: `@${alice.acct} Hello 1`,
status: `@${alice.account.acct} Hello 1`,
});
const s2 = await bob.rest.v1.statuses.create({
status: `@${alice.acct} Hello 2`,
status: `@${alice.account.acct} Hello 2`,
});
const s3 = await bob.rest.v1.statuses.create({
status: `@${alice.acct} Hello 3`,
status: `@${alice.account.acct} Hello 3`,
});

try {
Expand Down
6 changes: 3 additions & 3 deletions tests/rest/v1/statuses.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ describe("status", () => {
const context = await client.rest.v1.statuses
.$select(s2.id)
.context.fetch();
expect(context.ancestors).toContainId(s1.id);
expect(context.descendants).toContainId(s3.id);
expect(context.ancestors).toContainEqual(s1);
expect(context.descendants).toContainEqual(s3);
} finally {
await client.rest.v1.statuses.$select(s1.id).remove();
await client.rest.v1.statuses.$select(s2.id).remove();
Expand Down Expand Up @@ -212,7 +212,7 @@ describe("status", () => {

const error = await alice.rest.v1.statuses
.create({
status: `@${bob.acct} hello`,
status: `@${bob.account.acct} hello`,
allowedMentions: [],
})
.then(
Expand Down
8 changes: 4 additions & 4 deletions tests/rest/v1/timelines.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("timeline", () => {
expect(statuses.map((s) => s.id)).toContain(status.id);
});

expect(statuses).toContainId(status.id);
expect(statuses).toContainEqual(status);
});

it("returns public", async () => {
Expand All @@ -37,7 +37,7 @@ describe("timeline", () => {
status: "public post",
});
const statuses = await alice.rest.v1.timelines.public.list();
expect(statuses).toContainId(status.id);
expect(statuses).toContainEqual(status);
});

it("returns hashtag", async () => {
Expand All @@ -48,7 +48,7 @@ describe("timeline", () => {
const statuses = await client.rest.v1.timelines.tag
.$select("mastodon")
.list();
expect(statuses).toContainId(status.id);
expect(statuses).toContainEqual(status);
});

it("returns hashtag in camel case", async () => {
Expand All @@ -60,7 +60,7 @@ describe("timeline", () => {
const statuses = await client.rest.v1.timelines.tag
.$select("CamelCase")
.list();
expect(statuses).toContainId(status.id);
expect(statuses).toContainEqual(status);
});

it("returns list", async () => {
Expand Down
6 changes: 3 additions & 3 deletions tests/rest/v2/filters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("filters", () => {
expect(filter.title).toBe("Filter Updated");

const filters = await session.rest.v2.filters.list();
expect(filters).toContainId(filter.id);
expect(filters).toContainEqual(filter);
} finally {
await session.rest.v2.filters.$select(filter.id).remove();
}
Expand Down Expand Up @@ -47,7 +47,7 @@ describe("filters", () => {
const keywords = await session.rest.v2.filters
.$select(filter.id)
.keywords.list();
expect(keywords).toContainId(keyword.id);
expect(keywords).toContainEqual(keyword);
await session.rest.v2.filters.keywords.$select(keyword.id).remove();
} finally {
await session.rest.v2.filters.$select(filter.id).remove();
Expand Down Expand Up @@ -79,7 +79,7 @@ describe("filters", () => {
const statusFilters = await session.rest.v2.filters
.$select(filter.id)
.statuses.list();
expect(statusFilters).toContainId(statusFilter.id);
expect(statusFilters).toContainEqual(statusFilter);
await session.rest.v2.filters.statuses.$select(statusFilter.id).remove();
} finally {
await session.rest.v2.filters.$select(filter.id).remove();
Expand Down
12 changes: 7 additions & 5 deletions tests/rest/v2/notifications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ describe("notification requests", () => {
forNotFollowing: "filter",
});

await bob.rest.v1.statuses.create({ status: `@${alice.acct} Hello` });
await bob.rest.v1.statuses.create({
status: `@${alice.account.acct} Hello`,
});

let requests!: mastodon.v1.NotificationRequest[];
await waitForExpect(async () => {
Expand Down Expand Up @@ -128,7 +130,7 @@ describe("notification requests", () => {
});

await bob.rest.v1.statuses.create({
status: `@${alice.acct} hello`,
status: `@${alice.account.acct} hello`,
});

await alice.rest.v1.notifications.requests.accept();
Expand Down Expand Up @@ -156,7 +158,7 @@ describe("notification requests", () => {
});

await bob.rest.v1.statuses.create({
status: `@${alice.acct} hello`,
status: `@${alice.account.acct} hello`,
});

await alice.rest.v1.notifications.requests.accept();
Expand Down Expand Up @@ -190,7 +192,7 @@ describe("notification requests", () => {
});

await bob.rest.v1.statuses.create({
status: `@${alice.acct} hello`,
status: `@${alice.account.acct} hello`,
});

let requests!: mastodon.v1.NotificationRequest[];
Expand Down Expand Up @@ -226,7 +228,7 @@ describe("notification requests", () => {
});

await bob.rest.v1.statuses.create({
status: `@${alice.acct} hello`,
status: `@${alice.account.acct} hello`,
});

let requests!: mastodon.v1.NotificationRequest[];
Expand Down
Loading

0 comments on commit cf42534

Please sign in to comment.