Skip to content

Commit

Permalink
test: Write backend tests for auth, userQuests, userSettings, a…
Browse files Browse the repository at this point in the history
…nd `users` (#274)
  • Loading branch information
evadecker authored Dec 10, 2024
1 parent 3a731ed commit 53d3ee9
Show file tree
Hide file tree
Showing 9 changed files with 1,000 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ frontend:

testing:
- changed-files:
- any-glob-to-any-file: ['tests/**', '**.test.{ts,tsx}', 'playwright.config.ts']
- any-glob-to-any-file: ['tests/**', '**/*.test.ts', '**/*.test.tsx', 'playwright.config.ts']

workflows:
- changed-files:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Pull Request Labeler
name: PR Labeler
on:
- pull_request_target

jobs:
labeler:
name: Labeler
permissions:
contents: read
pull-requests: write
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/relative-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ permissions:

jobs:
build:
name: Build and report bundle stats
name: Report Bundle Size
runs-on: ubuntu-latest

steps:
Expand Down
39 changes: 39 additions & 0 deletions convex/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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");
});
});
});
Loading

0 comments on commit 53d3ee9

Please sign in to comment.