mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-05-21 14:59:50 -05:00
BattleRoom is now GameRoom, a slightly more abstract room type capable of holding any of a number of possible roomgames. Currently, battles are the only such roomgame, but any future roomgame could possibly use it. Differences between ChatRoom and GameRoom: - GameRooms start at the left, ChatRooms start at the right - GameRooms have chat on the right, and a game area on the left, with a view area at the top left and a controls area at the bottom left - GameRooms retain all their logs, ChatRooms only retain the latest 100 lines - GameRooms expire after 40 minutes of inactivity or 10 minutes of zero online users (configurable in the future) - GameRooms are guaranteed to have an associated game, while ChatRooms may or may not
107 lines
2.9 KiB
JavaScript
107 lines
2.9 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('assert');
|
|
|
|
const {User} = require('../../dev-tools/users-utils');
|
|
|
|
describe('Rooms features', function () {
|
|
describe('Rooms', function () {
|
|
describe('Rooms.get', function () {
|
|
it('should be a function', function () {
|
|
assert.strictEqual(typeof Rooms.get, 'function');
|
|
});
|
|
|
|
it('should be equal to `Rooms`', function () {
|
|
assert.strictEqual(Rooms.get, Rooms);
|
|
});
|
|
});
|
|
describe('Rooms.rooms', function () {
|
|
it('should be a Map', function () {
|
|
assert.ok(Rooms.rooms instanceof Map);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('GameRoom', function () {
|
|
const packedTeam = 'Weavile||lifeorb||swordsdance,knockoff,iceshard,iciclecrash|Jolly|,252,,,4,252|||||';
|
|
|
|
let room;
|
|
afterEach(function () {
|
|
Users.users.forEach(user => {
|
|
room.onLeave(user);
|
|
user.disconnectAll();
|
|
user.destroy();
|
|
});
|
|
if (room) room.destroy();
|
|
});
|
|
|
|
it('should allow two users to join the battle', function () {
|
|
let p1 = new User();
|
|
let p2 = new User();
|
|
let options = [{rated: false, tour: false}, {rated: false, tour: {onBattleWin() {}}}, {rated: true, tour: false}, {rated: true, tour: {onBattleWin() {}}}];
|
|
for (let option of options) {
|
|
room = Rooms.createBattle('customgame', Object.assign({
|
|
p1,
|
|
p2,
|
|
p1team: packedTeam,
|
|
p2team: packedTeam,
|
|
}, option));
|
|
assert.ok(room.battle.p1 && room.battle.p2); // Automatically joined
|
|
}
|
|
});
|
|
|
|
it('should copy auth from tournament', function () {
|
|
const p1 = new User();
|
|
const p2 = new User();
|
|
const options = {
|
|
p1,
|
|
p2,
|
|
p1team: packedTeam,
|
|
p2team: packedTeam,
|
|
rated: false,
|
|
auth: {},
|
|
tour: {
|
|
onBattleWin() {},
|
|
room: {getAuth() {
|
|
return '%';
|
|
}},
|
|
},
|
|
};
|
|
room = Rooms.createBattle('customgame', options);
|
|
assert.strictEqual(room.getAuth(new User()), '%');
|
|
});
|
|
|
|
it('should prevent overriding tournament room auth by a tournament player', function () {
|
|
const p1 = new User();
|
|
const p2 = new User();
|
|
const roomStaff = new User();
|
|
roomStaff.forceRename("Room auth", true);
|
|
const administrator = new User();
|
|
administrator.forceRename("Admin", true);
|
|
administrator.group = '~';
|
|
const options = {
|
|
p1,
|
|
p2,
|
|
p1team: packedTeam,
|
|
p2team: packedTeam,
|
|
rated: false,
|
|
auth: {},
|
|
tour: {
|
|
onBattleWin() {},
|
|
room: {getAuth(user) {
|
|
return '%';
|
|
}},
|
|
},
|
|
};
|
|
room = Rooms.createBattle('customgame', options);
|
|
roomStaff.joinRoom(room);
|
|
administrator.joinRoom(room);
|
|
assert.strictEqual(room.getAuth(roomStaff), '%', 'before promotion attempt');
|
|
Chat.parse("/roomvoice Room auth", room, p1, p1.connections[0]);
|
|
assert.strictEqual(room.getAuth(roomStaff), '%', 'after promotion attempt');
|
|
Chat.parse("/roomvoice Room auth", room, administrator, administrator.connections[0]);
|
|
assert.strictEqual(room.getAuth(roomStaff), '+', 'after being promoted by an administrator');
|
|
});
|
|
});
|
|
});
|