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

Nuevos tipos de preguntas, todos los tests de servicios y algunos de webapp implementados #165

Merged
merged 36 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
de016cc
Test historial de preguntas
pablouronesclavera Apr 18, 2024
b3d4925
Test historial de preguntas
pablouronesclavera Apr 18, 2024
fd1a602
Test historial de preguntas
pablouronesclavera Apr 18, 2024
8064d60
Test historial de preguntas
pablouronesclavera Apr 18, 2024
2005870
Test historial de preguntas
pablouronesclavera Apr 18, 2024
0f490a8
paginacion Historico de usuario
UO290054 Apr 22, 2024
3f916cd
Merge branch 'develop' into ray
UO290054 Apr 22, 2024
324a31a
Tests del gateway service
baraganio Apr 23, 2024
457395f
Merge remote-tracking branch 'origin' into carlos
baraganio Apr 23, 2024
68e86bb
Merge pull request #151 from Arquisoft/carlos
baraganio Apr 23, 2024
4e87224
Merge branch 'develop' into pablo
pablouronesclavera Apr 23, 2024
4687f0e
Añadiendo tests a userservice
baraganio Apr 23, 2024
7eff51b
Añadiendo tests a authservice
baraganio Apr 23, 2024
fe9b795
Sincronizacion y tests
pablouronesclavera Apr 23, 2024
a75bbfe
pagiancion completa ent todas las pestañas + errores de paginaciom an…
UO290054 Apr 24, 2024
ac1bdaf
cambio boton historicoUsusario
UO290054 Apr 24, 2024
19da8d8
Merge branch 'develop' into ray
UO290054 Apr 24, 2024
06055d9
Test HisotircalData y RegisteredUsers
pablouronesclavera Apr 25, 2024
cb45484
Merge branch 'develop' into carlos
baraganio Apr 26, 2024
9a8ae02
Añadidas 2 nuevas consultas (habitantes y numero atómico)
baraganio Apr 26, 2024
f2757bb
Arreglando un fallo de userservice test
baraganio Apr 26, 2024
46a9dd4
Merge pull request #160 from Arquisoft/carlos
pablouronesclavera Apr 26, 2024
d59b5ad
Test HistoricalData y RegisteredUsers
pablouronesclavera Apr 26, 2024
3b1d454
Merge branch 'develop' into pablo
pablouronesclavera Apr 26, 2024
74e846e
Merge pull request #161 from Arquisoft/pablo
pablouronesclavera Apr 26, 2024
aea0c61
Merge branch 'develop' into ray
UO290054 Apr 27, 2024
79ca9da
Arreglos sonarCloud
UO290054 Apr 27, 2024
1d78f05
Tests addUser y Login
UO290054 Apr 27, 2024
7289f7d
Añadidos tests a los servicios createquestion y retrieve
baraganio Apr 27, 2024
d9493fd
Merge pull request #164 from Arquisoft/carlos
baraganio Apr 27, 2024
6116650
Intentando eliminar securityHospots y código duplicado
baraganio Apr 27, 2024
2245b20
tests funcionando
UO290054 Apr 27, 2024
74bc474
Merge branch 'develop' into ray
UO290054 Apr 27, 2024
4cafb84
arreglar duplicacion de codigo
UO290054 Apr 28, 2024
ddee153
Merge pull request #168 from Arquisoft/ray
UO290054 Apr 28, 2024
b7d7962
Merge pull request #166 from Arquisoft/carlos
baraganio Apr 28, 2024
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
6 changes: 4 additions & 2 deletions questions/creationservice/creation-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ var answerOptions = [];

var randomQuerySelector;
// Array of the possible queries
var queries = ['SELECT DISTINCT ?questionObject ?questionObjectLabel ?answer ?answerLabel WHERE { ?questionObject wdt:P31 wd:Q6256. ?questionObject wdt:P36 ?answer. SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es".}}'];
var queries = ['SELECT DISTINCT ?questionObject ?questionObjectLabel ?answer ?answerLabel WHERE { ?questionObject wdt:P31 wd:Q6256. ?questionObject wdt:P36 ?answer. SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es".}}',
'SELECT DISTINCT ?questionObject ?questionObjectLabel ?answer ?answerLabel WHERE { ?questionObject wdt:P31 wd:Q11344; wdt:P1086 ?answer. SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es".}}',
'SELECT ?questionObject ?questionObjectLabel ?answer ?answerLabel WHERE { ?questionObject wdt:P31 wd:Q6256; wdt:P1082 ?answer. SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es".}}'];
// Array of the possible questions
var questions = ["¿Cuál es la capital de "];
var questions = ["¿Cuál es la capital de ","¿Cuál es el número atómico del ", "¿Cuántos habitantes tiene "];

// Recieves the information of the query and select wich data use on the question
function getQuestionInfo(info){
Expand Down
21 changes: 21 additions & 0 deletions users/authservice/auth-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const user = {
password: 'testpassword',
};

const user2 = {
username: 'testuser',
password: 'wrongpass',
};

async function addUser(user){
const hashedPassword = await bcrypt.hash(user.password, 10);
const newUser = new User({
Expand Down Expand Up @@ -42,4 +47,20 @@ describe('Auth Service', () => {
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('username', 'testuser');
});

it('Should perform a fail login operation du to incorrect answer /login', async () => {
const response = await request(app).post('/login').send(user2);
expect(response.status).toBe(401);
expect(response.body).toHaveProperty('error', 'Invalid credentials');
});

it('Should perform a server error due to missing value /login', async () => {
const response = await request(app).post('/login')
.send(user3 = {
username: 'testuser',
});
expect(response.status).toBe(500);
expect(response.body).toHaveProperty('error', 'Internal Server Error');
});

});
48 changes: 45 additions & 3 deletions users/userservice/user-service.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
const request = require('supertest');
const { MongoMemoryServer } = require('mongodb-memory-server');
const bcrypt = require('bcrypt');
const User = require('./user-model');

let mongoServer;
let app;

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

async function addUser(user){
const hashedPassword = await bcrypt.hash(user.password, 10);
const newUser = new User({
username: user.username,
password: hashedPassword,
});

await newUser.save();
}

beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
const mongoUri = mongoServer.getUri();
process.env.MONGODB_URI = mongoUri;
app = require('./user-service');
await addUser(user);
});

afterAll(async () => {
Expand All @@ -17,14 +35,38 @@ afterAll(async () => {
});

describe('User Service', () => {

//
it('should get the registered users on /getregisteredusers', async () => {

const response = await request(app).get('/getregisteredusers');
expect(response.status).toBe(200);
expect(response.body.length).toBe(1);
expect(Array.from(response.body[0])[0]).toBe('testuser');
});

//
it('should add a new user on POST /adduser', async () => {
const newUser = {
username: 'testuser',
password: 'testpassword',
username: 'testuser2',
password: 'testpassword2',
};

const response = await request(app).post('/adduser').send(newUser);
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('username', 'testuser');
expect(response.body).toHaveProperty('username', 'testuser2');
});

//
it('trying to add a user without username', async () => {
const newUser = {
password: 'testpassword',
};

const response = (await request(app).post('/adduser').send(newUser));
expect(response.status).toBe(400);
expect(response.body).toHaveProperty( "error" , "Missing required field: username" );
});


});