Skip to content

Commit 56c8374

Browse files
authored
Merge pull request #24 from JawherKl/feature/19-hosting-db-neon
hosting database testing to neon
2 parents dd66709 + 861c025 commit 56c8374

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

.env.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
PORT=3000
2+
DB_USER=your_db_user
3+
DB_HOST=your_db_host
4+
DB_DATABASE=your_db_name
5+
DB_PASSWORD=your_db_password
6+
DB_PORT=your_db_port
7+
JWT_SECRET=798ea961741292c2ae495590e8512d25fc1d7256c30c38d9a2087df00051eaac
8+
JWT_EXPIRATION_TIME=86400
9+
10+
EMAIL_PASS=your_email_password
11+
12+
DATABASE_URL=postgresql://bookdb_owner:[email protected]/testdb?sslmode=require

config/db.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@ require('dotenv').config();
22
const { Pool } = require('pg');
33

44
const pool = new Pool({
5-
user: process.env.DB_USER,
5+
/*user: process.env.DB_USER,
66
host: process.env.DB_HOST,
77
database: process.env.DB_DATABASE,
88
password: process.env.DB_PASSWORD,
9-
port: process.env.DB_PORT,
9+
port: process.env.DB_PORT,*/
10+
connectionString: process.env.DATABASE_URL,
11+
});
12+
13+
pool.on('connect', () => {
14+
console.log('Connected to the database.');
15+
});
16+
17+
pool.on('error', (err) => {
18+
console.error('Database connection error:', err);
1019
});
1120

1221
module.exports = pool;

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
]
5454
},
5555
"scripts": {
56-
"test": "DEBUG=module:* nyc mocha --require @babel/register",
57-
"start": "node src/index.js",
58-
"dev": "nodemon src/index.js"
56+
"test": "NODE_ENV=test DEBUG=module:* nyc mocha --require @babel/register",
57+
"start": "node index.js",
58+
"dev": "nodemon index.js"
5959
}
6060
}

test/userRoutes.test.mjs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ import chaiHttp from 'chai-http';
33
import request from 'supertest';
44
import app from '../index.js';
55
import bcrypt from 'bcryptjs';
6+
import path from 'path';
7+
import { fileURLToPath } from 'url';
8+
const __filename = fileURLToPath(import.meta.url);
9+
const __dirname = path.dirname(__filename);
610

711
chai.use(chaiHttp);
812
const { expect } = chai;
913

1014
describe('User API', () => {
1115
let token; // Store the authentication token
1216
let server;
13-
/*
17+
1418
// Start server before tests and login to get token
1519
before(async () => {
1620
// Start the app server
@@ -75,15 +79,17 @@ describe('User API', () => {
7579
});
7680
});
7781

78-
describe('POST /users', () => {
82+
/*describe('POST /users', () => {
7983
it('should create a new user with valid data and token', async () => {
84+
const filePath = path.join(__dirname, 'fixtures/sample-profile-pic.jpg');
85+
8086
const res = await request(app)
8187
.post('/users')
8288
.set('Authorization', `Bearer ${token}`)
8389
.field('name', 'John Doe')
8490
.field('email', '[email protected]')
8591
.field('password', 'password123')
86-
.attach('picture', 'test/fixtures/sample-profile-pic.jpg'); // Attach a file
92+
.attach('picture', filePath); // Attach a file
8793
8894
expect(res.status).to.equal(201);
8995
expect(res.body).to.have.property('message', 'User added');
@@ -107,7 +113,7 @@ describe('User API', () => {
107113
expect(res.status).to.equal(401);
108114
expect(res.body).to.have.property('error', 'Unauthorized');
109115
});
110-
});
116+
}); */
111117

112118
describe('PUT /users/:id', () => {
113119
it('should update a user with valid data', async () => {
@@ -202,7 +208,6 @@ describe('User API', () => {
202208
expect(res.body).to.have.property('error', 'Unauthorized');
203209
});
204210
});
205-
*/
206211

207212
// Close the server after tests
208213
after(async () => {

0 commit comments

Comments
 (0)