Skip to content

Commit

Permalink
Merge pull request #30 from joshuaisaact/pino
Browse files Browse the repository at this point in the history
feat: implemented pino for logging and errors. full refactor. need to update tests before merge
  • Loading branch information
joshuaisaact authored Nov 22, 2024
2 parents 96ec145 + c84798f commit f797d5b
Show file tree
Hide file tree
Showing 104 changed files with 4,593 additions and 3,028 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Integration Tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
integration-tests:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpassword
POSTGRES_DB: testdb
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4

- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'

- name: Cache node_modules
uses: actions/cache@v4
id: npm-cache
with:
path: |
**/node_modules
~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
if: steps.npm-cache.outputs.cache-hit != 'true'
run: npm ci

- name: Set environment variables
env:
SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
TEST_DATABASE_URL: ${{ secrets.TEST_DATABASE_URL }}
TEST_USER_UUID: ${{ secrets.TEST_USER_UUID }}
run: |
echo "SUPABASE_ANON_KEY=${SUPABASE_ANON_KEY}" >> $GITHUB_ENV
echo "SUPABASE_URL=${SUPABASE_URL}" >> $GITHUB_ENV
echo "TEST_DATABASE_URL=${TEST_DATABASE_URL}" >> $GITHUB_ENV
echo "DATABASE_URL=${TEST_DATABASE_URL}" >> $GITHUB_ENV
echo "TEST_USER_UUID=${TEST_USER_UUID}" >> $GITHUB_ENV
- name: Generate test migrations
run: npm run drizzle:generate:test
env:
NODE_ENV: test

- name: Run test migrations
run: npm run drizzle:migrate:test
env:
NODE_ENV: test
DATABASE_URL: postgresql://testuser:testpassword@localhost:5432/testdb

- name: Run integration tests with coverage
run: |
npm run test:integration -- --coverage --verbose --runInBand --detectOpenHandles
env:
NODE_ENV: test
DATABASE_URL: postgresql://testuser:testpassword@localhost:5432/testdb

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
37 changes: 0 additions & 37 deletions .github/workflows/tests.yml

This file was deleted.

54 changes: 54 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Unit Tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
unit-tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'

- name: Cache node_modules
uses: actions/cache@v4
id: npm-cache
with:
path: |
**/node_modules
~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
if: steps.npm-cache.outputs.cache-hit != 'true'
run: npm ci

- name: Set environment variables
env:
SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
TEST_DATABASE_URL: ${{ secrets.TEST_DATABASE_URL }}
run: |
echo "SUPABASE_ANON_KEY=${SUPABASE_ANON_KEY}" >> $GITHUB_ENV
echo "SUPABASE_URL=${SUPABASE_URL}" >> $GITHUB_ENV
echo "TEST_DATABASE_URL=${TEST_DATABASE_URL}" >> $GITHUB_ENV
echo "DATABASE_URL=${TEST_DATABASE_URL}" >> $GITHUB_ENV
- name: Run unit tests with coverage
run: npm run test:unit -- --coverage

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
postgres:
image: postgres:latest
container_name: test_postgres
environment:
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpassword
POSTGRES_DB: testdb
ports:
- '5432:5432'
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
17 changes: 6 additions & 11 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@ import { defineConfig } from 'drizzle-kit';

dotenv.config();

const isTestEnv = process.env.NODE_ENV === 'test';

if (!isTestEnv && !process.env.SUPABASE_URL) {
throw new Error('SUPABASE_URL is required in non-test environments');
}

const TEST_DB_URL = 'postgres://test_user:test_password@localhost:5433/test_db';

