Skip to content

Commit

Permalink
Bulk convert remaining errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Apr 8, 2024
1 parent 2154d5b commit cdb0951
Show file tree
Hide file tree
Showing 31 changed files with 148 additions and 95 deletions.
1 change: 1 addition & 0 deletions apps/server/src/trpc/routes/entityCreate.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { db } from "@peated/server/db";
import waitError from "@peated/server/lib/test/waitError";
import { eq } from "drizzle-orm";
import { entities } from "../../db/schema";
import { createCaller } from "../router";
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/trpc/routes/entityDelete.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import waitError from "@peated/server/lib/test/waitError";
import { eq } from "drizzle-orm";
import { db } from "../../db";
import { entities } from "../../db/schema";
Expand Down
11 changes: 7 additions & 4 deletions apps/server/src/trpc/routes/entityMerge.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import { db } from "@peated/server/db";
import { entities, entityTombstones } from "@peated/server/db/schema";
import waitError from "@peated/server/lib/test/waitError";
import { eq } from "drizzle-orm";
import { createCaller } from "../router";

test("requires authentication", async () => {
const caller = createCaller({ user: null });
expect(() =>
const err = await waitError(
caller.entityMerge({
root: 1,
other: 2,
}),
).rejects.toThrowError(/UNAUTHORIZED/);
);
expect(err).toMatchInlineSnapshot();
});

test("requires mod", async ({ defaults }) => {
const caller = createCaller({ user: defaults.user });
expect(() =>
const err = await waitError(
caller.entityMerge({
root: 1,
other: 2,
}),
).rejects.toThrowError(/UNAUTHORIZED/);
);
expect(err).toMatchInlineSnapshot();
});

