Skip to content

Commit

Permalink
Merge pull request #103 from Arquisoft/dev
Browse files Browse the repository at this point in the history
Dev
pelazas authored Apr 26, 2024
2 parents 27dd23c + 3ee97bf commit a465d55
Showing 5 changed files with 75 additions and 4 deletions.
2 changes: 1 addition & 1 deletion multiplayerservice/package.json
Original file line number Diff line number Diff line change
@@ -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": {
54 changes: 53 additions & 1 deletion 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 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();
});

});
19 changes: 19 additions & 0 deletions users/userservice/util/test/createMultipleUsers.js
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
@@ -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",
2 changes: 1 addition & 1 deletion webapp/src/components/game/multiplayer/GameMultiPlayer.tsx
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ export interface PlayerWithPoints {
const GameMultiPlayer: FC<GameMultiPlayerProps> = () => {

//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<SocketProps | null>(null);
const [stage, setStage] = useState<number>(1)

0 comments on commit a465d55

Please sign in to comment.