mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-22 07:51:17 +01:00
Add testing support
This commit is contained in:
parent
054d77c7fa
commit
7bfb0a7095
@ -30,6 +30,9 @@
|
|||||||
"debug": "~2.0.0",
|
"debug": "~2.0.0",
|
||||||
"jade": "~1.6.0",
|
"jade": "~1.6.0",
|
||||||
"lwip": "0.0.5",
|
"lwip": "0.0.5",
|
||||||
"request": "2.45.0"
|
"request": "2.45.0",
|
||||||
|
"mocha": "2.0.1",
|
||||||
|
"supertest": "0.14.0",
|
||||||
|
"should": "4.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
93
test/test.js
Normal file
93
test/test.js
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
var request = require('supertest');
|
||||||
|
var asset = require('assert');
|
||||||
|
var should = require('should');
|
||||||
|
var fs = require('fs')
|
||||||
|
var uuids = fs.readFileSync('uuids.txt').toString().split("\n");
|
||||||
|
// Get a random UUID in order to prevent rate limiting
|
||||||
|
var uuid = uuids[Math.floor((Math.random() * 200) + 1)];
|
||||||
|
|
||||||
|
// Only deletes files, doesn't delete directory.
|
||||||
|
var deleteFolderRecursive = function(path) {
|
||||||
|
if( fs.existsSync(path) ) {
|
||||||
|
fs.readdirSync(path).forEach(function(file,index){
|
||||||
|
var curPath = path + "/" + file;
|
||||||
|
if(fs.lstatSync(curPath).isDirectory()) {
|
||||||
|
deleteFolderRecursive(curPath);
|
||||||
|
} else {
|
||||||
|
fs.unlinkSync(curPath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('Avatar Serving', function(){
|
||||||
|
before(function() {
|
||||||
|
deleteFolderRecursive('../skins/');
|
||||||
|
})
|
||||||
|
describe('UUID', function(){
|
||||||
|
it("should respond with a 422", function(done){
|
||||||
|
request('http://localhost:3000')
|
||||||
|
.get('/avatars/invaliduuid')
|
||||||
|
.expect(422)
|
||||||
|
.end(function(err,res) {
|
||||||
|
if (err) throw err;
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("should be downloaded", function(done){
|
||||||
|
request('http://localhost:3000')
|
||||||
|
.get('/avatars/' + uuid)
|
||||||
|
.expect(200)
|
||||||
|
.expect('X-Storage-Type', "downloaded")
|
||||||
|
.end(function(err,res) {
|
||||||
|
if (err) throw err;
|
||||||
|
res.statusCode.should.eql(200);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("should respond with a valid avatar", function(done){
|
||||||
|
request('http://localhost:3000')
|
||||||
|
.get('/avatars/' + uuid)
|
||||||
|
.expect(200)
|
||||||
|
.expect('Content-Type', "image/png")
|
||||||
|
.end(function(err,res) {
|
||||||
|
if (err) throw err;
|
||||||
|
res.statusCode.should.eql(200);
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("should should be rate limited", function(done){
|
||||||
|
deleteFolderRecursive('../skins/');
|
||||||
|
request('http://localhost:3000')
|
||||||
|
.get('/avatars/' + uuid)
|
||||||
|
.expect(404)
|
||||||
|
.end(function(err,res) {
|
||||||
|
if (err) throw err;
|
||||||
|
res.statusCode.should.eql(404);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user