Skip to content
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

Added test for user model #154

Merged
merged 2 commits into from
Apr 28, 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
19 changes: 19 additions & 0 deletions users/userservice/user-service.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const request = require('supertest');
const { MongoMemoryServer } = require('mongodb-memory-server');
const jwt = require('jsonwebtoken');
const User = require('./user-model');

// Mock the `jsonwebtoken` module
jest.mock('jsonwebtoken', () => ({
Expand Down Expand Up @@ -68,6 +69,24 @@ describe('User Service /adduser', () => {
expect(response.status).toBe(400);
expect(response.body).toHaveProperty('error', 'Email already in use');
});

it('Should not register user /adduser', async () => {

var newUser4 = {
email: '[email protected]',
username: 'testuser4',
password: 'testpassword',
repeatPassword: 'testpassword'
};

var newUser4DB = new User(newUser4);
await newUser4DB.save();


const response = await request(app).post('/adduser').send(newUser);
expect(response.status).toBe(400);
expect(response.body).toHaveProperty('error', 'Username already in use');
})

});

Expand Down
67 changes: 0 additions & 67 deletions webapp/src/components/HistoricalData/HistoryRecordRetriever.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,9 @@ class HistoryRecordRetriever{
const receivedRecords = await response.data;
return receivedRecords.record;
} catch (error) {
console.log(error)
throw new Error(error);

}
/*
return {
userId: user,
games: [
{
questions: [
{
question: "¿Cuál es la capital de Francia?",
answers: ["Madrid", "París", "Londres", "Roma"],
answerGiven: "París",
correctAnswer: "París"
},
{
question: "¿En qué año comenzó la Segunda Guerra Mundial?",
answers: ["1939", "1945", "1914", "1941"],
answerGiven: "1939",
correctAnswer: "1939"
},
{
question: "¿Quién escribió 'Don Quijote de la Mancha'?",
answers: ["Miguel de Cervantes", "Gabriel García Márquez", "Federico García Lorca", "Jorge Luis Borges"],
answerGiven: "Miguel de Cervantes",
correctAnswer: "Miguel de Cervantes"
}
],
points: 3000,
date: "01/02/24"
},
{
questions: [
{
question: "¿Cuál es el río más largo del mundo?",
answers: ["Nilo", "Amazonas", "Yangtsé", "Misisipi"],
answerGiven: "Amazonas",
correctAnswer: "Amazonas"
},
{
question: "¿Cuál es el elemento más abundante en la corteza terrestre?",
answers: ["Hierro", "Oxígeno", "Silicio", "Aluminio"],
answerGiven: "Oxígeno",
correctAnswer: "Oxígeno"
}
],
points: 2500,
date: "02/02/24"
},
{
questions: [
{
question: "¿Quién pintó la Mona Lisa?",
answers: ["Leonardo da Vinci", "Pablo Picasso", "Vincent van Gogh", "Rembrandt"],
answerGiven: "Leonardo da Vinci",
correctAnswer: "Leonardo da Vinci"
},
{
question: "¿Cuál es el planeta más grande del sistema solar?",
answers: ["Júpiter", "Saturno", "Neptuno", "Urano"],
answerGiven: "Júpiter",
correctAnswer: "Júpiter"
}
],
points: 3500,
date: "03/02/24"
}
]
};*/
}


Expand Down
29 changes: 1 addition & 28 deletions webapp/src/components/questionView/QuestionGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,7 @@ class QuestionGenerator{

}

async generateQuestions(lang, type, amount, token) {

// try {
// //const response = await fetch(this.apiUrl);
// //const receivedQuestions = await response.json();

// //Mockup
// console.log("type: "+type+" amount: "+amount)
// const receivedQuestions = JSON.parse('{"0":{"question":"What is the population of Oviedo?","answers":["225089","191325","220587","121548"]},'+
// '"1":{"question":"¿Cuál es la población de Gijón?","answers":["275274","159658","233982","305554"]},'+
// '"2":{"question":"¿Cuál es la población de Avilés?","answers":["82568","115595","41284","122200"]},'+
// '"3":{"question":"¿Cuál es la capital de Asturias?","answers":["Ciudad de Oviedo","a","b","c"]},'+
// '"4":{"question":"¿Cuál es la capital de España?","answers":["Madrid","a","b","c"]},'+
// '"5":{"question":"¿Cuál es la capital de Turquía?","answers":["Ankara","a","b","c"]}}')

// let i = 0;
// var questions = [];
// for (const key in receivedQuestions) {
// questions[i] = new Question(receivedQuestions[key]);
// i += 1;
// }
// console.log(questions);
// return questions;
// } catch (error) {
// throw new Error(error);
// }


async generateQuestions(lang, type, amount, token) {

try {
let response;
Expand Down
Loading