mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 23:53:13 +09:00
Lots of tests
This commit is contained in:
1 parent
8ee3109fbc
commit
2a1badf7cb
4 files changed
+122
-20
No files matched your search
@@ -2,10 +2,11 @@ const assert = require("assert");
|
||||
const child_process = require("child_process");
|
||||
const functions = require("./interfacingFunctions");
|
||||
const luamin = require("luamin");
|
||||
const isFactorioCommand = require("./isFactorioCommand")
|
||||
|
||||
describe("inventoryImports/interfacingFunctions.js", function(){
|
||||
describe("handleInventory(inventory)", function(){
|
||||
it("does things to an object", function(){
|
||||
describe("handleInventory(inventory, config)", function(){
|
||||
/*it("does things to an object", function(){
|
||||
let inventory = {'1':{inventory: {"iron-plate":63,'raw-wood': 4},requestSlots:{'raw-wood': 50,'fast-transport-belt': 50,'express-underground-belt': 50}}};
|
||||
assert.throws(function(){
|
||||
functions.handleInventory(inventory);
|
||||
@@ -14,24 +15,42 @@ describe("inventoryImports/interfacingFunctions.js", function(){
|
||||
let error = ""+err
|
||||
// expected error is here
|
||||
/* istanbul ignore else */
|
||||
if(error.includes("TypeError: Cannot read property 'masterIP' of undefined")) return true
|
||||
/*if(error.includes("TypeError: Cannot read property 'masterIP' of undefined")) return true
|
||||
}, "threw unexpected error");
|
||||
});
|
||||
});*/
|
||||
it("returns false if given invalid input", function(){
|
||||
assert(functions.handleInventory("this is a string") === false, "when given strings it should return false and do nothing");
|
||||
});
|
||||
/*it("Sends post requests", function(){
|
||||
|
||||
var scope = nock('localhost:8080')
|
||||
.post('/api/remove', {
|
||||
username: 'pgte',
|
||||
email: 'pedro.teixeira@gmail.com'
|
||||
})
|
||||
.reply(201, {
|
||||
name: "copper-plate",
|
||||
count: 100
|
||||
});
|
||||
|
||||
|
||||
});*/
|
||||
});
|
||||
describe("pollInventories()", function(){
|
||||
describe("pollInventories(outputfile)", function(){
|
||||
it("Returns a big factorio command as string", function(){
|
||||
let x = functions.pollInventories("output.txt");
|
||||
assert(typeof x == "string", "pollInventories() should always return a string");
|
||||
assert(x.includes("/silent-command "), "This is not a command factorio will accept, please prepend /c");
|
||||
assert(x.includes("/silent-command ")||x.includes("/c "), "This is not a command factorio will accept, please prepend /c");
|
||||
assert(x.length > 20, "LUA string seems to short, this ain't good");
|
||||
});
|
||||
it("Returns valid LUA", function(){
|
||||
let x = functions.pollInventories("output.txt");
|
||||
|
||||
// remove string added to make factorio interpret as command
|
||||
x = x.replace("/silent-command ","").replace("/c ","");
|
||||
|
||||
let y = false;
|
||||
// luamin throws when it recieves something that is invalid LUA
|
||||
assert.doesNotThrow(function(){
|
||||
y = luamin.minify(x);
|
||||
}, "Invalid LUA supplied");
|
||||
@@ -39,6 +58,37 @@ describe("inventoryImports/interfacingFunctions.js", function(){
|
||||
assert(y.length > 20, "Minified LUA too short, something is up");
|
||||
});
|
||||
});
|
||||
describe("insertItemsFromObject(object)", function(){
|
||||
let testObject = {"copper-plate":100, "iron-ore":1337}
|
||||
let playerName = "Danielv123"
|
||||
it("Returns undefined if any of the parameters are missing", function(){
|
||||
let x = functions.insertItemsFromObject();
|
||||
assert(x === undefined);
|
||||
|
||||
let y = functions.insertItemsFromObject(testObject);
|
||||
assert(y === undefined);
|
||||
|
||||
let z = functions.insertItemsFromObject(undefined, playerName);
|
||||
assert(z === undefined);
|
||||
});
|
||||
it("Throws if player name is not a string", function(){
|
||||
assert.throws(function(){
|
||||
let x = functions.insertItemsFromObject(testObject, testObject);
|
||||
}, "playerName is: 'object' instead of string!");
|
||||
});
|
||||
it("Returns a big factorio command as string", function(){
|
||||
let x = functions.insertItemsFromObject(testObject, playerName);
|
||||
|
||||
assert(typeof x == "string", "LUA returned should be a string");
|
||||
assert(x.length > 20, "LUA strings are quite long");
|
||||
assert(x.includes("/silent-command ")||x.includes("/c "), "This is not a command factorio will accept, please prepend /c");
|
||||
});
|
||||
it("The returned string is a valid factorio command", function(){
|
||||
let x = functions.insertItemsFromObject(testObject, playerName);
|
||||
|
||||
assert(isFactorioCommand(x) == true);
|
||||
});
|
||||
});
|
||||
describe("parseJsString(string) => object", function(){
|
||||
it("converts a string with JS object notation to object", function(){
|
||||
let x = functions.parseJsString("{hello:'thisAString!', yes:function(){return 'JS string!'}, not:'json'}");
|
||||
@@ -57,5 +107,5 @@ describe("inventoryImports/interfacingFunctions.js", function(){
|
||||
}
|
||||
}, "should throw when ; are passed because those are the simplest form of xss");
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user