test.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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("invaliduuid"), 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. helpers.get_avatar("ec561538f3fd461daff5086b22154bce", false, 160, function(err, status, image) {
  32. assert.strictEqual(status, 3);
  33. done();
  34. });
  35. });
  36. });
  37. describe('Avatar', function(){
  38. it("should be downloaded", function(done) {
  39. helpers.get_avatar(uuid, false, 160, function(err, status, image) {
  40. assert.strictEqual(status, 2);
  41. done();
  42. });
  43. });
  44. it("should be local", function(done) {
  45. helpers.get_avatar(uuid, false, 160, function(err, status, image) {
  46. assert.strictEqual(status, 1);
  47. done();
  48. });
  49. });
  50. });
  51. describe('Mojang Errors', function(){
  52. before(function() {
  53. cache.get_redis().flushall();
  54. });
  55. it("should be rate limited", function(done) {
  56. helpers.get_avatar(uuid, false, 160, function(err, status, image) {
  57. assert.strictEqual(err, null);
  58. done();
  59. });
  60. });
  61. });
  62. });