test.js 2.1 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 cache = require("../modules/cache");
  8. var uuids = fs.readFileSync('test/uuids.txt').toString().split("\n");
  9. // Get a random UUID in order to prevent rate limiting
  10. var uuid = uuids[Math.floor((Math.random() * 200) + 1)];
  11. describe('Avatar Serving', function(){
  12. before(function() {
  13. cache.get_redis().flushall();
  14. });
  15. describe('UUID', function(){
  16. it("should be an invalid uuid", function(done){
  17. assert.strictEqual(helpers.uuid_valid("invaliduuidexample"), false);
  18. done();
  19. });
  20. it("should be a valid uuid", function(done){
  21. assert.strictEqual(helpers.uuid_valid("0098cb60fa8e427cb299793cbd302c9a"), true);
  22. done();
  23. });
  24. it("should not exist", function(done){
  25. networking.get_profile("00000000000000000000000000000000", function(err, profile) {
  26. assert.strictEqual(err, 0);
  27. done();
  28. });
  29. });
  30. it("should exist without skin", function(done) {
  31. // profile 'Alex'
  32. helpers.get_avatar("ec561538f3fd461daff5086b22154bce", false, 160, function(err, status, image) {
  33. assert.strictEqual(status, 3);
  34. done();
  35. });
  36. });
  37. });
  38. describe('Avatar', function(){
  39. it("should be downloaded", function(done) {
  40. helpers.get_avatar(uuid, false, 160, function(err, status, image) {
  41. assert.strictEqual(status, 2);
  42. done();
  43. });
  44. });
  45. it("should be local", function(done) {
  46. helpers.get_avatar(uuid, false, 160, function(err, status, image) {
  47. assert.strictEqual(status, 1);
  48. done();
  49. });
  50. });
  51. });
  52. describe('Mojang Errors', function(){
  53. before(function() {
  54. cache.get_redis().flushall();
  55. });
  56. it("should be rate limited", function(done) {
  57. helpers.get_avatar(uuid, false, 160, function(err, status, image) {
  58. assert.strictEqual(err, null);
  59. done();
  60. });
  61. });
  62. });
  63. });