Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Apr 9, 2024
1 parent c781a5b commit b22fa33
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
16 changes: 16 additions & 0 deletions apps/server/src/lib/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
bottles,
bottlesToDistillers,
changes,
collections,
comments,
entities,
externalSites,
Expand Down Expand Up @@ -521,6 +522,21 @@ export const Review = async (
return result;
};

export const Collection = async (
{ ...data }: Partial<Omit<dbSchema.NewCollection, "id">> = {},
db: DatabaseType = dbConn,
): Promise<dbSchema.Collection> => {
const [result] = await db
.insert(collections)
.values({
name: faker.company.name(),
...(data as Omit<dbSchema.NewCollection, "name">),
})
.returning();
if (!result) throw new Error("Unable to create fixture");
return result;
};

export const AuthToken = async (
{ user }: { user?: dbSchema.User | null } = {},
db: DatabaseType = dbConn,
Expand Down
12 changes: 11 additions & 1 deletion apps/server/src/trpc/routes/collectionBottleDelete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ test("requires auth", async () => {
test("delete bottle in default", async ({ fixtures, defaults }) => {
const bottle = await fixtures.Bottle();

const collection = await fixtures.Collection({
name: "default",
createdById: defaults.user.id,
});

await db.insert(collectionBottles).values({
bottleId: bottle.id,
collectionId: collection.id,
});

const caller = createCaller({
user: defaults.user,
});
Expand All @@ -35,5 +45,5 @@ test("delete bottle in default", async ({ fixtures, defaults }) => {
.from(collectionBottles)
.where(eq(collectionBottles.bottleId, bottle.id));

expect(bottleList.length).toBe(1);
expect(bottleList.length).toBe(0);
});

0 comments on commit b22fa33

Please sign in to comment.