Skip to content

hosting database testing to neon #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
PORT=3000
DB_USER=your_db_user
DB_HOST=your_db_host
DB_DATABASE=your_db_name
DB_PASSWORD=your_db_password
DB_PORT=your_db_port
JWT_SECRET=798ea961741292c2ae495590e8512d25fc1d7256c30c38d9a2087df00051eaac
JWT_EXPIRATION_TIME=86400
[email protected]
EMAIL_PASS=your_email_password

DATABASE_URL=postgresql://bookdb_owner:[email protected]/testdb?sslmode=require
13 changes: 11 additions & 2 deletions config/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ require('dotenv').config();
const { Pool } = require('pg');

const pool = new Pool({
user: process.env.DB_USER,
/*user: process.env.DB_USER,
host: process.env.DB_HOST,
database: process.env.DB_DATABASE,
password: process.env.DB_PASSWORD,
port: process.env.DB_PORT,
port: process.env.DB_PORT,*/
connectionString: process.env.DATABASE_URL,
});

pool.on('connect', () => {
console.log('Connected to the database.');
});

pool.on('error', (err) => {
console.error('Database connection error:', err);
});

module.exports = pool;
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
]
},
"scripts": {
"test": "DEBUG=module:* nyc mocha --require @babel/register",
"start": "node src/index.js",
"dev": "nodemon src/index.js"
"test": "NODE_ENV=test DEBUG=module:* nyc mocha --require @babel/register",
"start": "node index.js",
"dev": "nodemon index.js"
}
}
15 changes: 10 additions & 5 deletions test/userRoutes.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import chaiHttp from 'chai-http';
import request from 'supertest';
import app from '../index.js';
import bcrypt from 'bcryptjs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

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

describe('User API', () => {
let token; // Store the authentication token
let server;
/*

// Start server before tests and login to get token
before(async () => {
// Start the app server
Expand Down Expand Up @@ -75,15 +79,17 @@ describe('User API', () => {
});
});

describe('POST /users', () => {
/*describe('POST /users', () => {
it('should create a new user with valid data and token', async () => {
const filePath = path.join(__dirname, 'fixtures/sample-profile-pic.jpg');

const res = await request(app)
.post('/users')
.set('Authorization', `Bearer ${token}`)
.field('name', 'John Doe')
.field('email', '[email protected]')
.field('password', 'password123')
.attach('picture', 'test/fixtures/sample-profile-pic.jpg'); // Attach a file
.attach('picture', filePath); // Attach a file

expect(res.status).to.equal(201);
expect(res.body).to.have.property('message', 'User added');
Expand All @@ -107,7 +113,7 @@ describe('User API', () => {
expect(res.status).to.equal(401);
expect(res.body).to.have.property('error', 'Unauthorized');
});
});
}); */

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

// Close the server after tests
after(async () => {
Expand Down
Loading