-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Write backend tests for
auth
, userQuests
, userSettings
, a…
…nd `users` (#274)
- Loading branch information
Showing
9 changed files
with
1,000 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,25 @@ import { modules } from "./test.setup"; | |
|
||
describe("auth", () => { | ||
describe("createOrUpdateUser", () => { | ||
it("should return existing user if id already exists", async () => { | ||
const t = convexTest(schema, modules); | ||
|
||
const userId = await t.run(async (ctx) => { | ||
return await ctx.db.insert("users", { | ||
email: "[email protected]", | ||
role: "user", | ||
}); | ||
}); | ||
|
||
const user = await t.run(async (ctx) => { | ||
return await createOrUpdateUser(ctx, { | ||
existingUserId: userId, | ||
}); | ||
}); | ||
|
||
expect(user).toBe(userId); | ||
}); | ||
|
||
it("should set role to admin in development environment", async () => { | ||
const t = convexTest(schema, modules); | ||
|
||
|
@@ -46,5 +65,25 @@ describe("auth", () => { | |
expect(user?.role).toBe("user"); | ||
vi.unstubAllEnvs(); | ||
}); | ||
|
||
it("should initialize default user settings", async () => { | ||
const t = convexTest(schema, modules); | ||
|
||
const userId = await t.run(async (ctx) => { | ||
return await createOrUpdateUser(ctx, { | ||
profile: { | ||
email: "[email protected]", | ||
}, | ||
}); | ||
}); | ||
|
||
const userSettings = await t.query(api.userSettings.getByUserId, { | ||
userId, | ||
}); | ||
|
||
expect(userSettings).toBeDefined(); | ||
expect(userSettings?.theme).toBe("system"); | ||
expect(userSettings?.groupQuestsBy).toBe("dateAdded"); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.