partey_workadventure/back/tests/GameRoomTest.ts

152 lines
4.9 KiB
TypeScript
Raw Normal View History

2020-04-07 10:08:04 +02:00
import "jasmine";
import { ConnectCallback, DisconnectCallback, GameRoom } from "../src/Model/GameRoom";
import { Point } from "../src/Model/Websocket/MessageUserPosition";
import { Group } from "../src/Model/Group";
import { User, UserSocket } from "_Model/User";
import { JoinRoomMessage, PositionMessage } from "../src/Messages/generated/messages_pb";
2020-12-08 18:37:15 +01:00
import Direction = PositionMessage.Direction;
import { EmoteCallback } from "_Model/Zone";
2020-09-29 16:27:41 +02:00
2020-12-08 18:37:15 +01:00
function createMockUser(userId: number): User {
2020-09-29 16:27:41 +02:00
return {
userId,
2020-12-08 18:37:15 +01:00
} as unknown as User;
}
function createMockUserSocket(): UserSocket {
return {} as unknown as UserSocket;
2020-12-08 18:37:15 +01:00
}
function createJoinRoomMessage(uuid: string, x: number, y: number): JoinRoomMessage {
2020-12-08 18:37:15 +01:00
const positionMessage = new PositionMessage();
positionMessage.setX(x);
positionMessage.setY(y);
positionMessage.setDirection(Direction.DOWN);
positionMessage.setMoving(false);
const joinRoomMessage = new JoinRoomMessage();
joinRoomMessage.setUseruuid("1");
joinRoomMessage.setIpaddress("10.0.0.2");
joinRoomMessage.setName("foo");
joinRoomMessage.setRoomid("_/global/test.json");
2020-12-08 18:37:15 +01:00
joinRoomMessage.setPositionmessage(positionMessage);
return joinRoomMessage;
2020-09-29 16:27:41 +02:00
}
2020-04-07 10:08:04 +02:00
const emote: EmoteCallback = (emoteEventMessage, listener): void => {};
2020-10-22 16:14:32 +02:00
describe("GameRoom", () => {
it("should connect user1 and user2", async () => {
2020-05-03 16:22:42 +02:00
let connectCalledNumber: number = 0;
2020-09-29 16:27:41 +02:00
const connect: ConnectCallback = (user: User, group: Group): void => {
2020-05-03 16:22:42 +02:00
connectCalledNumber++;
};
const disconnect: DisconnectCallback = (user: User, group: Group): void => {};
2020-04-07 10:08:04 +02:00
const world = await GameRoom.create(
"https://play.workadventu.re/_/global/localhost/test.json",
connect,
disconnect,
160,
160,
() => {},
() => {},
() => {},
2021-12-23 10:44:46 +01:00
emote,
Release 1.9.6 (#2021) * Change accès token with query privateAccessToken in the url Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Add play uri param Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * PlayUri parameter Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * removed unused imports * send group userIds to players * sending info about group lock state. wip * listening to lockGroupMessage on front * cleanup * Updating GroupDescriptors on LockGroupMessage * remove console logs * group circles with color fill * fix GameRoom text * remove obsolete check * cr fixes #1 wip * much cleaner approach to group lock update * fix compilation error * well-known values wip * Removing old unused images Just a bit of cleanup! * update with dan suggest Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Change roomId by playUri Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * hide voice indicator for player leaving still existing bubble conversation * Refactor access by token Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Refactor connexion manager Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Adds settings options and localUser functions * PrivacyShutdownStore modifies constraints according to the user's setting * switches dropdown for checkboxes and adjusts wording * Adds the todo about German translation * Adds test map * Makes the default setting: camera off and mic on * Add z-index on embeds screens and action menu * Fixes tileset import * Adds settings options and localUser functions * PrivacyShutdownStore modifies constraints according to the user's setting * switches dropdown for checkboxes and adjusts wording * Adds the todo about German translation * Adds test map * Makes the default setting: camera off and mic on * Fixes tileset import * Applying German translation, thanks to @Lurkars * removed obsolete console.log * fix linter issues * make use of proto well knows types * fixed types for RoomConnection * fix locking bubble when returning from away mode * Fix run pretty Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * prevent actions menu from appearing when inserting space key on chat * Bump ansi-regex from 4.1.0 to 4.1.1 in /maps Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump minimist from 1.2.5 to 1.2.6 in /desktop/local-app Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6. - [Release notes](https://github.com/substack/minimist/releases) - [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6) --- updated-dependencies: - dependency-name: minimist dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump ansi-regex from 4.1.0 to 4.1.1 in /desktop/electron Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump ansi-regex from 4.1.0 to 4.1.1 in /uploader Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump plist from 3.0.4 to 3.0.5 in /desktop/electron Bumps [plist](https://github.com/TooTallNate/node-plist) from 3.0.4 to 3.0.5. - [Release notes](https://github.com/TooTallNate/node-plist/releases) - [Changelog](https://github.com/TooTallNate/plist.js/blob/master/History.md) - [Commits](https://github.com/TooTallNate/node-plist/commits) --- updated-dependencies: - dependency-name: plist dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Hanusiak Piotr <piotr@ltmp.co> Co-authored-by: David Négrier <d.negrier@thecodingmachine.com> Co-authored-by: Piotr 'pwh' Hanusiak <p.hanusiak@workadventu.re> Co-authored-by: Benedicte Quimbert <b.quimbert@workadventu.re> Co-authored-by: Alexis Faizeau <a.faizeau@workadventu.re> Co-authored-by: Bénédicte Q <37311765+HimeShaman@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-30 11:13:27 +02:00
() => {},
2021-12-23 10:44:46 +01:00
() => {}
);
2020-05-15 23:24:04 +02:00
const user1 = world.join(createMockUserSocket(), createJoinRoomMessage("1", 100, 100));
2020-05-15 23:24:04 +02:00
const user2 = world.join(createMockUserSocket(), createJoinRoomMessage("2", 500, 100));
2020-12-08 18:37:15 +01:00
world.updatePosition(user2, new Point(261, 100));
2020-05-03 16:22:42 +02:00
expect(connectCalledNumber).toBe(0);
2020-12-08 18:37:15 +01:00
world.updatePosition(user2, new Point(101, 100));
2020-04-07 10:08:04 +02:00
2020-05-03 16:22:42 +02:00
expect(connectCalledNumber).toBe(2);
2020-04-07 10:08:04 +02:00
2020-12-08 18:37:15 +01:00
world.updatePosition(user2, new Point(102, 100));
2020-05-03 16:22:42 +02:00
expect(connectCalledNumber).toBe(2);
});
it("should connect 3 users", async () => {
let connectCalled: boolean = false;
2020-09-29 16:27:41 +02:00
const connect: ConnectCallback = (user: User, group: Group): void => {
connectCalled = true;
};
const disconnect: DisconnectCallback = (user: User, group: Group): void => {};
const world = await GameRoom.create(
"https://play.workadventu.re/_/global/localhost/test.json",
connect,
disconnect,
160,
160,
() => {},
() => {},
() => {},
2021-12-23 10:44:46 +01:00
emote,
Release 1.9.6 (#2021) * Change accès token with query privateAccessToken in the url Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Add play uri param Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * PlayUri parameter Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * removed unused imports * send group userIds to players * sending info about group lock state. wip * listening to lockGroupMessage on front * cleanup * Updating GroupDescriptors on LockGroupMessage * remove console logs * group circles with color fill * fix GameRoom text * remove obsolete check * cr fixes #1 wip * much cleaner approach to group lock update * fix compilation error * well-known values wip * Removing old unused images Just a bit of cleanup! * update with dan suggest Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Change roomId by playUri Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * hide voice indicator for player leaving still existing bubble conversation * Refactor access by token Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Refactor connexion manager Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Adds settings options and localUser functions * PrivacyShutdownStore modifies constraints according to the user's setting * switches dropdown for checkboxes and adjusts wording * Adds the todo about German translation * Adds test map * Makes the default setting: camera off and mic on * Add z-index on embeds screens and action menu * Fixes tileset import * Adds settings options and localUser functions * PrivacyShutdownStore modifies constraints according to the user's setting * switches dropdown for checkboxes and adjusts wording * Adds the todo about German translation * Adds test map * Makes the default setting: camera off and mic on * Fixes tileset import * Applying German translation, thanks to @Lurkars * removed obsolete console.log * fix linter issues * make use of proto well knows types * fixed types for RoomConnection * fix locking bubble when returning from away mode * Fix run pretty Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * prevent actions menu from appearing when inserting space key on chat * Bump ansi-regex from 4.1.0 to 4.1.1 in /maps Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump minimist from 1.2.5 to 1.2.6 in /desktop/local-app Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6. - [Release notes](https://github.com/substack/minimist/releases) - [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6) --- updated-dependencies: - dependency-name: minimist dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump ansi-regex from 4.1.0 to 4.1.1 in /desktop/electron Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump ansi-regex from 4.1.0 to 4.1.1 in /uploader Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump plist from 3.0.4 to 3.0.5 in /desktop/electron Bumps [plist](https://github.com/TooTallNate/node-plist) from 3.0.4 to 3.0.5. - [Release notes](https://github.com/TooTallNate/node-plist/releases) - [Changelog](https://github.com/TooTallNate/plist.js/blob/master/History.md) - [Commits](https://github.com/TooTallNate/node-plist/commits) --- updated-dependencies: - dependency-name: plist dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Hanusiak Piotr <piotr@ltmp.co> Co-authored-by: David Négrier <d.negrier@thecodingmachine.com> Co-authored-by: Piotr 'pwh' Hanusiak <p.hanusiak@workadventu.re> Co-authored-by: Benedicte Quimbert <b.quimbert@workadventu.re> Co-authored-by: Alexis Faizeau <a.faizeau@workadventu.re> Co-authored-by: Bénédicte Q <37311765+HimeShaman@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-30 11:13:27 +02:00
() => {},
2021-12-23 10:44:46 +01:00
() => {}
);
const user1 = world.join(createMockUserSocket(), createJoinRoomMessage("1", 100, 100));
const user2 = world.join(createMockUserSocket(), createJoinRoomMessage("2", 200, 100));
expect(connectCalled).toBe(true);
connectCalled = false;
// baz joins at the outer limit of the group
const user3 = world.join(createMockUserSocket(), createJoinRoomMessage("2", 311, 100));
expect(connectCalled).toBe(false);
2020-12-08 18:37:15 +01:00
world.updatePosition(user3, new Point(309, 100));
expect(connectCalled).toBe(true);
});
it("should disconnect user1 and user2", async () => {
let connectCalled: boolean = false;
2020-05-03 16:22:42 +02:00
let disconnectCallNumber: number = 0;
2020-09-29 16:27:41 +02:00
const connect: ConnectCallback = (user: User, group: Group): void => {
connectCalled = true;
};
2020-09-29 16:27:41 +02:00
const disconnect: DisconnectCallback = (user: User, group: Group): void => {
2020-05-03 16:22:42 +02:00
disconnectCallNumber++;
};
const world = await GameRoom.create(
"https://play.workadventu.re/_/global/localhost/test.json",
connect,
disconnect,
160,
160,
() => {},
() => {},
() => {},
2021-12-23 10:44:46 +01:00
emote,
Release 1.9.6 (#2021) * Change accès token with query privateAccessToken in the url Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Add play uri param Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * PlayUri parameter Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * removed unused imports * send group userIds to players * sending info about group lock state. wip * listening to lockGroupMessage on front * cleanup * Updating GroupDescriptors on LockGroupMessage * remove console logs * group circles with color fill * fix GameRoom text * remove obsolete check * cr fixes #1 wip * much cleaner approach to group lock update * fix compilation error * well-known values wip * Removing old unused images Just a bit of cleanup! * update with dan suggest Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Change roomId by playUri Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * hide voice indicator for player leaving still existing bubble conversation * Refactor access by token Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Refactor connexion manager Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Adds settings options and localUser functions * PrivacyShutdownStore modifies constraints according to the user's setting * switches dropdown for checkboxes and adjusts wording * Adds the todo about German translation * Adds test map * Makes the default setting: camera off and mic on * Add z-index on embeds screens and action menu * Fixes tileset import * Adds settings options and localUser functions * PrivacyShutdownStore modifies constraints according to the user's setting * switches dropdown for checkboxes and adjusts wording * Adds the todo about German translation * Adds test map * Makes the default setting: camera off and mic on * Fixes tileset import * Applying German translation, thanks to @Lurkars * removed obsolete console.log * fix linter issues * make use of proto well knows types * fixed types for RoomConnection * fix locking bubble when returning from away mode * Fix run pretty Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * prevent actions menu from appearing when inserting space key on chat * Bump ansi-regex from 4.1.0 to 4.1.1 in /maps Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump minimist from 1.2.5 to 1.2.6 in /desktop/local-app Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6. - [Release notes](https://github.com/substack/minimist/releases) - [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6) --- updated-dependencies: - dependency-name: minimist dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump ansi-regex from 4.1.0 to 4.1.1 in /desktop/electron Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump ansi-regex from 4.1.0 to 4.1.1 in /uploader Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump plist from 3.0.4 to 3.0.5 in /desktop/electron Bumps [plist](https://github.com/TooTallNate/node-plist) from 3.0.4 to 3.0.5. - [Release notes](https://github.com/TooTallNate/node-plist/releases) - [Changelog](https://github.com/TooTallNate/plist.js/blob/master/History.md) - [Commits](https://github.com/TooTallNate/node-plist/commits) --- updated-dependencies: - dependency-name: plist dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Hanusiak Piotr <piotr@ltmp.co> Co-authored-by: David Négrier <d.negrier@thecodingmachine.com> Co-authored-by: Piotr 'pwh' Hanusiak <p.hanusiak@workadventu.re> Co-authored-by: Benedicte Quimbert <b.quimbert@workadventu.re> Co-authored-by: Alexis Faizeau <a.faizeau@workadventu.re> Co-authored-by: Bénédicte Q <37311765+HimeShaman@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-30 11:13:27 +02:00
() => {},
2021-12-23 10:44:46 +01:00
() => {}
);
const user1 = world.join(createMockUserSocket(), createJoinRoomMessage("1", 100, 100));
const user2 = world.join(createMockUserSocket(), createJoinRoomMessage("2", 259, 100));
expect(connectCalled).toBe(true);
2020-05-03 16:22:42 +02:00
expect(disconnectCallNumber).toBe(0);
world.updatePosition(user2, new Point(100 + 160 + 160 + 1, 100));
2020-05-03 16:22:42 +02:00
expect(disconnectCallNumber).toBe(2);
2020-12-08 18:37:15 +01:00
world.updatePosition(user2, new Point(262, 100));
2020-05-03 16:22:42 +02:00
expect(disconnectCallNumber).toBe(2);
});
});