Browse Source

Add testing support

Jake 10 years ago
parent
commit
7bfb0a7095
4 changed files with 97 additions and 1 deletions
  1. 4 1
      package.json
  2. 0 0
      skins/faces/.gitkeep
  3. 0 0
      skins/helms/.gitkeep
  4. 93 0
      test/test.js

+ 4 - 1
package.json

@@ -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"
   }
   }
 }
 }

+ 0 - 0
skins/faces/.gitkeep


+ 0 - 0
skins/helms/.gitkeep


+ 93 - 0
test/test.js

@@ -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();
+			});
+		});
+	});
+});