From 00f6c28cfcc9a4d0fafdb255fcef5096a147510f Mon Sep 17 00:00:00 2001 From: jomo Date: Wed, 6 May 2015 22:11:19 +0200 Subject: [PATCH] add tests for 422 / invalid xy / user error --- test/test.js | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/test/test.js b/test/test.js index 0dad70b..3846cd6 100644 --- a/test/test.js +++ b/test/test.js @@ -291,7 +291,7 @@ describe("Crafatar", function() { }); }); - var locations = { + var server_tests = { "avatar with existing username": { url: "http://localhost:3000/avatars/jeb_?size=16", etag: '"a846b82963"', @@ -602,8 +602,8 @@ describe("Crafatar", function() { }, }; - for (var description in locations) { - var location = locations[description]; + for (var description in server_tests) { + var location = server_tests[description]; (function(location) { it("should return correct HTTP response for " + description, function(done) { request.get(location.url, {followRedirect: false, encoding: null}, function(error, res, body) { @@ -641,6 +641,43 @@ describe("Crafatar", function() { }(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) { server.close(function() { done();