test("merge A into B", async ({ fixtures }) => {
Expand Down
11 changes: 7 additions & 4 deletions apps/server/src/trpc/routes/entityUpdate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,28 @@ import {
entities,
} from "@peated/server/db/schema";
import { omit } from "@peated/server/lib/filter";
import waitError from "@peated/server/lib/test/waitError";
import { desc, eq } from "drizzle-orm";
import { createCaller } from "../router";

test("requires authentication", async () => {
const caller = createCaller({ user: null });
expect(() =>
const err = await waitError(
caller.entityUpdate({
entity: 1,
}),
).rejects.toThrowError(/UNAUTHORIZED/);
);
expect(err).toMatchInlineSnapshot();
});

test("requires mod", async ({ defaults }) => {
const caller = createCaller({ user: defaults.user });
expect(() =>
const err = await waitError(
caller.entityUpdate({
entity: 1,
}),
).rejects.toThrowError(/UNAUTHORIZED/);
);
expect(err).toMatchInlineSnapshot();
});

test("no changes", async ({ fixtures }) => {
Expand Down
6 changes: 4 additions & 2 deletions apps/server/src/trpc/routes/externalSiteConfigGet.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { db } from "@peated/server/db";
import { externalSiteConfig } from "@peated/server/db/schema";
import waitError from "@peated/server/lib/test/waitError";
import { createCaller } from "../router";

test("requires admin", async ({ fixtures }) => {
const site = await fixtures.ExternalSite();
const caller = createCaller({
user: await fixtures.User({ mod: true }),
});
expect(() =>
const err = await waitError(
caller.externalSiteConfigGet({
site: site.type,
key: "test",
}),
).rejects.toThrowError(/UNAUTHORIZED/);
);
expect(err).toMatchInlineSnapshot();
});

test("get missing value", async ({ fixtures }) => {
Expand Down
6 changes: 4 additions & 2 deletions apps/server/src/trpc/routes/externalSiteConfigSet.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { db } from "@peated/server/db";
import { externalSiteConfig } from "@peated/server/db/schema";
import waitError from "@peated/server/lib/test/waitError";
import { eq } from "drizzle-orm";
import { createCaller } from "../router";

Expand All @@ -8,13 +9,14 @@ test("requires admin", async ({ fixtures }) => {
const caller = createCaller({
user: await fixtures.User({ mod: true }),
});
expect(() =>
const err = await waitError(
caller.externalSiteConfigSet({
site: site.type,
key: "test",
value: "test",
}),
).rejects.toThrowError(/UNAUTHORIZED/);
);
expect(err).toMatchInlineSnapshot();
});

test("set new value", async ({ fixtures }) => {
Expand Down
6 changes: 4 additions & 2 deletions apps/server/src/trpc/routes/externalSiteCreate.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import waitError from "@peated/server/lib/test/waitError";
import { createCaller } from "../router";

test("requires admin", async ({ fixtures }) => {
const caller = createCaller({
user: await fixtures.User({ mod: true }),
});
expect(() =>
const err = await waitError(
caller.externalSiteCreate({
name: "Whisky Advocate",
type: "whiskyadvocate",
}),
).rejects.toThrowError(/UNAUTHORIZED/);
);
expect(err).toMatchInlineSnapshot();
});

test("triggers job", async ({ fixtures }) => {
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/trpc/routes/externalSiteTriggerJob.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as jobs from "@peated/server/jobs/client";
import waitError from "@peated/server/lib/test/waitError";
import { createCaller } from "../router";

test("requires admin", async ({ fixtures }) => {
const site = await fixtures.ExternalSite({ type: "whiskyadvocate" });
const caller = createCaller({
user: await fixtures.User({ mod: true }),
});
expect(() => caller.externalSiteTriggerJob(site.type)).rejects.toThrowError(
/UNAUTHORIZED/,
);
const err = await waitError(caller.externalSiteTriggerJob(site.type));
expect(err).toMatchInlineSnapshot();
});

test("triggers job", async ({ fixtures }) => {
Expand Down
6 changes: 4 additions & 2 deletions apps/server/src/trpc/routes/externalSiteUpdate.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import waitError from "@peated/server/lib/test/waitError";
import { createCaller } from "../router";

test("requires admin", async ({ fixtures }) => {
const site = await fixtures.ExternalSite();
const caller = createCaller({
user: await fixtures.User({ mod: true }),
});
expect(() =>
const err = await waitError(
caller.externalSiteUpdate({
site: site.type,
}),
).rejects.toThrowError(/UNAUTHORIZED/);
);
expect(err).toMatchInlineSnapshot();
});

test("updates site", async ({ fixtures }) => {
Expand Down
4 changes: 3 additions & 1 deletion apps/server/src/trpc/routes/flightById.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import waitError from "@peated/server/lib/test/waitError";
import { createCaller } from "../router";

test("get flight by id", async ({ fixtures }) => {
Expand All @@ -10,5 +11,6 @@ test("get flight by id", async ({ fixtures }) => {

test("errors on invalid flight", async () => {
const caller = createCaller({ user: null });
expect(() => caller.flightById("123")).rejects.toThrowError(/NOT_FOUND/);
const err = await waitError(caller.flightById("123"));
expect(err).toMatchInlineSnapshot();
});
6 changes: 4 additions & 2 deletions apps/server/src/trpc/routes/flightCreate.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { db } from "@peated/server/db";
import waitError from "@peated/server/lib/test/waitError";
import { eq } from "drizzle-orm";
import { flights } from "../../db/schema";
import { createCaller } from "../router";

test("requires authentication", async () => {
const caller = createCaller({ user: null });
expect(() =>
const err = await waitError(
caller.flightCreate({
name: "Delicious Wood",
}),
).rejects.toThrowError(/UNAUTHORIZED/);
);
expect(err).toMatchInlineSnapshot();
});

test("creates a new flight", async ({ defaults }) => {
Expand Down
11 changes: 7 additions & 4 deletions apps/server/src/trpc/routes/flightUpdate.test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import { db } from "@peated/server/db";
import { flightBottles, flights } from "@peated/server/db/schema";
import { omit } from "@peated/server/lib/filter";
import waitError from "@peated/server/lib/test/waitError";
import { eq } from "drizzle-orm";
import { createCaller } from "../router";

test("requires authentication", async () => {
const caller = createCaller({ user: null });
expect(() =>
const err = await waitError(
caller.flightUpdate({
flight: "1",
}),
).rejects.toThrowError(/UNAUTHORIZED/);
);
expect(err).toMatchInlineSnapshot();
});

test("requires mod", async ({ defaults, fixtures }) => {
const flight = await fixtures.Flight();

const caller = createCaller({ user: defaults.user });
expect(() =>
const err = await waitError(
caller.flightUpdate({
flight: flight.publicId,
}),
).rejects.toThrowError(/Cannot update another user's flight./);
);
expect(err).toMatchInlineSnapshot();
});

test("no changes", async ({ fixtures }) => {
Expand Down
11 changes: 5 additions & 6 deletions apps/server/src/trpc/routes/friendCreate.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { db } from "@peated/server/db";
import waitError from "@peated/server/lib/test/waitError";
import { and, eq } from "drizzle-orm";
import { follows, notifications } from "../../db/schema";
import { createCaller } from "../router";

test("requires authentication", async ({ defaults }) => {
const caller = createCaller({ user: null });
expect(() => caller.friendCreate(defaults.user.id)).rejects.toThrowError(
/UNAUTHORIZED/,
);
const err = await waitError(caller.friendCreate(defaults.user.id));
expect(err).toMatchInlineSnapshot();
});

test("cannot friend self", async ({ defaults }) => {
const caller = createCaller({ user: defaults.user });
expect(() => caller.friendCreate(defaults.user.id)).rejects.toThrowError(
/Cannot friend yourself/,
);
const err = await waitError(caller.friendCreate(defaults.user.id));
expect(err).toMatchInlineSnapshot();
});

test("can friend new link", async ({ defaults, fixtures }) => {
Expand Down
9 changes: 5 additions & 4 deletions apps/server/src/trpc/routes/friendDelete.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { db } from "@peated/server/db";
import { follows } from "@peated/server/db/schema";
import waitError from "@peated/server/lib/test/waitError";
import { and, eq } from "drizzle-orm";
import { createCaller } from "../router";

test("requires authentication", async () => {
const caller = createCaller({ user: null });
expect(() => caller.friendDelete(1)).rejects.toThrowError(/UNAUTHORIZED/);
const err = await waitError(caller.friendDelete(1));
expect(err).toMatchInlineSnapshot();
});

test("cannot unfriend self", async ({ defaults }) => {
const caller = createCaller({ user: defaults.user });
expect(() => caller.friendDelete(defaults.user.id)).rejects.toThrowError(
/Cannot unfriend yourself/,
);
const err = await waitError(caller.friendDelete(defaults.user.id));
expect(err).toMatchInlineSnapshot();
});

test("can unfriend new link", async ({ defaults, fixtures }) => {
Expand Down
4 changes: 3 additions & 1 deletion apps/server/src/trpc/routes/friendList.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import waitError from "@peated/server/lib/test/waitError";
import { createCaller } from "../router";

test("lists friends", async ({ defaults, fixtures }) => {
Expand All @@ -15,5 +16,6 @@ test("lists friends", async ({ defaults, fixtures }) => {

test("requires authentication", async () => {
const caller = createCaller({ user: null });
expect(() => caller.friendList()).rejects.toThrowError(/UNAUTHORIZED/);
const err = await waitError(caller.friendList());
expect(err).toMatchInlineSnapshot();
});
16 changes: 7 additions & 9 deletions apps/server/src/trpc/routes/notificationDelete.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { db } from "@peated/server/db";
import { notifications } from "@peated/server/db/schema";
import waitError from "@peated/server/lib/test/waitError";
import { eq } from "drizzle-orm";
import { createCaller } from "../router";

test("requires authentication", async () => {
const caller = createCaller({ user: null });
expect(() => caller.notificationDelete(1)).rejects.toThrowError(
/UNAUTHORIZED/,
);
const err = await waitError(caller.notificationDelete(1));
expect(err).toMatchInlineSnapshot();
});

test("invalid notification", async ({ defaults }) => {
const caller = createCaller({ user: defaults.user });
expect(() => caller.notificationDelete(1)).rejects.toThrowError(
/Notification not found/,
);
const err = await waitError(caller.notificationDelete(1));
expect(err).toMatchInlineSnapshot();
});

test("delete own notification", async ({ defaults, fixtures }) => {
Expand Down Expand Up @@ -52,7 +51,6 @@ test("cannot delete others notification", async ({ defaults, fixtures }) => {
.returning();

const caller = createCaller({ user: defaults.user });
expect(() => caller.notificationDelete(notification.id)).rejects.toThrowError(
/Cannot delete another user's notification/,
);
const err = await waitError(caller.notificationDelete(notification.id));
expect(err).toMatchInlineSnapshot();
});
11 changes: 7 additions & 4 deletions apps/server/src/trpc/routes/notificationUpdate.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { db } from "@peated/server/db";
import { notifications } from "@peated/server/db/schema";
import waitError from "@peated/server/lib/test/waitError";
import { eq } from "drizzle-orm";
import { createCaller } from "../router";

test("requires authentication", async () => {
const caller = createCaller({ user: null });
expect(() =>
const err = await waitError(
caller.notificationUpdate({
notification: 1,
}),
).rejects.toThrowError(/UNAUTHORIZED/);
);
expect(err).toMatchInlineSnapshot();
});

test("mark own notification as read", async ({ defaults, fixtures }) => {
Expand Down Expand Up @@ -52,10 +54,11 @@ test("cannot update others notification", async ({ defaults, fixtures }) => {
.returning();

const caller = createCaller({ user: defaults.user });
expect(() =>
const err = await waitError(
caller.notificationUpdate({
notification: notification.id,
read: true,
}),
).rejects.toThrowError(/Cannot edit another user's notification/);
);
expect(err).toMatchInlineSnapshot();
});
Loading

0 comments on commit cdb0951

Please sign in to comment.