test.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 url = require('url');
  8. var redisURL = url.parse(process.env.REDISCLOUD_URL);
  9. var redis = require("redis").createClient(redisURL.port, redisURL.hostname, {no_ready_check: true});
  10. redis.auth(redisURL.auth.split(":")[1]);
  11. var uuids = fs.readFileSync('test/uuids.txt').toString().split("\r\n");
  12. // Get a random UUID in order to prevent rate limiting
  13. var uuid = uuids[Math.floor(Math.random() * uuids.length)];
  14. describe('Avatar Serving', function(){
  15. before(function() {
  16. redis.flushall();
  17. });
  18. describe('UUID', function(){
  19. it("should be an invalid uuid", function(done){
  20. assert.equal(helpers.uuid_valid("invaliduuid"), false);
  21. done();
  22. });
  23. it("should be a valid uuid", function(done){
  24. assert.equal(helpers.uuid_valid("0098cb60fa8e427cb299793cbd302c9a"), true);
  25. done();
  26. });
  27. });
  28. describe('Avatar', function(){
  29. it("should be downloaded", function(done) {
  30. helpers.get_avatar(uuid, false, 180, function(err, status, image) {
  31. assert.equal(status, 2);
  32. done();
  33. });
  34. });
  35. it("should be local", function(done) {
  36. helpers.get_avatar(uuid, false, 180, function(err, status, image) {
  37. assert.equal(status, 1);
  38. done();
  39. });
  40. });
  41. });
  42. describe('Mojang Errors', function(){
  43. before(function() {
  44. redis.flushall();
  45. });
  46. it("should be rate limited", function(done) {
  47. helpers.get_avatar(uuid, false, 180, function(err, status, image) {
  48. assert.equal(err, null);
  49. done();
  50. });
  51. });
  52. });
  53. });