Start working on a non-interactive test script for drafting
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Hamcha 2019-07-03 17:52:29 +02:00
parent 9df4c610dc
commit e06b0b29a1
7 changed files with 133 additions and 1 deletions

2
Vagrantfile vendored
View file

@ -7,7 +7,7 @@ Vagrant.configure("2") do |config|
end end
config.vm.box = "ubuntu/cosmic64" config.vm.box = "ubuntu/cosmic64"
config.vm.network "private_network", ip: "192.168.22.23" config.vm.network "private_network", ip: "192.168.20.20"
config.vm.provision "docker" config.vm.provision "docker"
config.vm.provision :docker_compose, yml: "/vagrant/docker-compose.yml", rebuild: true, run: "always" config.vm.provision :docker_compose, yml: "/vagrant/docker-compose.yml", rebuild: true, run: "always"
end end

1
tools/test-draft/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
node_modules

View file

@ -0,0 +1,41 @@
import { roomList, createRoom, joinRoom } from "./lobbyapi.mjs";
import Player from "./wsplayer.mjs";
async function createSession(playerCount) {
// Create room
const createResult = await createRoom("test script", "owner");
const roomID = createResult.data.room_id;
// Create owner player
const tp1 = new Player(
createResult.data.ws_url,
createResult.data.auth_token
);
// List rooms and check that ours is available
const listResult = await roomList();
const roomFound =
listResult.data.rooms.filter(x => x.id == roomID).length > 0;
if (!roomFound) {
throw `room ${roomID} not found in list after creation`;
}
// Create other players
let players = [tp1];
for (let i = 1; i < playerCount; i++) {
// Join the room
const joinResult = await joinRoom(roomID, `guest${i}`);
// Create player
const player = new Player(
joinResult.data.ws_url,
joinResult.data.auth_token
);
players.push(player);
}
return players;
}
createSession(4);

View file

@ -0,0 +1,27 @@
import axios from "axios";
const APIEndpoint = "http://192.168.20.20/api";
export async function roomList() {
return await axios.get(`${APIEndpoint}/lobby/room/list`);
}
export async function createRoom(roomName, playerName) {
return await axios.post(`${APIEndpoint}/lobby/room/create`, {
game_id: "mlpccg-mcg",
player_name: playerName,
name: roomName,
allow_spectators: true,
max_players: 8,
max_spectators: 10,
tags: ["draft"]
});
}
export async function joinRoom(roomID, playerName, asPlayer = true) {
return await axios.post(`${APIEndpoint}/lobby/room/join`, {
room_id: roomID,
player_name: playerName,
as_player: asPlayer
});
}

View file

@ -0,0 +1,13 @@
{
"name": "test-draft",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"axios": "^0.19.0",
"ws": "^7.0.1"
},
"scripts": {
"start": "node --experimental-modules ./index.mjs"
}
}

View file

@ -0,0 +1,3 @@
export default class Player {
constructor(wsURL, authToken) {}
}

View file

@ -0,0 +1,47 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
async-limiter@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.0.tgz#78faed8c3d074ab81f22b4e985d79e8738f720f8"
integrity sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==
axios@^0.19.0:
version "0.19.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.0.tgz#8e09bff3d9122e133f7b8101c8fbdd00ed3d2ab8"
integrity sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==
dependencies:
follow-redirects "1.5.10"
is-buffer "^2.0.2"
debug@=3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
dependencies:
ms "2.0.0"
follow-redirects@1.5.10:
version "1.5.10"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==
dependencies:
debug "=3.1.0"
is-buffer@^2.0.2:
version "2.0.3"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.3.tgz#4ecf3fcf749cbd1e472689e109ac66261a25e725"
integrity sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw==
ms@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=
ws@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.0.1.tgz#1a04e86cc3a57c03783f4910fdb090cf31b8e165"
integrity sha512-ILHfMbuqLJvnSgYXLgy4kMntroJpe8hT41dOVWM8bxRuw6TK4mgMp9VJUNsZTEc5Bh+Mbs0DJT4M0N+wBG9l9A==
dependencies:
async-limiter "^1.0.0"