Skip to content

Commit

Permalink
Update GH Actions (#14)
Browse files Browse the repository at this point in the history
* add unittest step

* use nvmrc for `node-version`

* init playwright

* fix playwright action issue

* update artifact path

* headless only

* remove playwright

* init mock server

* explain how to run playwright tests
  • Loading branch information
noxify authored Dec 20, 2024
1 parent b9920c7 commit 3a54d4b
Show file tree
Hide file tree
Showing 14 changed files with 555 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ DISCORD_CLIENT_SECRET=""

# OAuth Mock
OAUTH_MOCK_ENABLED=false
#OAUTH_MOCK_ENDPOINT="http://localhost"
OAUTH_MOCK_ENDPOINT="http://localhost:8080"
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,14 @@ jobs:

- name: Typecheck
run: pnpm typecheck

unittest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup
uses: ./tooling/github/setup

- name: Unittest
run: pnpm test
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ This project is a monorepo based on turborepo.
├── apps
│ └── frontend - Contains the logic for the site
├── packages
│ ├── auth - Based on lucia-auth.com / same as we have at itaps monorepo
│ ├── auth - Based on lucia-auth.com
│ ├── db - Contains all the database related stuff ( prisma schema, migrations, seeds etc. )
│ ├── helpers - Helper functions 🤷‍♂️
│ ├── locales - contains the translations for the `frontend` app
Expand Down Expand Up @@ -85,11 +85,26 @@ This project is a monorepo based on turborepo.
## Todos

- [ ] Add unit tests
- [ ] Add more docs ( like how to activate/use mock users )
- [ ] Integrate https://github.com/sadmann7/shadcn-table to have an example
- [ ] Maybe: Adding a RBAC solution ( maybe via casl? )
- [ ] Add a contribution guide

## Running playwright tests

We have prepared some simple testcases to test the authentication in the nextjs app.

To make it runable inside a CI or locally, we're using an [oauth mock server](https://github.com/axa-group/oauth2-mock-server) to make it easier to run the tests and ensuring everything works as expected without having to add some magic to bypass the tests.

With this, we automatically test the authentication flow.

By running `pnpm dev`, the oauth mock server will start, too.

You only have to set `OAUTH_MOCK_ENABLED` to `true` in your `.env` file.

Last step is to open a new terminal tab and run `pnpm test:e2e:nextjs` to start the playwright tests.

You can find the complete playwright configuration in `tooling/playwright`.

## Credits

Without the amazing work of the [T3 OSS Community](https://github.com/t3-oss), this project wouldn't exists.
Expand Down
4 changes: 4 additions & 0 deletions apps/mock-server/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import baseConfig, { restrictEnvAccess } from "@acme/eslint-config/base"

/** @type {import('typescript-eslint').Config} */
export default [...baseConfig]
30 changes: 30 additions & 0 deletions apps/mock-server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "mock-server",
"version": "2.0.0",
"private": true,
"type": "module",
"scripts": {
"clean": "git clean -xdf .cache .turbo dist node_modules .next",
"clean:cache": "git clean -xdf .cache",
"dev": "tsx --watch src/server.ts",
"format": "prettier --check . --ignore-path ../../.gitignore",
"lint": "eslint .",
"typecheck": "tsc --noEmit"
},
"prettier": "@acme/prettier-config",
"dependencies": {
"@acme/logging": "workspace:*",
"oauth2-mock-server": "7.2.0"
},
"devDependencies": {
"@acme/eslint-config": "workspace:*",
"@acme/prettier-config": "workspace:*",
"@acme/tailwind-config": "workspace:*",
"@acme/tsconfig": "workspace:*",
"@types/node": "22.10.2",
"eslint": "9.17.0",
"prettier": "3.4.2",
"tsx": "4.19.2",
"typescript": "5.7.2"
}
}
10 changes: 10 additions & 0 deletions apps/mock-server/src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { OAuth2Server } from "oauth2-mock-server"

import { createLogger } from "@acme/logging"

const logger = createLogger("console")
const server = new OAuth2Server()
await server.issuer.keys.generate("RS256")

await server.start(8080, "localhost")
logger.info("Issuer URL:", server.issuer.url) // -> http://localhost:8080
16 changes: 16 additions & 0 deletions apps/mock-server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "@acme/tsconfig/base.json",
"compilerOptions": {
"lib": ["es2022", "dom", "dom.iterable"],
"jsx": "preserve",
"typeRoots": ["types"],
"baseUrl": ".",
"paths": {
"~/*": ["./src/*"]
},

"module": "esnext"
},
"include": [".", "dist/types/**/*.ts", "types"],
"exclude": ["node_modules"]
}
6 changes: 1 addition & 5 deletions apps/nextjs/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import playwrightConfig from "@acme/playwright"

const baseUrl = process.env.APPLICATION_URL
? `${process.env.APPLICATION_URL}`
: process.env.LOCAL_HTTPS
? "https://localhost:3000"
: "http://localhost:3000"
const baseUrl = process.env.APPLICATION_URL ?? "http://localhost:3000"

export default playwrightConfig({
basePath: "/",
Expand Down
15 changes: 0 additions & 15 deletions apps/nextjs/tests/a11y/initial.test.ts

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
"test": "vitest --project=unit",
"test:ui": "vitest --ui",
"prune": "turbo prune --docker",
"prepare_test": "turbo run build --filter @acme/* --filter !./apps/*",
"turbo": "turbo",
"test:e2e:frontend": "pnpm -F frontend test:e2e",
"test:e2e:nextjs": "pnpm -F nextjs test:e2e",
"playwright:init": "pnpm -F playwright test:init"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/providers/mock-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const callbackUrl = env.APPLICATION_URL

const oauthMock = new MockProvider("dummy-client-id", "dummy-client-secret", {
baseUrl: env.OAUTH_MOCK_ENDPOINT ?? "http://localhost",
redirectURI: `${callbackUrl}/api/auth/mock_user/callback`,
redirectURI: `${callbackUrl}`,
})

export const name = "Mock User"
Expand Down
Loading

0 comments on commit 3a54d4b

Please sign in to comment.