First development of the deploy action (#6)
Some checks failed
Lint / pre-commit Linting (push) Has been cancelled
Some checks failed
Lint / pre-commit Linting (push) Has been cancelled
Deploy js code to an instance of screeps. Some debugging tools are implemented. Reviewed-on: #6 Co-authored-by: Philipp Horstenkamp <philipp@horstenkamp.de> Co-committed-by: Philipp Horstenkamp <philipp@horstenkamp.de>
This commit is contained in:
159
node_modules/screeps-api/test/api.general.js
generated
vendored
Normal file
159
node_modules/screeps-api/test/api.general.js
generated
vendored
Normal file
@ -0,0 +1,159 @@
|
||||
const assert = require('assert')
|
||||
const _ = require('lodash')
|
||||
const { ScreepsAPI } = require('../')
|
||||
const auth = require('./credentials')
|
||||
|
||||
describe('ScreepsAPI', function () {
|
||||
this.slow(2000)
|
||||
this.timeout(5000)
|
||||
|
||||
describe('.constructor()', function () {
|
||||
it('should save passed options', function () {
|
||||
let options = {
|
||||
email: 'screeps@email.com',
|
||||
// don't use a fake password here or API will try to authenticate
|
||||
protocol: 'https',
|
||||
hostname: 'screeps.com',
|
||||
port: 443,
|
||||
path: '/'
|
||||
}
|
||||
let api = new ScreepsAPI(options)
|
||||
_.each(options, (value, key) => assert.equal(api.opts[key], value, `invalid ${key} option`))
|
||||
})
|
||||
it('should assign default options when needed', function () {
|
||||
const DEFAULTS = {
|
||||
protocol: 'https',
|
||||
hostname: 'screeps.com',
|
||||
port: 443,
|
||||
path: '/'
|
||||
}
|
||||
let api = new ScreepsAPI({})
|
||||
_.each(DEFAULTS, (value, key) => assert.equal(api.opts[key], value, `invalid ${key} default option`))
|
||||
})
|
||||
})
|
||||
|
||||
describe('.me()', function () {
|
||||
it('should return user informations from `/api/auth/me` endpoint', async function () {
|
||||
let opts = _.omit(auth, ['username', 'password'])
|
||||
let api = new ScreepsAPI(opts)
|
||||
await api.auth(auth.username, auth.password)
|
||||
let infos = await api.me()
|
||||
assert.equal(infos.ok, 1, 'incorrect server answer: ok should be 1')
|
||||
assert(_.has(infos, 'email'), 'answer has no email field')
|
||||
assert(_.has(infos, 'badge'), 'answer has no badge field')
|
||||
assert(_.has(infos, 'username'), 'answer has no username field')
|
||||
})
|
||||
})
|
||||
|
||||
describe('.mapToShard()', function () {
|
||||
it('should do things... but I\'m not sure what exactly...')
|
||||
})
|
||||
|
||||
describe('.setServer()', function () {
|
||||
it('should save passed options', function () {
|
||||
let options = {
|
||||
email: 'screeps@email.com',
|
||||
protocol: 'https',
|
||||
hostname: 'screeps.com',
|
||||
port: 443,
|
||||
path: '/'
|
||||
}
|
||||
let api = new ScreepsAPI()
|
||||
api.setServer(options)
|
||||
_.each(options, (value, key) => assert.equal(api.opts[key], value, `invalid ${key} option`))
|
||||
})
|
||||
it('should compute opts.url if opts.url wasn\'t provided', function () {
|
||||
let options1 = { protocol: 'http', hostname: 'screeps.com' }
|
||||
let options2 = { protocol: 'https', hostname: 'screeps.com', path: '/ptr/' }
|
||||
let options3 = { protocol: 'https', hostname: 'screeps.com', port: 80, path: '/' }
|
||||
let api = new ScreepsAPI()
|
||||
api.setServer(options1)
|
||||
assert.equal(api.opts['url'], 'http://screeps.com:443/', 'invalid computed url')
|
||||
api.setServer(options2)
|
||||
assert.equal(api.opts['url'], 'https://screeps.com:443/ptr/', 'invalid computed url')
|
||||
api.setServer(options3)
|
||||
assert.equal(api.opts['url'], 'https://screeps.com:80/', 'invalid computed url')
|
||||
})
|
||||
it('should compute opts.pathname if opts.url wasn\'t provided', function () {
|
||||
let api = new ScreepsAPI()
|
||||
api.setServer({ path: '/ptr/' })
|
||||
assert.equal(api.opts['pathname'], '/ptr/', 'pathname was not updated')
|
||||
api.setServer({ path: '/' })
|
||||
assert.equal(api.opts['pathname'], '/', 'pathname was not updated')
|
||||
})
|
||||
})
|
||||
|
||||
describe('.auth()', function () {
|
||||
it('should save email and password', async function () {
|
||||
let api = new ScreepsAPI()
|
||||
await api.auth('screeps@email.com', 'invalid_password').catch(() => { /* do nothing */; })
|
||||
assert.equal(api.opts.email, 'screeps@email.com', `invalid email option`)
|
||||
assert.equal(api.opts.password, 'invalid_password', `invalid email option`)
|
||||
})
|
||||
it('should update options if opt object was passed', async function () {
|
||||
let options = {
|
||||
protocol: 'https',
|
||||
hostname: 'screeps.com',
|
||||
port: 443
|
||||
}
|
||||
let api = new ScreepsAPI()
|
||||
await api.auth('email', 'password', options).catch(() => { /* do nothing */; })
|
||||
_.each(options, (value, key) => assert.equal(api.opts[key], value, `invalid ${key} option`))
|
||||
})
|
||||
it('should authenticate and get token', async function () {
|
||||
let event = false
|
||||
let opts = _.omit(auth, ['username', 'password'])
|
||||
let api = new ScreepsAPI(opts)
|
||||
api.on('token', () => event = true)
|
||||
await api.auth(auth.username, auth.password)
|
||||
assert(event, 'token event was not emited')
|
||||
assert(_.has(api, 'token'), 'token was not saved')
|
||||
assert.equal(api.__authed, true, 'internal state has not changed (api.__authed)')
|
||||
})
|
||||
it('should reject promise in case of error', async function () {
|
||||
try {
|
||||
let api = new ScreepsAPI()
|
||||
await api.auth(auth.username, 'bad password')
|
||||
} catch (err) {
|
||||
assert(err.message.match(/Not authorized/i), 'wrong error message')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('.req()', function () {
|
||||
it('should send request to game server and get the answer')
|
||||
it('can send GET and POST requests')
|
||||
it('should throw an error in case of 401 and if not authenticated')
|
||||
it('should read, save and emit authentication token if any')
|
||||
it('should use opts.path correctly (ie: for PTR)')
|
||||
// Disabled, offifical PTR is down
|
||||
// it('should use opts.path correctly (ie: for PTR)', async function() {
|
||||
// // This test must be run against official server (the only one to use PTR)
|
||||
// let opts = {
|
||||
// protocol: 'https',
|
||||
// hostname: 'screeps.com',
|
||||
// port: 443,
|
||||
// }
|
||||
// // Get official server time
|
||||
// let api1 = new ScreepsAPI(opts)
|
||||
// let res1 = await api1.raw.game.time()
|
||||
// let time1 = res1.time
|
||||
// // Get PTR time
|
||||
// opts.path = '/ptr'
|
||||
// let api2 = new ScreepsAPI(opts)
|
||||
// let res2 = await api2.raw.game.time()
|
||||
// let time2 = res2.time
|
||||
// // Compare them
|
||||
// assert.notEqual(time1, time2, 'time for official and PTR should be different')
|
||||
// })
|
||||
it('should throw an error if response.ok !== 1')
|
||||
})
|
||||
|
||||
describe('.gz()', function () {
|
||||
it('should unzip data and return JSON')
|
||||
})
|
||||
|
||||
describe('.inflate()', function () {
|
||||
it('should inflate data')
|
||||
})
|
||||
})
|
45
node_modules/screeps-api/test/api.raw.auth.js
generated
vendored
Normal file
45
node_modules/screeps-api/test/api.raw.auth.js
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
const assert = require('assert');
|
||||
const _ = require('lodash');
|
||||
const { ScreepsAPI } = require('../');
|
||||
const auth = require('./credentials')
|
||||
|
||||
describe('api.raw.auth', function() {
|
||||
|
||||
this.slow(2000);
|
||||
this.timeout(5000);
|
||||
|
||||
describe('.signin (email, password)', function() {
|
||||
it('should send a POST request to /api/auth/signin and authenticate', async function() {
|
||||
let opts = _.omit(auth, ['username', 'password'])
|
||||
let api = new ScreepsAPI(opts)
|
||||
let res = await api.raw.auth.signin(auth.username, auth.password)
|
||||
assert(_.has(res, 'token'), 'no token found in server answer')
|
||||
assert.equal(res.ok, 1, 'res.ok is incorrect')
|
||||
})
|
||||
it('should reject promise if unauthorized', async function() {
|
||||
try {
|
||||
let api = new ScreepsAPI()
|
||||
await api.raw.auth.signin(auth.username, 'invalid_password')
|
||||
} catch (err) {
|
||||
assert(err.message.match(/Not authorized/i), 'wrong error message')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('.steamTicket (ticket, useNativeAuth = false)', function() {
|
||||
it('should do things... but I\'m not sure what exactly...')
|
||||
})
|
||||
|
||||
describe('.me ()', function() {
|
||||
it('should return user informations from `/api/auth/me` endpoint', async function() {
|
||||
let opts = _.omit(auth, ['username', 'password'])
|
||||
let api = new ScreepsAPI(opts)
|
||||
await api.auth(auth.username, auth.password)
|
||||
let res = await api.raw.auth.me()
|
||||
assert(_.has(res, 'email'), 'response has no email field')
|
||||
assert(_.has(res, 'badge'), 'response has no badge field')
|
||||
assert(_.has(res, 'username'), 'response has no username field')
|
||||
})
|
||||
})
|
||||
|
||||
})
|
120
node_modules/screeps-api/test/api.raw.game.js
generated
vendored
Normal file
120
node_modules/screeps-api/test/api.raw.game.js
generated
vendored
Normal file
@ -0,0 +1,120 @@
|
||||
const assert = require('assert');
|
||||
const _ = require('lodash');
|
||||
const { ScreepsAPI } = require('../');
|
||||
const auth = require('./credentials')
|
||||
|
||||
describe('api.raw.userMessages', function() {
|
||||
|
||||
this.slow(2000);
|
||||
this.timeout(5000);
|
||||
|
||||
describe('.mapStats (rooms, statName, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.genUniqueObjectName (type, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.checkUniqueObjectName (type, name, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.placeSpawn (room, x, y, name, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.createFlag (room, x, y, name, color = 1, secondaryColor = 1, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.genUniqueFlagName (shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.checkUniqueFlagName (name, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.changeFlagColor (color = 1, secondaryColor = 1, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.removeFlag (room, name, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.addObjectIntent (room, name, intent, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.createConstruction (room, x, y, structureType, name, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.setNotifyWhenAttacked (_id, enabled = true, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.createInvader (room, x, y, size, type, boosted = false, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.removeInvader (_id, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.time (shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.worldSize (shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.roomTerrain (room, encoded = 1, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.roomStatus (room, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.roomOverview (room, interval = 8, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.market.ordersIndex (shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.market.myOrders ()', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.market.orders (resourceType, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.market.stats (resourceType, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
// This endpoint is not implemented on S+
|
||||
describe.skip('.shards.info ()', function() {
|
||||
it('should send a request to /api/shards/info and return shards informations', async function() {
|
||||
let opts = _.omit(auth, ['email', 'password'])
|
||||
let api = new ScreepsAPI(opts)
|
||||
let res = await api.raw.game.shards.info()
|
||||
assert.equal(res.ok, 1, 'incorrect server response: ok should be 1')
|
||||
assert(_.has(res, 'shards'), 'response has no shards field')
|
||||
res.shards.forEach((shard, idx) => {
|
||||
assert(_.has(shard, 'name'), `shard ${idx} has no name field`)
|
||||
assert(_.has(shard, 'rooms'), `shard ${idx} has no rooms field`)
|
||||
assert(_.has(shard, 'users'), `shard ${idx} has no users field`)
|
||||
assert(_.has(shard, 'tick'), `shard ${idx} has no tick field`)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
})
|
62
node_modules/screeps-api/test/api.raw.general.js
generated
vendored
Normal file
62
node_modules/screeps-api/test/api.raw.general.js
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
const assert = require('assert');
|
||||
const _ = require('lodash');
|
||||
const { ScreepsAPI } = require('../');
|
||||
const auth = require('./credentials')
|
||||
|
||||
describe('api.raw', function() {
|
||||
|
||||
this.slow(2000);
|
||||
this.timeout(5000);
|
||||
|
||||
describe('.version()', function() {
|
||||
it('should call /api/version endpoint and return version information', async function() {
|
||||
let opts = _.omit(auth, ['username', 'password'])
|
||||
let api = new ScreepsAPI(opts)
|
||||
let res = await api.raw.version()
|
||||
assert.equal(res.ok, 1, 'incorrect server response: ok should be 1')
|
||||
assert(_.has(res, 'protocol'), 'response has no protocol field')
|
||||
assert(_.has(res, 'serverData.historyChunkSize'), 'response has no serverData.historyChunkSize field')
|
||||
if (api.opts.hostname === 'screeps.com') {
|
||||
assert(_.has(res, 'package'), 'response has no package field')
|
||||
assert(_.has(res, 'serverData.shards'), 'response has no serverData.shards field')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('.authmod()', function() {
|
||||
it('should return server name from /authmod for private servers with authmod', async function() {
|
||||
let opts = _.omit(auth, ['username', 'password'])
|
||||
let api = new ScreepsAPI(opts)
|
||||
let res = await api.raw.authmod()
|
||||
if (api.opts.hostname === 'screeps.com') {
|
||||
assert.equal(res.name, 'official', 'invalid name for official server')
|
||||
} else {
|
||||
assert.equal(res.ok, 1, 'incorrect server response: ok should be 1')
|
||||
assert(_.has(res, 'name'), 'server response should have a name field')
|
||||
assert(_.has(res, 'version'), 'server response should have a version field')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// This API is not implemented for private servers
|
||||
describe.skip('.history(room, tick)', function() {
|
||||
it('should return room history as a json file', async function() {
|
||||
let opts = _.omit(auth, ['username', 'password'])
|
||||
let api = new ScreepsAPI(opts)
|
||||
// Get current tick (as history is not kept forever)
|
||||
let res = await api.raw.game.time('shard1')
|
||||
let time = res.time - 1000 // history is not available right away
|
||||
// Make sure that time is not a multiple of 20 or 100
|
||||
time = (time % 20 === 0) ? time - 10 : time
|
||||
// Try to get history for W1N1
|
||||
let json = await api.raw.history('W1N1', time, 'shard1')
|
||||
// Verify results
|
||||
assert(_.has(json, 'ticks'), 'result has no ticks field')
|
||||
assert(_.size(json.ticks) >= 20, 'results are incomplete ; official server usually returns 100 ticks and private servers should return at least 20 ticks')
|
||||
assert.equal(json.room, 'W1N1', 'result room is incorrect')
|
||||
assert(_.has(json, 'timestamp'), 'result has no timestamp field')
|
||||
assert(_.has(json, 'base'), 'result has no base field')
|
||||
})
|
||||
})
|
||||
|
||||
})
|
59
node_modules/screeps-api/test/api.raw.leaderboard.js
generated
vendored
Normal file
59
node_modules/screeps-api/test/api.raw.leaderboard.js
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
const assert = require('assert');
|
||||
const _ = require('lodash');
|
||||
const { ScreepsAPI } = require('../');
|
||||
const auth = require('./credentials')
|
||||
|
||||
describe('api.raw.leaderboard', function() {
|
||||
|
||||
this.slow(2000);
|
||||
this.timeout(5000);
|
||||
|
||||
describe('.list ()', function() {
|
||||
it('should call /api/leaderboard/list endpoint and return leaderboard inforamtion', async function() {
|
||||
let opts = _.omit(auth, ['username', 'password'])
|
||||
let api = new ScreepsAPI(opts)
|
||||
let res = await api.raw.leaderboard.list()
|
||||
assert.equal(res.ok, 1, 'incorrect server response: ok should be 1')
|
||||
assert(_.has(res, 'list'), 'server response should have a list field')
|
||||
assert(_.has(res, 'count'), 'server response should have a count field')
|
||||
assert(_.has(res, 'users'), 'server response should have a users field')
|
||||
if (api.opts.url.includes('screeps.com')) {
|
||||
assert(_.size(res.list) > 0, 'leaderboard list is empty')
|
||||
assert(_.size(res.users) > 0, 'leaderboard users is empty')
|
||||
assert(res.count > 0, 'leaderboard count equals 0 (or maybe is negative)')
|
||||
}
|
||||
})
|
||||
it('should return leaderboard data based on world or power stats', async function() {
|
||||
let opts = _.omit(auth, ['username', 'password'])
|
||||
let api = new ScreepsAPI(opts)
|
||||
let res1 = await api.raw.leaderboard.list(10, 'world')
|
||||
let res2 = await api.raw.leaderboard.list(10, 'power')
|
||||
if (api.opts.url.includes('screeps.com')) {
|
||||
assert.notEqual(_.first(res1.list), _.first(res2.list), 'same player shouldn\'t be #1')
|
||||
}
|
||||
})
|
||||
it('should return paginated data', async function() {
|
||||
let opts = _.omit(auth, ['username', 'password'])
|
||||
let api = new ScreepsAPI(opts)
|
||||
let res1 = await api.raw.leaderboard.list(5, 'world')
|
||||
let res2 = await api.raw.leaderboard.list(10, 'world')
|
||||
let res3 = await api.raw.leaderboard.list(10, 'world', 9)
|
||||
if (api.opts.url.includes('screeps.com')) {
|
||||
assert.equal(_.size(res1.list), 5, 'requested top 5 and got a shorter or longer list')
|
||||
assert.equal(_.size(res2.list), 10, 'requested top 10 and got a shorter or longer list')
|
||||
assert.notEqual(_.first(res1.list).user, _.first(res3.list).user, 'offset is not working')
|
||||
assert.equal(_.first(res1.list).user, _.first(res2.list).user, 'player #1 is incoherent')
|
||||
assert.equal(_.last(res2.list).user, _.first(res3.list).user, 'player #9 is incoherent')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('.find (username, mode = \'world\', season = \'\')', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.seasons ()', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
})
|
27
node_modules/screeps-api/test/api.raw.register.js
generated
vendored
Normal file
27
node_modules/screeps-api/test/api.raw.register.js
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
const assert = require('assert');
|
||||
const _ = require('lodash');
|
||||
const { ScreepsAPI } = require('../');
|
||||
const auth = require('./credentials')
|
||||
|
||||
describe('api.raw.register', function() {
|
||||
|
||||
this.slow(2000);
|
||||
this.timeout(5000);
|
||||
|
||||
describe('.checkEmail (email)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.checkUsername (username)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.setUsername (username)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.submit (username, email, password, modules)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
})
|
204
node_modules/screeps-api/test/api.raw.user.js
generated
vendored
Normal file
204
node_modules/screeps-api/test/api.raw.user.js
generated
vendored
Normal file
@ -0,0 +1,204 @@
|
||||
const assert = require('assert');
|
||||
const _ = require('lodash');
|
||||
const { ScreepsAPI } = require('../');
|
||||
const auth = require('./credentials')
|
||||
|
||||
describe('api.raw.user', function() {
|
||||
|
||||
this.slow(3000);
|
||||
this.timeout(5000);
|
||||
|
||||
describe('.badge (badge)', function() {
|
||||
it('should send a request to /api/user/badge which sets user badge', async function() {
|
||||
let opts = _.omit(auth, ['username', 'password'])
|
||||
let api = new ScreepsAPI(opts)
|
||||
await api.auth(auth.username, auth.password)
|
||||
// Save previous badge
|
||||
let res = await api.me()
|
||||
let initialBadge = res.badge
|
||||
// Set new badge
|
||||
let newBadge = { type: 16, color1: '#000000', color2: '#000000', color3:'#000000', param: 100, flip: false }
|
||||
res = await api.raw.user.badge(newBadge)
|
||||
assert.equal(res.ok, 1, 'incorrect server response: ok should be 1')
|
||||
// Check that badge was effectively changed
|
||||
res = await api.me()
|
||||
_.each(res.badge, (value, key) => {
|
||||
assert.equal(value, newBadge[key], `badge ${key} is incorrect`)
|
||||
})
|
||||
// Reset badge
|
||||
res = await api.raw.user.badge(initialBadge)
|
||||
})
|
||||
})
|
||||
|
||||
describe('.respawn ()', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.branches ()', function() {
|
||||
it('should send a request to /api/user/branches and return branches list', async function() {
|
||||
let opts = _.omit(auth, ['username', 'password'])
|
||||
let api = new ScreepsAPI(opts)
|
||||
await api.auth(auth.username, auth.password)
|
||||
let res = await api.raw.user.branches()
|
||||
assert.equal(res.ok, 1, 'incorrect server response: ok should be 1')
|
||||
assert(res.list.length > 0, 'no branch found')
|
||||
})
|
||||
})
|
||||
|
||||
describe('.cloneBranch (branch, newName, defaultModules)', function() {
|
||||
it('should send a request to /api/user/clone-branch in order to clone @branch into @newName', async function() {
|
||||
let opts = _.omit(auth, ['username', 'password'])
|
||||
let api = new ScreepsAPI(opts)
|
||||
await api.auth(auth.username, auth.password)
|
||||
// Create a new branch
|
||||
let res = await api.raw.user.cloneBranch('default', 'screeps-api-testing')
|
||||
assert.equal(res.ok, 1, 'incorrect server response: ok should be 1')
|
||||
// Check if branch was indeed created
|
||||
res = await api.raw.user.branches()
|
||||
let found = _.find(res.list, { branch: 'screeps-api-testing' })
|
||||
assert(found != null, 'branch was not cloned')
|
||||
})
|
||||
})
|
||||
|
||||
describe('.setActiveBranch (branch, activeName)', function() {
|
||||
it('should send a request to /api/user/set-active-branch in order to define @branch as active', async function() {
|
||||
let opts = _.omit(auth, ['username', 'password'])
|
||||
let api = new ScreepsAPI(opts)
|
||||
await api.auth(auth.username, auth.password)
|
||||
// Find current active branch for simulator
|
||||
let res = await api.raw.user.branches()
|
||||
let initialBranch = _.find(res.list, { activeSim: true })
|
||||
assert(initialBranch != null, 'cannot find current active branch for simulator')
|
||||
// Change active branch for simulator
|
||||
res = await api.raw.user.setActiveBranch('screeps-api-testing', 'activeSim')
|
||||
assert.equal(res.ok, 1, 'incorrect server response: ok should be 1')
|
||||
// Check if branch was indeed changed
|
||||
res = await api.raw.user.branches()
|
||||
let found = _.find(res.list, { activeSim: true })
|
||||
assert.equal(found.branch, 'screeps-api-testing', 'branch was not set')
|
||||
// Reset branch back to initial state
|
||||
await api.raw.user.setActiveBranch(initialBranch.branch, 'activeSim')
|
||||
})
|
||||
})
|
||||
|
||||
describe('.deleteBranch (branch)', function() {
|
||||
it('should send a request to /api/user/delete-branch in order to delete @branch', async function() {
|
||||
let opts = _.omit(auth, ['username', 'password'])
|
||||
let api = new ScreepsAPI(opts)
|
||||
await api.auth(auth.username, auth.password)
|
||||
// Delete 'screeps-api-testing' branch
|
||||
let res = await api.raw.user.deleteBranch('screeps-api-testing')
|
||||
assert.equal(res.ok, 1, 'incorrect server response: ok should be 1')
|
||||
// Check if branch was indeed deleted
|
||||
res = await api.raw.user.branches()
|
||||
let found = _.find(res.list, { branch: 'screeps-api-testing' })
|
||||
assert(found == null, 'branch was not deleted')
|
||||
})
|
||||
})
|
||||
|
||||
describe('.notifyPrefs (prefs)', function() {
|
||||
it('should send a request to /api/user/notify-prefs which sets user preferences', async function() {
|
||||
let opts = _.omit(auth, ['username', 'password'])
|
||||
let api = new ScreepsAPI(opts)
|
||||
await api.auth(auth.username, auth.password)
|
||||
let defaults = { disabled: false, disabledOnMessages: false, sendOnline: true, interval: 5, errorsInterval: 30 }
|
||||
// Save previous prefs
|
||||
let res = await api.me()
|
||||
let initialPrefs = _.merge(defaults, res.notifyPrefs)
|
||||
// Set new preferences
|
||||
let newPrefs = { disabled: true, disabledOnMessages: true, sendOnline: false, interval: 60, errorsInterval: 60 }
|
||||
res = await api.raw.user.notifyPrefs(newPrefs)
|
||||
assert.equal(res.ok, 1, 'incorrect server response: ok should be 1')
|
||||
// Check that preferences were indeed changed
|
||||
res = await api.me()
|
||||
_.each(res.notifyPrefs, (value, key) => {
|
||||
assert.equal(value, newPrefs[key], `preference ${key} is incorrect`)
|
||||
})
|
||||
// Reset preferences
|
||||
res = await api.raw.user.notifyPrefs(initialPrefs)
|
||||
})
|
||||
})
|
||||
|
||||
describe('.tutorialDone ()', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.email (email)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.worldStartRoom (shard)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.worldStatus ()', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.code.get (branch)', function() {
|
||||
it('should do untested things (for now)')
|
||||
it('should send a GET request to /api/user/code and return user code from specified branch.', async function() {
|
||||
let opts = _.omit(auth, ['username', 'password'])
|
||||
let api = new ScreepsAPI(opts)
|
||||
await api.auth(auth.username, auth.password)
|
||||
let res = await api.raw.user.code.get('default')
|
||||
assert.equal(res.ok, 1, 'incorrect server response: ok should be 1')
|
||||
assert(_.has(res, 'modules'), 'response has no modules field')
|
||||
assert(_.has(res, 'branch'), 'response has no branch field')
|
||||
assert.equal(res.branch, 'default', 'branch is incorrect')
|
||||
})
|
||||
})
|
||||
|
||||
describe('.code.set (branch, modules, _hash)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.respawnProhibitedRooms ()', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.memory.get (path, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.memory.set (path, value, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.segment.get (segment, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.segment.set (segment, data, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.find (username)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.findById (id)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.stats (interval)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.rooms (id)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.overview (interval, statName)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.moneyHistory (page = 0)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.console (expression, shard = DEFAULT_SHARD)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
})
|
31
node_modules/screeps-api/test/api.raw.userMessage.js
generated
vendored
Normal file
31
node_modules/screeps-api/test/api.raw.userMessage.js
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
const assert = require('assert');
|
||||
const _ = require('lodash');
|
||||
const { ScreepsAPI } = require('../');
|
||||
const auth = require('./credentials')
|
||||
|
||||
describe('api.raw.userMessages', function() {
|
||||
|
||||
this.slow(2000);
|
||||
this.timeout(5000);
|
||||
|
||||
describe('.list (respondent)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.index ()', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.unreadCount ()', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.send (respondent, text)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
describe('.markRead (id)', function() {
|
||||
it('should do untested things (for now)')
|
||||
})
|
||||
|
||||
})
|
7
node_modules/screeps-api/test/credentials.js
generated
vendored
Normal file
7
node_modules/screeps-api/test/credentials.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
username: 'screeps-api-testing',
|
||||
password: 'mG3r3TIRbDnSrraGnOdIQyBek1hfxu',
|
||||
protocol: 'https',
|
||||
hostname: 'server1.screepspl.us',
|
||||
port: 443,
|
||||
};
|
Reference in New Issue
Block a user