Skip to content

Commit

Permalink
unit-tests fix (6)
Browse files Browse the repository at this point in the history
  • Loading branch information
angelalvaigle committed Nov 26, 2024
1 parent ac8071e commit ec18ad8
Show file tree
Hide file tree
Showing 13 changed files with 6,919 additions and 371 deletions.
5,137 changes: 5,133 additions & 4 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
{}
{
"scripts": {
"test": "node --experimental-vm-modules ./node_modules/.bin/jest"
},
"devDependencies": {
"@babel/preset-env": "^7.26.0",
"babel-jest": "^29.7.0",
"jest": "^29.7.0"
}
}
6 changes: 2 additions & 4 deletions questionservice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
"main": "service.js",
"type": "module",
"jest": {
"transform": {
"^.+\\.js$": "babel-jest"
}
"transform": {}
},
"scripts": {
"start": "node question-service.js",
"test": "jest"
"test": "node --experimental-vm-modules ./node_modules/.bin/jest"
},
"repository": {
"type": "git",
Expand Down
5 changes: 4 additions & 1 deletion statservice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
"description": "Statistics service, in charge of generating statistics in the application",
"main": "service.js",
"type": "module",
"jest": {
"transform": {}
},
"scripts": {
"start": "node stat-service.js",
"test": "jest"
"test": "node --experimental-vm-modules ./node_modules/.bin/jest"
},
"repository": {
"type": "git",
Expand Down
4 changes: 4 additions & 0 deletions users/authservice/auth-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ app.use(express.json());

// Connect to MongoDB
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/userdb';

console.log('auth service');
console.log(mongoUri);

mongoose.connect(mongoUri);

// Route for user login
Expand Down
12 changes: 6 additions & 6 deletions users/authservice/auth-service.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const request = require('supertest');
const { MongoMemoryServer } = require('mongodb-memory-server');
const bcrypt = require('bcrypt');
const User = require('./auth-model');
import request from 'supertest';
import { MongoMemoryServer } from 'mongodb-memory-server';
import bcrypt from 'bcrypt';
import User from './auth-model.js';

let mongoServer;
let app;
Expand All @@ -26,8 +26,8 @@ beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
const mongoUri = mongoServer.getUri();
process.env.MONGODB_URI = mongoUri;
app = require('./auth-service');
//Load database with initial conditions
app = (await import('./auth-service.js')).default; // Import app dynamically to ensure MONGODB_URI is set
// Load database with initial conditions
await addUser(user);
});

Expand Down
Loading

0 comments on commit ec18ad8

Please sign in to comment.