Skip to content

Commit

Permalink
feat(test): test suite implementation #23
Browse files Browse the repository at this point in the history
  • Loading branch information
KaungWai committed Feb 14, 2024
1 parent 39073b0 commit a2e4899
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ENVIRONMENT=development
ALLOWED_ORIGINS=localhost:3333,example.com

# absolute paths to jwt keys
JWT_SECRET=/Users/kaungwai/Projects/003_KickstartFastify/kickstart-fastify/keys/jwtsecret
JWT_SECRET=/absolute-path-to/jwtsecret

# This was inserted by `prisma init`:
# Environment variables declared in this file are automatically made available to Prisma.
Expand Down
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ENVIRONMENT=test
ALLOWED_ORIGINS=localhost:3333,example.com

# absolute paths to jwt keys
JWT_SECRET=/Users/kaungwai/Projects/003_KickstartFastify/kickstart-fastify/keys/jwtsecret
JWT_SECRET=/absolute-path-to/jwtsecret

# This was inserted by `prisma init`:
# Environment variables declared in this file are automatically made available to Prisma.
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: 16

- name: Set up PostgreSQL
run: docker-compose up -d

- name: Install dependencies
run: npm install

- name: Generate jwt secret
run: npm run script.keygen

- name: Run tests
run: npm test
5 changes: 4 additions & 1 deletion src/plugins/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import fastifyJwt, { FastifyJWTOptions } from '@fastify/jwt'
import { FastifyInstance, FastifyPluginOptions } from 'fastify'
import fs from 'fastify-plugin'
import { readFileSync } from 'fs'
import path from 'path'

import { SYS_CONSTANTS } from '@/constants/systemConstants'
import env from '@/utils/env'

const secretPath = env.ENVIRONMENT === 'test' ? path.join(__dirname, '../../../keys/jwtsecret') : env.JWT_SECRET

// read key files
const jwtSecret = readFileSync(env.JWT_SECRET, { encoding: SYS_CONSTANTS.DEFAULT_ENCODING })
const jwtSecret = readFileSync(secretPath, { encoding: SYS_CONSTANTS.DEFAULT_ENCODING })

// jwt options
const jwtOptins: FastifyJWTOptions = {
Expand Down

0 comments on commit a2e4899

Please sign in to comment.