mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-21 23:41:18 +01:00
lint tests
This commit is contained in:
parent
94322f3a77
commit
7f8da3abe2
79
test/test.js
79
test/test.js
@ -1,3 +1,5 @@
|
|||||||
|
/* globals describe, it, before, after */
|
||||||
|
/* eslint no-loop-func:0 guard-for-in:0 */
|
||||||
var networking = require("../lib/networking");
|
var networking = require("../lib/networking");
|
||||||
var helpers = require("../lib/helpers");
|
var helpers = require("../lib/helpers");
|
||||||
var logging = require("../lib/logging");
|
var logging = require("../lib/logging");
|
||||||
@ -119,13 +121,14 @@ describe("Crafatar", function() {
|
|||||||
it("should not exist (uuid)", function(done) {
|
it("should not exist (uuid)", function(done) {
|
||||||
var number = getRandomInt(0, 9).toString();
|
var number = getRandomInt(0, 9).toString();
|
||||||
networking.get_profile(rid, Array(33).join(number), function(err, profile) {
|
networking.get_profile(rid, Array(33).join(number), function(err, profile) {
|
||||||
|
assert.ifError(err);
|
||||||
assert.strictEqual(profile, null);
|
assert.strictEqual(profile, null);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("should not exist (username)", function(done) {
|
it("should not exist (username)", function(done) {
|
||||||
networking.get_username_url(rid, "Steve", 0, function(err, profile) {
|
networking.get_username_url(rid, "Steve", 0, function(err, profile) {
|
||||||
assert.strictEqual(err, null);
|
assert.ifError(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -134,6 +137,7 @@ describe("Crafatar", function() {
|
|||||||
it("uuid's account should exist, but skin should not", function(done) {
|
it("uuid's account should exist, but skin should not", function(done) {
|
||||||
// profile "Alex" - hoping it'll never have a skin
|
// profile "Alex" - hoping it'll never have a skin
|
||||||
networking.get_profile(rid, "ec561538f3fd461daff5086b22154bce", function(err, profile) {
|
networking.get_profile(rid, "ec561538f3fd461daff5086b22154bce", function(err, profile) {
|
||||||
|
assert.ifError(err);
|
||||||
assert.notStrictEqual(profile, null);
|
assert.notStrictEqual(profile, null);
|
||||||
networking.get_uuid_url(profile, 1, function(url) {
|
networking.get_uuid_url(profile, 1, function(url) {
|
||||||
assert.strictEqual(url, null);
|
assert.strictEqual(url, null);
|
||||||
@ -146,22 +150,22 @@ describe("Crafatar", function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
for (var a in alex_ids) {
|
for (var a in alex_ids) {
|
||||||
var alex_id = alex_ids[a];
|
var alexid = alex_ids[a];
|
||||||
(function(alex_id) {
|
(function(alex_id) {
|
||||||
it("UUID " + alex_id + " should default to Alex", function(done) {
|
it("UUID " + alex_id + " should default to Alex", function(done) {
|
||||||
assert.strictEqual(skins.default_skin(alex_id), "alex");
|
assert.strictEqual(skins.default_skin(alex_id), "alex");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
})(alex_id);
|
}(alexid));
|
||||||
}
|
}
|
||||||
for (var s in steve_ids) {
|
for (var s in steve_ids) {
|
||||||
var steve_id = steve_ids[s];
|
var steveid = steve_ids[s];
|
||||||
(function(steve_id) {
|
(function(steve_id) {
|
||||||
it("UUID " + steve_id + " should default to Steve", function(done) {
|
it("UUID " + steve_id + " should default to Steve", function(done) {
|
||||||
assert.strictEqual(skins.default_skin(steve_id), "steve");
|
assert.strictEqual(skins.default_skin(steve_id), "steve");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
})(steve_id);
|
}(steveid));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
describe("Errors", function() {
|
describe("Errors", function() {
|
||||||
@ -203,20 +207,20 @@ describe("Crafatar", function() {
|
|||||||
it("should ignore file updates on invalid files", function(done) {
|
it("should ignore file updates on invalid files", function(done) {
|
||||||
assert.doesNotThrow(function() {
|
assert.doesNotThrow(function() {
|
||||||
cache.update_timestamp(rid, "0123456789abcdef0123456789abcdef", "invalid-file.png", false, function(err) {
|
cache.update_timestamp(rid, "0123456789abcdef0123456789abcdef", "invalid-file.png", false, function(err) {
|
||||||
|
assert.ifError(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("should not find the file", function(done) {
|
it("should not find the file", function(done) {
|
||||||
skins.open_skin(rid, "non/existent/path", function(err, img) {
|
skins.open_skin(rid, "non/existent/path", function(err, img) {
|
||||||
assert.notStrictEqual(err, null);
|
assert(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Server", function() {
|
describe("Server", function() {
|
||||||
|
|
||||||
// throws Exception when default headers are not in res.headers
|
// throws Exception when default headers are not in res.headers
|
||||||
function assert_headers(res) {
|
function assert_headers(res) {
|
||||||
assert(res.headers["content-type"]);
|
assert(res.headers["content-type"]);
|
||||||
@ -237,7 +241,7 @@ describe("Crafatar", function() {
|
|||||||
assert.ifError(error);
|
assert.ifError(error);
|
||||||
assert.ifError(body);
|
assert.ifError(body);
|
||||||
assert.equal(res.statusCode, 304);
|
assert.equal(res.statusCode, 304);
|
||||||
assert(res.headers["etag"]);
|
assert(res.headers.etag);
|
||||||
assert_headers(res);
|
assert_headers(res);
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
@ -263,12 +267,12 @@ describe("Crafatar", function() {
|
|||||||
assert.ifError(error);
|
assert.ifError(error);
|
||||||
assert.strictEqual(res.statusCode, 200);
|
assert.strictEqual(res.statusCode, 200);
|
||||||
assert_headers(res);
|
assert_headers(res);
|
||||||
assert(res.headers["etag"]);
|
assert(res.headers.etag);
|
||||||
assert.strictEqual(res.headers["content-type"], "text/html; charset=utf-8");
|
assert.strictEqual(res.headers["content-type"], "text/html; charset=utf-8");
|
||||||
assert.strictEqual(res.headers["etag"], "\"" + crc(body) + "\"");
|
assert.strictEqual(res.headers.etag, '"' + crc(body) + '"');
|
||||||
assert(body);
|
assert(body);
|
||||||
|
|
||||||
assert_cache(url, res.headers["etag"], function() {
|
assert_cache(url, res.headers.etag, function() {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -280,12 +284,12 @@ describe("Crafatar", function() {
|
|||||||
assert.ifError(error);
|
assert.ifError(error);
|
||||||
assert.strictEqual(res.statusCode, 200);
|
assert.strictEqual(res.statusCode, 200);
|
||||||
assert_headers(res);
|
assert_headers(res);
|
||||||
assert(res.headers["etag"]);
|
assert(res.headers.etag);
|
||||||
assert.strictEqual(res.headers["content-type"], "text/css");
|
assert.strictEqual(res.headers["content-type"], "text/css");
|
||||||
assert.strictEqual(res.headers["etag"], "\"" + crc(body) + "\"");
|
assert.strictEqual(res.headers.etag, '"' + crc(body) + '"');
|
||||||
assert(body);
|
assert(body);
|
||||||
|
|
||||||
assert_cache(url, res.headers["etag"], function() {
|
assert_cache(url, res.headers.etag, function() {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -297,7 +301,7 @@ describe("Crafatar", function() {
|
|||||||
assert.ifError(error);
|
assert.ifError(error);
|
||||||
assert.strictEqual(res.statusCode, 200);
|
assert.strictEqual(res.statusCode, 200);
|
||||||
assert_headers(res);
|
assert_headers(res);
|
||||||
assert(res.headers["etag"]);
|
assert(res.headers.etag);
|
||||||
assert.strictEqual(res.headers["content-type"], "image/png");
|
assert.strictEqual(res.headers["content-type"], "image/png");
|
||||||
assert(body);
|
assert(body);
|
||||||
done();
|
done();
|
||||||
@ -320,7 +324,7 @@ describe("Crafatar", function() {
|
|||||||
assert.ifError(error);
|
assert.ifError(error);
|
||||||
assert.strictEqual(res.statusCode, 200);
|
assert.strictEqual(res.statusCode, 200);
|
||||||
assert_headers(res);
|
assert_headers(res);
|
||||||
assert(res.headers["etag"]);
|
assert(res.headers.etag);
|
||||||
assert.strictEqual(res.headers["content-type"], "image/png");
|
assert.strictEqual(res.headers["content-type"], "image/png");
|
||||||
assert(body);
|
assert(body);
|
||||||
partDone();
|
partDone();
|
||||||
@ -644,14 +648,14 @@ describe("Crafatar", function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (var description in server_tests) {
|
for (var description in server_tests) {
|
||||||
var location = server_tests[description];
|
var loc = 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) {
|
||||||
assert.ifError(error);
|
assert.ifError(error);
|
||||||
assert_headers(res);
|
assert_headers(res);
|
||||||
assert(res.headers["x-storage-type"]);
|
assert(res.headers["x-storage-type"]);
|
||||||
assert.strictEqual(res.headers["etag"], location.etag);
|
assert.strictEqual(res.headers.etag, location.etag);
|
||||||
var matches = false;
|
var matches = false;
|
||||||
if (location.crc32 instanceof Array) {
|
if (location.crc32 instanceof Array) {
|
||||||
for (var i = 0; i < location.crc32.length; i++) {
|
for (var i = 0; i < location.crc32.length; i++) {
|
||||||
@ -663,28 +667,33 @@ describe("Crafatar", function() {
|
|||||||
} else {
|
} else {
|
||||||
matches = (location.crc32 === crc(body));
|
matches = (location.crc32 === crc(body));
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
assert.ok(matches);
|
assert.ok(matches);
|
||||||
assert.strictEqual(res.headers["location"], location.redirect);
|
} catch(e) {
|
||||||
|
throw new Error(crc(body) + " != " + location.crc32);
|
||||||
|
}
|
||||||
|
assert.strictEqual(res.headers.location, location.redirect);
|
||||||
if (location.etag === undefined) {
|
if (location.etag === undefined) {
|
||||||
assert.strictEqual(res.statusCode, location.redirect ? 307 : 404);
|
assert.strictEqual(res.statusCode, location.redirect ? 307 : 404);
|
||||||
assert.strictEqual(res.headers["content-type"], "text/plain");
|
assert.strictEqual(res.headers["content-type"], "text/plain");
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
assert(res.headers["etag"]);
|
assert(res.headers.etag);
|
||||||
assert.strictEqual(res.headers["content-type"], "image/png");
|
assert.strictEqual(res.headers["content-type"], "image/png");
|
||||||
assert.strictEqual(res.statusCode, 200);
|
assert.strictEqual(res.statusCode, 200);
|
||||||
assert_cache(location.url, res.headers["etag"], function() {
|
assert_cache(location.url, res.headers.etag, function() {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}(location));
|
}(loc));
|
||||||
}
|
}
|
||||||
|
|
||||||
it("should return a 422 (invalid size)", function(done) {
|
it("should return a 422 (invalid size)", function(done) {
|
||||||
var size = config.max_size + 1;
|
var size = config.max_size + 1;
|
||||||
request.get("http://localhost:3000/avatars/Jake_0?size=" + size, function(error, res, body) {
|
request.get("http://localhost:3000/avatars/Jake_0?size=" + size, function(error, res, body) {
|
||||||
|
assert.ifError(error);
|
||||||
assert.strictEqual(res.statusCode, 422);
|
assert.strictEqual(res.statusCode, 422);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -693,6 +702,7 @@ describe("Crafatar", function() {
|
|||||||
it("should return a 422 (invalid scale)", function(done) {
|
it("should return a 422 (invalid scale)", function(done) {
|
||||||
var scale = config.max_scale + 1;
|
var scale = config.max_scale + 1;
|
||||||
request.get("http://localhost:3000/renders/head/Jake_0?scale=" + scale, function(error, res, body) {
|
request.get("http://localhost:3000/renders/head/Jake_0?scale=" + scale, function(error, res, body) {
|
||||||
|
assert.ifError(error);
|
||||||
assert.strictEqual(res.statusCode, 422);
|
assert.strictEqual(res.statusCode, 422);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -700,6 +710,7 @@ describe("Crafatar", function() {
|
|||||||
|
|
||||||
it("should return a 422 (invalid render type)", function(done) {
|
it("should return a 422 (invalid render type)", function(done) {
|
||||||
request.get("http://localhost:3000/renders/invalid/Jake_0", function(error, res, body) {
|
request.get("http://localhost:3000/renders/invalid/Jake_0", function(error, res, body) {
|
||||||
|
assert.ifError(error);
|
||||||
assert.strictEqual(res.statusCode, 422);
|
assert.strictEqual(res.statusCode, 422);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -708,15 +719,16 @@ describe("Crafatar", function() {
|
|||||||
// testing all paths for Invalid UserID
|
// testing all paths for Invalid UserID
|
||||||
var locations = ["avatars", "skins", "capes", "renders/body", "renders/head"];
|
var locations = ["avatars", "skins", "capes", "renders/body", "renders/head"];
|
||||||
for (var l in locations) {
|
for (var l in locations) {
|
||||||
var location = locations[l];
|
loc = locations[l];
|
||||||
(function(location) {
|
(function(location) {
|
||||||
it("should return a 422 (invalid id " + location + ")", function(done) {
|
it("should return a 422 (invalid id " + location + ")", function(done) {
|
||||||
request.get("http://localhost:3000/" + location + "/thisisaninvaliduuid", function(error, res, body) {
|
request.get("http://localhost:3000/" + location + "/thisisaninvaliduuid", function(error, res, body) {
|
||||||
|
assert.ifError(error);
|
||||||
assert.strictEqual(res.statusCode, 422);
|
assert.strictEqual(res.statusCode, 422);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})(location);
|
}(loc));
|
||||||
}
|
}
|
||||||
|
|
||||||
after(function(done) {
|
after(function(done) {
|
||||||
@ -760,6 +772,7 @@ describe("Crafatar", function() {
|
|||||||
});
|
});
|
||||||
it("should not be found", function(done) {
|
it("should not be found", function(done) {
|
||||||
helpers.get_cape(rid, "Jake_0", function(err, hash, status, img) {
|
helpers.get_cape(rid, "Jake_0", function(err, hash, status, img) {
|
||||||
|
assert.ifError(err);
|
||||||
assert.strictEqual(img, null);
|
assert.strictEqual(img, null);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -787,8 +800,8 @@ describe("Crafatar", function() {
|
|||||||
|
|
||||||
// DRY with uuid and username tests
|
// DRY with uuid and username tests
|
||||||
for (var i in ids) {
|
for (var i in ids) {
|
||||||
var id = ids[i];
|
var iid = ids[i];
|
||||||
var id_type = id.length > 16 ? "uuid" : "name";
|
var iid_type = iid.length > 16 ? "uuid" : "name";
|
||||||
// needs an anonymous function because id and id_type aren't constant
|
// needs an anonymous function because id and id_type aren't constant
|
||||||
(function(id, id_type) {
|
(function(id, id_type) {
|
||||||
describe("Networking: Avatar", function() {
|
describe("Networking: Avatar", function() {
|
||||||
@ -799,12 +812,14 @@ describe("Crafatar", function() {
|
|||||||
|
|
||||||
it("should be downloaded", function(done) {
|
it("should be downloaded", function(done) {
|
||||||
helpers.get_avatar(rid, id, false, 160, function(err, status, image) {
|
helpers.get_avatar(rid, id, false, 160, function(err, status, image) {
|
||||||
|
assert.ifError(err);
|
||||||
assert.strictEqual(status, 2);
|
assert.strictEqual(status, 2);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("should be cached", function(done) {
|
it("should be cached", function(done) {
|
||||||
helpers.get_avatar(rid, id, false, 160, function(err, status, image) {
|
helpers.get_avatar(rid, id, false, 160, function(err, status, image) {
|
||||||
|
assert.ifError(err);
|
||||||
assert.strictEqual(status === 0 || status === 1, true);
|
assert.strictEqual(status === 0 || status === 1, true);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -816,6 +831,7 @@ describe("Crafatar", function() {
|
|||||||
var original_cache_time = config.local_cache_time;
|
var original_cache_time = config.local_cache_time;
|
||||||
config.local_cache_time = 0;
|
config.local_cache_time = 0;
|
||||||
helpers.get_avatar(rid, id, false, 160, function(err, status, image) {
|
helpers.get_avatar(rid, id, false, 160, function(err, status, image) {
|
||||||
|
assert.ifError(err);
|
||||||
assert.strictEqual(status, 3);
|
assert.strictEqual(status, 3);
|
||||||
config.local_cache_time = original_cache_time;
|
config.local_cache_time = original_cache_time;
|
||||||
done();
|
done();
|
||||||
@ -836,13 +852,13 @@ describe("Crafatar", function() {
|
|||||||
describe("Networking: Render", function() {
|
describe("Networking: Render", function() {
|
||||||
it("should not fail (full body)", function(done) {
|
it("should not fail (full body)", function(done) {
|
||||||
helpers.get_render(rid, id, 6, true, true, function(err, hash, img) {
|
helpers.get_render(rid, id, 6, true, true, function(err, hash, img) {
|
||||||
assert.strictEqual(err, null);
|
assert.ifError(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("should not fail (only head)", function(done) {
|
it("should not fail (only head)", function(done) {
|
||||||
helpers.get_render(rid, id, 6, true, false, function(err, hash, img) {
|
helpers.get_render(rid, id, 6, true, false, function(err, hash, img) {
|
||||||
assert.strictEqual(err, null);
|
assert.ifError(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -851,7 +867,7 @@ describe("Crafatar", function() {
|
|||||||
describe("Networking: Cape", function() {
|
describe("Networking: Cape", function() {
|
||||||
it("should not fail (possible cape)", function(done) {
|
it("should not fail (possible cape)", function(done) {
|
||||||
helpers.get_cape(rid, id, function(err, hash, status, img) {
|
helpers.get_cape(rid, id, function(err, hash, status, img) {
|
||||||
assert.strictEqual(err, null);
|
assert.ifError(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -863,9 +879,10 @@ describe("Crafatar", function() {
|
|||||||
cache.get_redis().flushall();
|
cache.get_redis().flushall();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (id_type == "uuid") {
|
if (id_type === "uuid") {
|
||||||
it("uuid should be rate limited", function(done) {
|
it("uuid should be rate limited", function(done) {
|
||||||
networking.get_profile(rid, id, function(err, profile) {
|
networking.get_profile(rid, id, function(err, profile) {
|
||||||
|
assert.ifError(err);
|
||||||
assert.strictEqual(profile.error, "TooManyRequestsException");
|
assert.strictEqual(profile.error, "TooManyRequestsException");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -879,6 +896,6 @@ describe("Crafatar", function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})(id, id_type);
|
}(iid, iid_type));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user