diff --git a/multiplayerservice/package.json b/multiplayerservice/package.json index 2fd1834..1e0b672 100644 --- a/multiplayerservice/package.json +++ b/multiplayerservice/package.json @@ -5,7 +5,7 @@ "main": "service.js", "scripts": { "start": "node server.js", - "start:prod": "cross-env WEBAPP_ENDPOINT=http://conoceryvencer.xyz node server.js", + "start:prod": "cross-env WEBAPP_ENDPOINT=http://localhost node server.js", "test": "jest" }, "repository": { diff --git a/users/userservice/user-service.test.js b/users/userservice/user-service.test.js index dc12406..6ef6f32 100644 --- a/users/userservice/user-service.test.js +++ b/users/userservice/user-service.test.js @@ -1,6 +1,7 @@ const request = require('supertest'); const { MongoMemoryServer } = require('mongodb-memory-server'); const User = require('./user-model'); +const createMultipleUsers = require('./util/test/createMultipleUsers'); let mongoServer; let app; @@ -143,7 +144,6 @@ it('retrieves user by username and returns user data without password field', as .get(`/getUser/${mockUser.username}`); expect(response.status).toBe(200); - console.log(response.body) expect(response.body).toEqual(mockUserWithoutPassword); }); @@ -159,4 +159,56 @@ it('gets the statistics for a player given its uuid', async () => { expect(response.body).toEqual(mockUserWithoutPassword); }) +it('adds group to user successfully', async () => { + const userUUID = mockUser.uuid; + const groupUUID1 = '3c68688e-84e7-4d29-b7c7-09474d42b670'; + const groupUUID2 = '3c68688e-84e7-4d29-b7c7-09474d42b675'; + + const response1 = await request(app) + .put(`/addGroup/${userUUID}`) + .send({ groupUUID: groupUUID1 }); + + // Check if the response status is 200 + expect(response1.status).toBe(200); + + const response2 = await request(app) + .put(`/addGroup/${userUUID}`) + .send({ groupUUID: groupUUID2 }); + + expect(response2.status).toBe(200); + expect(response2.body).toHaveProperty("previousGroup") + expect(response2.body.previousGroup).toEqual(groupUUID1); + + const updatedUser = await User.findOne({ uuid: mockUser.uuid }); + expect(updatedUser.groupId).toEqual(groupUUID2); +}); + +it('retrieves users by IDs successfully', async () => { + const mockUsers = await createMultipleUsers(3); + const userIds = mockUsers.map(user => user.uuid); + + const response = await request(app) + .post(`/getUsersByIds`) + .send({ userIds }); + + expect(response.status).toBe(200); + expect(Array.isArray(response.body)).toBe(true); + expect(response.body.length).toEqual(userIds.length); + + response.body.forEach((user, index) => { + expect(user.uuid).toEqual(userIds[index]); + }); +}); + +it('removes user from group successfully', async () => { + const userUUID = mockUser.uuid; + const response = await request(app) + .delete(`/leaveGroup/${userUUID}`); + + expect(response.status).toBe(200); + + const updatedUser = await User.findOne({ uuid: userUUID }); + expect(updatedUser.groupId).toBeNull(); }); + +}); \ No newline at end of file diff --git a/users/userservice/util/test/createMultipleUsers.js b/users/userservice/util/test/createMultipleUsers.js new file mode 100644 index 0000000..93e2851 --- /dev/null +++ b/users/userservice/util/test/createMultipleUsers.js @@ -0,0 +1,19 @@ +const User = require('../../user-model'); + + +async function createMultipleUsers(nUsers){ + let users = []; + for (let index = 0; index < nUsers; index++) { + const newUser = new User({ + username: `User ${index}`, + uuid: 'valid-uuid', + password: 'XXXXXXXX' + }); + users.push(newUser); + await newUser.save(); + } + return users; + +} + +module.exports = createMultipleUsers \ No newline at end of file diff --git a/webapp/package.json b/webapp/package.json index 6169d2d..9fcbf34 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -27,7 +27,7 @@ "scripts": { "start": "react-scripts start", "build": "react-scripts build", - "prod": "cross-env REACT_APP_API_ENDPOINT=http://localhost:8000 serve -s build -l 80", + "prod": "cross-env REACT_APP_API_ENDPOINT=http://localhost:8000 REACT_APP_MULTIPLAYER_ENDPOINT=http://localhost:8006 serve -s build -l 80", "test": "react-scripts test --transformIgnorePatterns 'node_modules/(?!axios)/'", "test:e2e": "start-server-and-test 'node e2e/test-environment-setup.js' http://localhost:8000/health prod 3000 \"cd e2e && jest\"", "eject": "react-scripts eject", diff --git a/webapp/src/components/game/multiplayer/GameMultiPlayer.tsx b/webapp/src/components/game/multiplayer/GameMultiPlayer.tsx index f0be289..fb5c9cd 100644 --- a/webapp/src/components/game/multiplayer/GameMultiPlayer.tsx +++ b/webapp/src/components/game/multiplayer/GameMultiPlayer.tsx @@ -31,7 +31,7 @@ export interface PlayerWithPoints { const GameMultiPlayer: FC = () => { //const SERVER_URL = 'http://conoceryvencer.xyz:8006'; - const SERVER_URL = process.env.MULTIPLAYER_ENDPOINT || 'http://localhost:8006'; + const SERVER_URL = process.env.REACT_APP_MULTIPLAYER_ENDPOINT || 'http://localhost:8006'; const [socket, setSocket] = useState(null); const [stage, setStage] = useState(1)