Skip to content

Commit

Permalink
refactoring code
Browse files Browse the repository at this point in the history
  • Loading branch information
pglez82 committed Jan 10, 2024
1 parent 9ae1cce commit 05a7ee8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

This is a base project for the Software Architecture course in 2023/2024. It is a basic application composed of several components.

- User service. Express service that handles the insertion of new users in the system.
- Auth service. Express service that handles the authentication of users.
- Gateway service. Express service that is exposed to the public and serves as a proxy to the two previous ones.
- Webapp. React web application that uses the gateway service to allow basic login and new user features.
- **User service**. Express service that handles the insertion of new users in the system.
- **Auth service**. Express service that handles the authentication of users.
- **Gateway service**. Express service that is exposed to the public and serves as a proxy to the two previous ones.
- **Webapp**. React web application that uses the gateway service to allow basic login and new user features.

Both the user and auth service share a Mongo database that is accessed with mongoose.

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion authservice/auth-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const express = require('express');
const mongoose = require('mongoose');
const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken');
const User = require('./model')
const User = require('./auth-model')

const app = express();
const port = 8002;
Expand Down
16 changes: 9 additions & 7 deletions authservice/auth-service.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
const request = require('supertest');
const { MongoMemoryServer } = require('mongodb-memory-server');
const bcrypt = require('bcrypt');
const User = require('./model');
const User = require('./auth-model');

let mongoServer;
let app;

//test user
const user = {
username: 'testuser',
password: 'testpassword',
};

async function addUser(user){
const hashedPassword = await bcrypt.hash(user.password, 10);
const newUser = new User({
Expand All @@ -21,6 +27,8 @@ beforeAll(async () => {
const mongoUri = mongoServer.getUri();
process.env.MONGODB_URI = mongoUri;
app = require('./auth-service');
//Load database with initial conditions
await addUser(user);
});

afterAll(async () => {
Expand All @@ -30,12 +38,6 @@ afterAll(async () => {

describe('Auth Service', () => {
it('Should perform a login operation /login', async () => {
const user = {
username: 'testuser',
password: 'testpassword',
};
await addUser(user);

const response = await request(app).post('/login').send(user);
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('username', 'testuser');
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const express = require('express');
const mongoose = require('mongoose');
const bcrypt = require('bcrypt');
const bodyParser = require('body-parser');
const User = require('./model')
const User = require('./user-model')

const app = express();
const port = 8001;
Expand Down

0 comments on commit 05a7ee8

Please sign in to comment.