mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 00:13:13 +09:00
#58 added test for /api/remove
This commit is contained in:
1 parent
0dd6315abc
commit
ea603c61fd
2 files changed
+22
-10
No files matched your search
@@ -271,12 +271,13 @@ app.post("/api/remove", function(req, res) {
|
|||||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||||
// save items we get
|
// save items we get
|
||||||
var object = req.body;
|
var object = req.body;
|
||||||
if(!object.instanceName) {
|
|
||||||
object.instanceName = "unknown"
|
|
||||||
}
|
|
||||||
if(!object.instanceID) {
|
if(!object.instanceID) {
|
||||||
object.instanceID = "unknown"
|
object.instanceID = "unknown"
|
||||||
}
|
}
|
||||||
|
if(!object.instanceName) {
|
||||||
|
object.instanceName = "unknown";
|
||||||
|
}
|
||||||
|
if(slaves[object.instanceID]) object.instanceName = slaves[object.instanceID].instanceName;
|
||||||
let item = db.items[object.name]
|
let item = db.items[object.name]
|
||||||
// console.dir(doc);
|
// console.dir(doc);
|
||||||
if (!item) {
|
if (!item) {
|
||||||
|
|||||||
+18
-7
@@ -88,19 +88,14 @@ describe('Master server endpoint testing', function() {
|
|||||||
assert(!err)
|
assert(!err)
|
||||||
assert.equal(res.text, "success", "something went wrong with the request")
|
assert.equal(res.text, "success", "something went wrong with the request")
|
||||||
done();
|
done();
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("#GET /api/inventory", function(){
|
describe("#GET /api/inventory", function(){
|
||||||
it("returns the masters current inventory", function(done){
|
it("returns the masters current inventory", function(done){
|
||||||
persistentMaster.get("/api/inventory").end(function(err,res){
|
persistentMaster.get("/api/inventory").end(function(err,res){
|
||||||
assert.equal(res.statusCode, 200);
|
assert.equal(res.statusCode, 200);
|
||||||
let inventory
|
let inventory = JSON.parse(res.text);
|
||||||
try {
|
|
||||||
inventory = JSON.parse(res.text);
|
|
||||||
} catch (e){
|
|
||||||
assert(!e);
|
|
||||||
}
|
|
||||||
assert.equal(typeof inventory, "object", "Inventory should be an object");
|
assert.equal(typeof inventory, "object", "Inventory should be an object");
|
||||||
assert(inventory.length >= 1, "There should be at least 1 entry in the inventory");
|
assert(inventory.length >= 1, "There should be at least 1 entry in the inventory");
|
||||||
|
|
||||||
@@ -113,4 +108,20 @@ describe('Master server endpoint testing', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe("#POST /api/remove", function(){
|
||||||
|
it("returns an itemStack of how many items were removed", function(done){
|
||||||
|
persistentMaster.post("/api/remove")
|
||||||
|
.send({
|
||||||
|
name:"steel-plate",
|
||||||
|
count:10
|
||||||
|
})
|
||||||
|
.end(function(err,res){
|
||||||
|
assert(!err);
|
||||||
|
assert.equal(res.text, '{"name":"steel-plate","count":10,"instanceID":"unknown","instanceName":"unknown"}', "Something is wrong with the response, maybe the format changed slightly or you didn't have enough steel?");
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user