mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-22 07:51:17 +01:00
Rewrite tests
This commit is contained in:
parent
a1052b7cbe
commit
7e0d0fff68
@ -19,7 +19,8 @@
|
|||||||
"avatar"
|
"avatar"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node server.js"
|
"start": "node server.js",
|
||||||
|
"test": "node_modules/.bin/mocha -w"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "~4.9.0",
|
"express": "~4.9.0",
|
||||||
|
|||||||
86
test/test.js
86
test/test.js
@ -1,10 +1,15 @@
|
|||||||
var request = require('supertest');
|
var assert = require('assert');
|
||||||
var asset = require('assert');
|
|
||||||
var should = require('should');
|
|
||||||
var fs = require('fs')
|
var fs = require('fs')
|
||||||
var uuids = fs.readFileSync('uuids.txt').toString().split("\n");
|
var should = require('should')
|
||||||
|
|
||||||
|
var networking = require('../modules/networking');
|
||||||
|
var helpers = require('../modules/helpers');
|
||||||
|
var config = require('../modules/config');
|
||||||
|
var skins = require('../modules/skins');
|
||||||
|
|
||||||
|
var uuids = fs.readFileSync('test/uuids.txt').toString().split("\r\n");
|
||||||
// Get a random UUID in order to prevent rate limiting
|
// Get a random UUID in order to prevent rate limiting
|
||||||
var uuid = uuids[Math.floor((Math.random() * 200) + 1)];
|
var uuid = uuids[Math.floor((Math.random() * 200) + 1)]
|
||||||
|
|
||||||
// Only deletes files, doesn't delete directory.
|
// Only deletes files, doesn't delete directory.
|
||||||
var deleteFolderRecursive = function(path) {
|
var deleteFolderRecursive = function(path) {
|
||||||
@ -22,70 +27,39 @@ var deleteFolderRecursive = function(path) {
|
|||||||
|
|
||||||
describe('Avatar Serving', function(){
|
describe('Avatar Serving', function(){
|
||||||
before(function() {
|
before(function() {
|
||||||
deleteFolderRecursive('../skins/');
|
deleteFolderRecursive('skins/');
|
||||||
})
|
})
|
||||||
describe('UUID', function(){
|
describe('UUID', function(){
|
||||||
it("should respond with a 422", function(done){
|
it("should be an invalid uuid", function(done){
|
||||||
request('http://localhost:3000')
|
assert.equal(helpers.uuid_valid("invaliduuid"), false);
|
||||||
.get('/avatars/invaliduuid')
|
done();
|
||||||
.expect(422)
|
});
|
||||||
.end(function(err,res) {
|
it("should be a valid uuid", function(done){
|
||||||
if (err) throw err;
|
assert.equal(helpers.uuid_valid("0098cb60fa8e427cb299793cbd302c9a"), true);
|
||||||
res.statusCode.should.eql(422);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it("should respond with a 404", function(done){
|
|
||||||
request('http://localhost:3000')
|
|
||||||
.get('/avatars/2d5aa9cdaeb049189930461fc9b91dd5')
|
|
||||||
.expect(404)
|
|
||||||
.end(function(err,res) {
|
|
||||||
if (err) throw err;
|
|
||||||
res.statusCode.should.eql(404);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('Avatar', function(){
|
||||||
it("should be downloaded", function(done) {
|
it("should be downloaded", function(done) {
|
||||||
request('http://localhost:3000')
|
helpers.get_avatar(uuid, false, 180, function(err, status, image) {
|
||||||
.get('/avatars/' + uuid)
|
assert.equal(status, 2);
|
||||||
.expect(200)
|
|
||||||
.expect('X-Storage-Type', "downloaded")
|
|
||||||
.end(function(err,res) {
|
|
||||||
if (err) throw err;
|
|
||||||
res.statusCode.should.eql(200);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("should respond with a valid avatar", function(done){
|
it("should be local", function(done) {
|
||||||
request('http://localhost:3000')
|
helpers.get_avatar(uuid, false, 180, function(err, status, image) {
|
||||||
.get('/avatars/' + uuid)
|
assert.equal(status, 1);
|
||||||
.expect(200)
|
|
||||||
.expect('Content-Type', "image/png")
|
|
||||||
.end(function(err,res) {
|
|
||||||
if (err) throw err;
|
|
||||||
res.statusCode.should.eql(200);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("should should be locally saved", function(done){
|
|
||||||
request('http://localhost:3000')
|
|
||||||
.get('/avatars/' + uuid)
|
|
||||||
.expect(200)
|
|
||||||
.expect('X-Storage-Type', "local")
|
|
||||||
.end(function(err,res) {
|
|
||||||
if (err) throw err;
|
|
||||||
res.statusCode.should.eql(200);
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
describe('Mojang Errors', function(){
|
||||||
it("should should be rate limited", function(done){
|
before(function() {
|
||||||
deleteFolderRecursive('../skins/');
|
deleteFolderRecursive('skins/');
|
||||||
request('http://localhost:3000')
|
})
|
||||||
.get('/avatars/' + uuid)
|
it("should be rate limited", function(done) {
|
||||||
.expect(404)
|
helpers.get_avatar(uuid, false, 180, function(err, status, image) {
|
||||||
.end(function(err,res) {
|
assert.equal(err, null);
|
||||||
if (err) throw err;
|
|
||||||
res.statusCode.should.eql(404);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user