From e06b0b29a1e9cae3c84ec394e8532328cd6159f5 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Wed, 3 Jul 2019 17:52:29 +0200 Subject: [PATCH] Start working on a non-interactive test script for drafting --- Vagrantfile | 2 +- tools/test-draft/.gitignore | 1 + tools/test-draft/index.mjs | 41 ++++++++++++++++++++++++++++++ tools/test-draft/lobbyapi.mjs | 27 ++++++++++++++++++++ tools/test-draft/package.json | 13 ++++++++++ tools/test-draft/wsplayer.mjs | 3 +++ tools/test-draft/yarn.lock | 47 +++++++++++++++++++++++++++++++++++ 7 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 tools/test-draft/.gitignore create mode 100644 tools/test-draft/index.mjs create mode 100644 tools/test-draft/lobbyapi.mjs create mode 100644 tools/test-draft/package.json create mode 100644 tools/test-draft/wsplayer.mjs create mode 100644 tools/test-draft/yarn.lock diff --git a/Vagrantfile b/Vagrantfile index ff8a6a5..1ed2cdc 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -7,7 +7,7 @@ Vagrant.configure("2") do |config| end 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_compose, yml: "/vagrant/docker-compose.yml", rebuild: true, run: "always" end diff --git a/tools/test-draft/.gitignore b/tools/test-draft/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/tools/test-draft/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/tools/test-draft/index.mjs b/tools/test-draft/index.mjs new file mode 100644 index 0000000..47b1ae7 --- /dev/null +++ b/tools/test-draft/index.mjs @@ -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); diff --git a/tools/test-draft/lobbyapi.mjs b/tools/test-draft/lobbyapi.mjs new file mode 100644 index 0000000..8a2bcfa --- /dev/null +++ b/tools/test-draft/lobbyapi.mjs @@ -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 + }); +} diff --git a/tools/test-draft/package.json b/tools/test-draft/package.json new file mode 100644 index 0000000..49ead63 --- /dev/null +++ b/tools/test-draft/package.json @@ -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" + } +} diff --git a/tools/test-draft/wsplayer.mjs b/tools/test-draft/wsplayer.mjs new file mode 100644 index 0000000..31c7e9f --- /dev/null +++ b/tools/test-draft/wsplayer.mjs @@ -0,0 +1,3 @@ +export default class Player { + constructor(wsURL, authToken) {} +} diff --git a/tools/test-draft/yarn.lock b/tools/test-draft/yarn.lock new file mode 100644 index 0000000..a867da6 --- /dev/null +++ b/tools/test-draft/yarn.lock @@ -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"