generated 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 #48 from Arquisoft/dev
Dev
- Loading branch information
Showing
78 changed files
with
13,934 additions
and
1,453 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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
coverage | ||
docs/build | ||
docs/build | ||
game/qgservice/.env |
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,2 @@ | ||
node_modules | ||
coverage |
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,20 @@ | ||
# Use an official Node.js runtime as a parent image | ||
FROM node:20 | ||
|
||
# Set the working directory in the container | ||
WORKDIR /usr/src/gameservice | ||
|
||
# Copy package.json and package-lock.json to the working directory | ||
COPY package*.json ./ | ||
|
||
# Install app dependencies | ||
RUN npm install | ||
|
||
# Copy the app source code to the working directory | ||
COPY . . | ||
|
||
# Expose the port the app runs on | ||
EXPOSE 8004 | ||
|
||
# Define the command to run your app | ||
CMD ["node", "gameservice.js"] |
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,28 @@ | ||
let Game = require('./game-model'); | ||
const { createGame } = require('./queries/CreateGame'); | ||
const mongoose = require('mongoose'); | ||
|
||
let GameController = { | ||
/* HACER EN USER - GET LAST GAME BY USER | ||
findByUsername: async (req, res) => { | ||
let game = await User.find({username: req.params.username}).populate("lastGame") | ||
let response = await Game.findById(game[0].lastGame.id).populate("questions").populate("players") | ||
res.json(response); | ||
},*/ | ||
create: async (req, res) => { | ||
const { questions, players } = req.body; | ||
console.log(questions, players) | ||
const game = await createGame(questions, players); | ||
res.json(game); | ||
}, | ||
delete: async (req, res) => { | ||
await Game.findOneAndDelete({uuid: req.params.id}); | ||
res.json({message: "Game deleted"}); | ||
}, | ||
getById: async (req, res) => { | ||
let game = await Game.find({uuid: req.params.id}) | ||
res.json(game); | ||
} | ||
} | ||
|
||
module.exports = GameController; |
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,22 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const gameSchema = new mongoose.Schema({ | ||
uuid: { | ||
type: String, | ||
required: true, | ||
}, | ||
players:[{ | ||
type: String, | ||
required: true, | ||
}], | ||
questions:[ | ||
{ | ||
type: String, | ||
required: true, | ||
} | ||
], | ||
}); | ||
|
||
const Game = mongoose.model('Game', gameSchema); | ||
|
||
module.exports = Game |
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 request = require('supertest'); | ||
const { MongoMemoryServer } = require('mongodb-memory-server'); | ||
|
||
let mongoServer; | ||
let app; | ||
|
||
beforeAll(async () => { | ||
mongoServer = await MongoMemoryServer.create(); | ||
const mongoUri = mongoServer.getUri(); | ||
process.env.MONGODB_URI = mongoUri; | ||
app = require('./gameservice'); | ||
}); | ||
|
||
afterAll(async () => { | ||
app.close(); | ||
await mongoServer.stop(); | ||
}); | ||
|
||
describe('Game service', () => { | ||
|
||
// mock data | ||
const questions = [{ _id: 'question1_id' }, { _id: 'question2_id' }]; | ||
const users = [{ _id: 'user1_id' }, { _id: 'user2_id' }]; | ||
|
||
it('should create a game and update user lastGame field', async () => { | ||
const response = await request(app).post('/creategame').send({questions,users}); | ||
expect(response.status).toBe(200); | ||
expect(response.body).toHaveProperty('_id'); | ||
|
||
const gameId = response.body._id; | ||
const gameFromDB = await mongoose.model('Game').findById(gameId); | ||
const user1FromDB = await mongoose.model('User').findById('user1_id'); | ||
const user2FromDB = await mongoose.model('User').findById('user2_id'); | ||
|
||
// Assertions for the database state | ||
expect(gameFromDB).toBeTruthy(); | ||
expect(user1FromDB.lastGame.toString()).toBe(gameId); | ||
expect(user2FromDB.lastGame.toString()).toBe(gameId); | ||
}); | ||
}); |
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,32 @@ | ||
// gameservice.js | ||
const express = require('express'); | ||
const axios = require('axios'); | ||
const mongoose = require('mongoose'); | ||
const { createGame } = require('./queries/CreateGame'); | ||
const GameController = require('./GameController'); | ||
|
||
const app = express(); | ||
const port = 8004; | ||
|
||
// app.use(bodyParser.json()); | ||
app.use(express.json()); | ||
|
||
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/userdb'; | ||
mongoose.connect(mongoUri); | ||
|
||
app.get('/', (req, res) => { | ||
res.json({ | ||
"hi": "game service" | ||
}); | ||
}); | ||
|
||
// Routes | ||
app.post('/createGame', GameController.create); | ||
app.delete('/deleteGame/:id', GameController.delete); | ||
app.get('/getGame/:id', GameController.getById); | ||
|
||
const server = app.listen(port, () => { | ||
console.log(`Question generator Service listening at http://localhost:${port}`); | ||
}); | ||
|
||
module.exports = server; |
Oops, something went wrong.