add tests for 422 / invalid xy / user error

This commit is contained in:
jomo 2015-05-06 22:11:19 +02:00
parent d27eb0049f
commit 00f6c28cfc

View File

@ -291,7 +291,7 @@ describe("Crafatar", function() {
}); });
}); });
var locations = { var server_tests = {
"avatar with existing username": { "avatar with existing username": {
url: "http://localhost:3000/avatars/jeb_?size=16", url: "http://localhost:3000/avatars/jeb_?size=16",
etag: '"a846b82963"', etag: '"a846b82963"',
@ -602,8 +602,8 @@ describe("Crafatar", function() {
}, },
}; };
for (var description in locations) { for (var description in server_tests) {
var location = locations[description]; var location = server_tests[description];
(function(location) { (function(location) {
it("should return correct HTTP response for " + description, function(done) { it("should return correct HTTP response for " + description, function(done) {
request.get(location.url, {followRedirect: false, encoding: null}, function(error, res, body) { request.get(location.url, {followRedirect: false, encoding: null}, function(error, res, body) {
@ -641,6 +641,43 @@ describe("Crafatar", function() {
}(location)); }(location));
} }
it("should return a 422 (invalid size)", function(done) {
var size = config.max_size + 1;
request.get("http://localhost:3000/avatars/Jake_0?size=" + size, function(error, res, body) {
assert.strictEqual(res.statusCode, 422);
done();
});
});
it("should return a 422 (invalid scale)", function(done) {
var scale = config.max_scale + 1;
request.get("http://localhost:3000/renders/head/Jake_0?scale=" + scale, function(error, res, body) {
assert.strictEqual(res.statusCode, 422);
done();
});
});
it("should return a 422 (invalid render type)", function(done) {
request.get("http://localhost:3000/renders/invalid/Jake_0", function(error, res, body) {
assert.strictEqual(res.statusCode, 422);
done();
});
});
// testing all paths for invalid userid
var locations = ["avatars", "skins", "capes", "renders/body", "renders/head"];
for (var l in locations) {
var location = locations[l];
(function(location) {
it("should return a 422 (invalid id " + location + ")", function(done) {
request.get("http://localhost:3000/" + location + "/thisisaninvaliduuid", function(error, res, body) {
assert.strictEqual(res.statusCode, 422);
done();
});
});
})(location);
}
after(function(done) { after(function(done) {
server.close(function() { server.close(function() {
done(); done();