Skip to content

Commit

Permalink
feat: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartek532 committed Nov 13, 2024
1 parent 8fb4e13 commit 4ba47f9
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 8 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ jobs:
- name: 🛻 Lint
run: bun lint

- name: 🧪 Typecheck
- name: 💡 Typecheck
run: bun typecheck

- name: 🧪 Unit tests
run: bun test
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@

Everything you need to build a production ready browser extension, it's an **opinionated** stack based on learnings from building multiple browser extensions using the latest React framework. It's a starter kit with a focus on code reuse and best practices that will grow with your business.

> [!NOTE]
> This project is listed on [Awesome Open Source Boilerplates](https://github.com/EinGuterWaran/awesome-opensource-boilerplates) and [Awesome SaaS Boilerplates](https://github.com/smirnov-am/awesome-saas-boilerplates)

> [!TIP]
> Sharing storage and authentication session between all pages
>
Expand All @@ -58,6 +62,7 @@
- 🌍 Internationalization
- 📊 Analytics
- ✨ Linting and formatting
- 🧪 Unit tests
- 🔄 CI/CD pipelines
- ⚙️ Environment variables
- 🎨 shadcn/ui compatible
Expand Down
Binary file modified bun.lockb
Binary file not shown.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
"author": "Bartosz Zagrodzki",
"scripts": {
"build": "run-p build:chrome build:firefox",
"build:chrome": "bun with-app-dir plasmo build --zip",
"build:firefox": "bun with-app-dir plasmo build --target=firefox-mv2 --zip",
"build:chrome": "plasmo build --src-path=src/app --zip",
"build:firefox": "plasmo build --src-path=src/app --target=firefox-mv2 --zip",
"dev": "bun dev:chrome",
"dev:chrome": "bun with-app-dir plasmo dev",
"dev:firefox": "bun with-app-dir plasmo dev --target=firefox-mv2",
"dev:chrome": "plasmo dev --src-path=src/app",
"dev:firefox": "plasmo dev --src-path=src/app --target=firefox-mv2",
"lint": "biome check",
"lint:fix": "biome check --write",
"prepare": "husky",
"typecheck": "tsc --noEmit",
"with-app-dir": "sh -c 'if [[ \"$*\" != *--src-path=* ]]; then set -- $@ --src-path=src/app; fi; exec $@' --"
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@biomejs/biome": "^1.9.4",
Expand All @@ -40,7 +39,7 @@
"marked": "^14.1.3",
"next-themes": "^0.3.0",
"npm-run-all": "^4.1.5",
"plasmo": "0.89.3",
"plasmo": "0.89.4",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-hook-form": "^7.53.1",
Expand All @@ -55,6 +54,7 @@
"@commitlint/types": "19.0.3",
"@tailwindcss/typography": "^0.5.15",
"@total-typescript/ts-reset": "^0.6.1",
"@types/bun": "latest",
"@types/chrome": "0.0.270",
"@types/node": "20.16.10",
"@types/react": "^18.3.3",
Expand Down
71 changes: 71 additions & 0 deletions src/lib/tests/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { describe, expect, it } from "bun:test";
import { getAvatar, getName } from "~/lib/utils";
import type { User } from "~/types";

describe("getName", () => {
it("returns user_metadata.name when available", () => {
const user = {
user_metadata: { name: "John Doe" },
identities: [],
} as unknown as User;

expect(getName(user)).toBe("John Doe");
});

it("returns identity name when user_metadata.name is not available", () => {
const user = {
user_metadata: {},
identities: [{ identity_data: { name: "John Smith" } }],
} as unknown as User;

expect(getName(user)).toBe("John Smith");
});

it("returns name from email when no other name is available", () => {
const user = {
user_metadata: {},
identities: [],
email: "[email protected]",
} as unknown as User;

expect(getName(user)).toBe("john.doe");
});

it("returns undefined when no name source is available", () => {
const user = {
user_metadata: {},
identities: [],
} as unknown as User;

expect(getName(user)).toBeUndefined();
});
});

describe("getAvatar", () => {
it("returns identity avatar_url when available", () => {
const avatarUrl = "https://example.com/avatar.jpg";
const user = {
user_metadata: {},
identities: [{ identity_data: { avatar_url: avatarUrl } }],
} as unknown as User;

expect(getAvatar(user)).toBe(avatarUrl);
});

it("returns user_metadata avatar_url when identity avatar is not available", () => {
const avatarUrl = "https://example.com/avatar.jpg";
const user = {
user_metadata: { avatar_url: avatarUrl },
identities: [],
} as unknown as User;
expect(getAvatar(user)).toBe(avatarUrl);
});

it("returns undefined when no avatar is available", () => {
const user = {
user_metadata: {},
identities: [],
} as unknown as User;
expect(getAvatar(user)).toBeUndefined();
});
});

0 comments on commit 4ba47f9

Please sign in to comment.