test.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. var assert = require('assert');
  2. var fs = require('fs')
  3. var networking = require('../modules/networking');
  4. var helpers = require('../modules/helpers');
  5. var config = require('../modules/config');
  6. var skins = require('../modules/skins');
  7. var uuids = fs.readFileSync('test/uuids.txt').toString().split("\r\n");
  8. // Get a random UUID in order to prevent rate limiting
  9. var uuid = uuids[Math.floor((Math.random() * 200) + 1)]
  10. // Only deletes files, doesn't delete directory.
  11. var deleteFolderRecursive = function(path) {
  12. if( fs.existsSync(path) ) {
  13. fs.readdirSync(path).forEach(function(file,index){
  14. var curPath = path + "/" + file;
  15. if(fs.lstatSync(curPath).isDirectory()) {
  16. deleteFolderRecursive(curPath);
  17. } else {
  18. fs.unlinkSync(curPath);
  19. }
  20. });
  21. }
  22. };
  23. describe('Avatar Serving', function(){
  24. before(function() {
  25. deleteFolderRecursive('skins/');
  26. })
  27. describe('UUID', function(){
  28. it("should be an invalid uuid", function(done){
  29. assert.equal(helpers.uuid_valid("invaliduuid"), false);
  30. done();
  31. });
  32. it("should be a valid uuid", function(done){
  33. assert.equal(helpers.uuid_valid("0098cb60fa8e427cb299793cbd302c9a"), true);
  34. done();
  35. });
  36. });
  37. describe('Avatar', function(){
  38. it("should be downloaded", function(done) {
  39. helpers.get_avatar(uuid, false, 180, function(err, status, image) {
  40. assert.equal(status, 2);
  41. done();
  42. });
  43. });
  44. it("should be local", function(done) {
  45. helpers.get_avatar(uuid, false, 180, function(err, status, image) {
  46. assert.equal(status, 1);
  47. done();
  48. });
  49. });
  50. });
  51. describe('Mojang Errors', function(){
  52. before(function() {
  53. deleteFolderRecursive('skins/');
  54. })
  55. it("should be rate limited", function(done) {
  56. helpers.get_avatar(uuid, false, 180, function(err, status, image) {
  57. assert.equal(err, null);
  58. done();
  59. });
  60. });
  61. });
  62. });