export default defineConfig({
out: './drizzle',
schema: './src/db/tables/**/*.ts',
out: './drizzle/pg',
schema: './src/db/tables/*.ts',
dialect: 'postgresql',
dbCredentials: {
url: isTestEnv ? TEST_DB_URL : process.env.SUPABASE_URL!,
url: process.env.SUPABASE_URL!,
},
verbose: true,
strict: true,
tablesFilter: ['!_*'],
});
19 changes: 19 additions & 0 deletions drizzle.test.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
out: './drizzle', // Directory to output the migration files
schema: './src/db/tables/*.ts', // Path to your test schema (same as production schema)
dialect: 'postgresql', // Use PostgreSQL since you're using pgmem (in-memory PostgreSQL)
dbCredentials: {
url:
process.env.TEST_DATABASE_URL ||
'postgres://testuser:testpassword@localhost:5432/testdb', // Connection string (pgmem creates an in-memory PostgreSQL database)
},
verbose: true,
strict: false,
migrations: {
prefix: 'timestamp', // Migration file prefix
table: '__drizzle_migrations__', // Table to track migrations
schema: 'public', // Schema to use for migrations
},
});
20 changes: 10 additions & 10 deletions drizzle/0000_cynical_betty_brant.sql
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
CREATE TABLE IF NOT EXISTS "activities" (
"activity_id" serial PRIMARY KEY NOT NULL,
"activity_id" serial ,
"activity_name" text,
"description" text,
"location" text,
"latitude" numeric,
"longitude" numeric,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"created_at" timestamp with time zone DEFAULT now() ,
"price" text,
"location_id" integer
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "destinations" (
"destination_id" serial PRIMARY KEY NOT NULL,
"destination_name" text NOT NULL,
"destination_id" serial,
"destination_name" text,
"latitude" numeric,
"longitude" numeric,
"description" text,
"country" text,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"created_at" timestamp with time zone DEFAULT now() ,
"best_time_to_visit" varchar,
"average_temperature_low" text,
"average_temperature_high" text,
Expand All @@ -36,18 +36,18 @@ CREATE TABLE IF NOT EXISTS "destinations" (
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "itinerary_days" (
"day_id" serial PRIMARY KEY NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"day_id" serial ,
"created_at" timestamp with time zone DEFAULT now() ,
"trip_id" bigint,
"day_number" bigint,
"activity_id" bigint
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "trips" (
"trip_id" serial PRIMARY KEY NOT NULL,
"user_id" uuid NOT NULL,
"trip_id" serial ,
"user_id" uuid ,
"destination_id" bigint,
"start_date" timestamp with time zone,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"created_at" timestamp with time zone DEFAULT now() ,
"num_days" bigint
);
69 changes: 69 additions & 0 deletions drizzle/0001_yummy_bloodstorm.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
CREATE TABLE `activities` (
`activity_id` integer AUTOINCREMENT,
`activity_name` text,
`description` text,
`location` text,
`latitude` real,
`longitude` real,
`created_at` text DEFAULT CURRENT_TIMESTAMP,
`price` text,
`location_id` integer,
`duration` text,
`difficulty` text,
`category` text,
`best_time` text
);
--> statement-breakpoint
CREATE TABLE `destinations` (
`destination_id` integer AUTOINCREMENT,
`destination_name` text,
`normalized_name` text,
`latitude` real,
`longitude` real,
`description` text,
`country` text,
`created_at` text DEFAULT CURRENT_TIMESTAMP,
`best_time_to_visit` text,
`average_temperature_low` text,
`average_temperature_high` text,
`popular_activities` text,
`travel_tips` text,
`nearby_attractions` text,
`transportation_options` text,
`accessibility_info` text,
`official_language` text,
`currency` text,
`local_cuisine` text,
`cost_level` text,
`safety_rating` text,
`cultural_significance` text,
`user_ratings` text
);
--> statement-breakpoint
CREATE UNIQUE INDEX `destinations_normalized_name_unique` ON `destinations` (`normalized_name`);--> statement-breakpoint
CREATE TABLE `itinerary_days` (
`day_id` integer AUTOINCREMENT,
`created_at` text DEFAULT CURRENT_TIMESTAMP,
`trip_id` integer,
`day_number` integer,
`activity_id` integer
);
--> statement-breakpoint
CREATE TABLE `saved_destinations` (
`id` integer AUTOINCREMENT,
`user_id` text,
`destination_id` integer,
`created_at` text DEFAULT CURRENT_TIMESTAMP,
`notes` text,
`is_visited` integer DEFAULT false,
FOREIGN KEY (`destination_id`) REFERENCES `destinations`(`destination_id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `trips` (
`trip_id` integer AUTOINCREMENT,
`user_id` text,
`destination_id` integer,
`start_date` text,
`created_at` text DEFAULT CURRENT_TIMESTAMP,
`num_days` integer
);
Loading

0 comments on commit f797d5b

Please sign in to comment.