Skip to content

Commit 6377885

Browse files
Merge pull request #33 from echelonnought/fix/db-test-config-errors
fix: fixed pg db command errors when running tests and logger errors
2 parents cc81d4c + d9552a4 commit 6377885

File tree

7 files changed

+80
-6
lines changed

7 files changed

+80
-6
lines changed

.env.example

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# App Configuration
2+
NODE_ENV=development
3+
PORT=7000
4+
APP_URL=http://localhost:7000
5+
6+
# Database
7+
POSTGRES_HOST=postgres
8+
POSTGRES_PORT=5432
9+
POSTGRES_USER=postgres
10+
POSTGRES_PASSWORD=postgres
11+
POSTGRES_DB=chatbot
12+
13+
# Auth0 Configuration
14+
AUTH0_DOMAIN=your-domain.auth0.com
15+
AUTH0_CLIENT_ID=your-client-id
16+
AUTH0_CLIENT_SECRET=your-client-secret
17+
AUTH0_AUDIENCE=your-api-audience
18+
AUTH0_ISSUER_BASE_URL=https://your-domain.auth0.com
19+
20+
# Twilio Configuration
21+
TWILIO_ACCOUNT_SID=your-account-sid
22+
TWILIO_AUTH_TOKEN=your-auth-token
23+
TWILIO_PHONE_NUMBER=your-twilio-number
24+
25+
# EdX API
26+
EDX_API_KEY=your_edx_api_key
27+
EDX_API_URL=https://api.edx.org
28+
EDX_CLIENT_ID=your_client_id
29+
EDX_CLIENT_SECRET=your_client_secret
30+
31+
# AI Service
32+
AI_API_KEY=your_ai_api_key
33+
AI_MODEL=gpt-4

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
"db:create-model": "sequelize model:generate",
1919
"db:drop": "sequelize db:drop",
2020
"db:migrate": "sequelize db:migrate",
21-
"db:migrate:test": "NODE_ENV=test pnpm db:migrate",
21+
"db:drop:test": "node .jest/jest.global-setup.js",
22+
"db:create:test": "node .jest/jest.global-setup.js",
23+
"db:migrate:test": "node .jest/jest.global-setup.js",
2224
"db:generate-migration": "sequelize migration:generate",
2325
"db:undo-migration": "sequelize db:migrate:undo",
2426
"db:rollback-migrations": "sequelize db:migrate:undo:all",

scripts/init-dev.sh

100644100755
File mode changed.

scripts/stop.sh

100644100755
File mode changed.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// this should be the imported module for the test
2+
function sum(a, b) {
3+
return a + b;
4+
}
5+
6+
// Test case 1: Basic addition
7+
test('adds 1 + 2 to equal 3', () => {
8+
expect(sum(1, 2)).toBe(3);
9+
});
10+
11+
// Test case 2: Negative numbers
12+
test('adds -1 + (-1) to equal -2', () => {
13+
expect(sum(-1, -1)).toBe(-2);
14+
});
15+
16+
// Test case 3: Zero handling
17+
test('adds 0 + 5 to equal 5', () => {
18+
expect(sum(0, 5)).toBe(5);
19+
});

src/config/database.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ const { Sequelize } = require('sequelize');
22
const logger = require('../config/logger');
33
const { initializeModels } = require('../models');
44
const config = require('./config');
5-
const envConfig = require('./sequelize-cli.config')[config.env];
5+
6+
// Load configuration
7+
const env = config.env || 'development';
8+
const envConfig = require('./sequelize-cli.config')[env];
9+
10+
if (!envConfig) {
11+
logger.error(`No database config found for environment: ${env}`);
12+
}
613

714
const sequelize = new Sequelize(
815
envConfig.database,

src/config/sequelize-cli.config.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,22 @@ module.exports = {
99
host: config.postgresHost || 'postgres',
1010
port: config.postgresPort,
1111
dialect: 'postgres',
12-
logging: config.env === 'development' ? logger.info('development') : false,
12+
logging: config.env === 'development' ? logger.info : false,
13+
pool: {
14+
max: 5,
15+
min: 0,
16+
acquire: 30000,
17+
idle: 10000
18+
}
19+
},
20+
test: { // Add this test environment configuration
21+
username: config.postgresUser,
22+
password: config.postgresPassword,
23+
database: config.postgresDb,
24+
host: config.postgresHost || 'postgres',
25+
port: config.postgresPort,
26+
dialect: 'postgres',
27+
logging: false, // Disable logging during tests
1328
pool: {
1429
max: 5,
1530
min: 0,
@@ -34,13 +49,11 @@ module.exports = {
3449
dialectOptions: {
3550
ssl: {
3651
require: true,
37-
rejectUnauthorized: false // For self-signed certificates
52+
rejectUnauthorized: false
3853
},
39-
// For connection timeouts
4054
connectTimeout: 60000,
4155
keepAlive: true
4256
},
43-
// Heroku and other cloud providers often use this
4457
...(config.dbUrl ? { url: config.dbUrl } : {})
4558
}
4659
};

0 commit comments

Comments
 (0)