forked from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from Arquisoft/Ruben
Empezada monitorización y nuevos tests
- Loading branch information
Showing
6 changed files
with
108 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const mongoose = require('mongoose'); | ||
const { MongoMemoryServer } = require('mongodb-memory-server'); | ||
const Question = require('./question-model'); | ||
|
||
let mongoServer; | ||
|
||
beforeAll(async () => { | ||
mongoServer = await MongoMemoryServer.create(); | ||
const mongoUri = mongoServer.getUri(); | ||
process.env.MONGODB_URI = mongoUri; | ||
await mongoose.connect(mongoUri, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await mongoose.disconnect(); | ||
await mongoServer.stop(); | ||
}); | ||
|
||
describe('Question Model', () => { | ||
it('should create a new question', async () => { | ||
const questionData = { | ||
enunciado: '¿Cuál es la capital de España?', | ||
respuesta_correcta: 'Madrid', | ||
respuesta_falsa1: 'París', | ||
respuesta_falsa2: 'Londres', | ||
respuesta_falsa3: 'Berlín', | ||
}; | ||
|
||
const newQuestion = await Question.create(questionData); | ||
|
||
expect(newQuestion.enunciado).toBe(questionData.enunciado); | ||
expect(newQuestion.respuesta_correcta).toBe(questionData.respuesta_correcta); | ||
expect(newQuestion.respuesta_falsa1).toBe(questionData.respuesta_falsa1); | ||
expect(newQuestion.respuesta_falsa2).toBe(questionData.respuesta_falsa2); | ||
expect(newQuestion.respuesta_falsa3).toBe(questionData.respuesta_falsa3); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const mongoose = require('mongoose'); | ||
const { MongoMemoryServer } = require('mongodb-memory-server'); | ||
const User = require('./user-model'); | ||
const { randomBytes } = require('crypto'); | ||
|
||
let mongoServer; | ||
|
||
function generateSecureRandomPassword(length) { | ||
const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+'; | ||
const password = []; | ||
const bytes = randomBytes(length); | ||
for (let i = 0; i < length; i++) { | ||
const randomIndex = bytes[i] % characters.length; | ||
password.push(characters[randomIndex]); | ||
} | ||
return password.join(''); | ||
} | ||
|
||
beforeAll(async () => { | ||
mongoServer = await MongoMemoryServer.create(); | ||
const mongoUri = mongoServer.getUri(); | ||
process.env.MONGODB_URI = mongoUri; | ||
await mongoose.connect(mongoUri, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await mongoose.disconnect(); | ||
await mongoServer.stop(); | ||
}); | ||
|
||
describe('Question Model', () => { | ||
it('should create a new user', async () => { | ||
const userData = { | ||
username: 'testuser', | ||
email: '[email protected]', | ||
password: generateSecureRandomPassword(8), | ||
}; | ||
|
||
const newUser = await User.create(userData); | ||
|
||
expect(newUser.username).toBe(userData.username); | ||
expect(newUser.email).toBe(userData.email); | ||
expect(newUser.password).toBe(userData.password); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters