a zip code crypto-currency system good for red ONLY

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. 'use strict';
  2. var _supertest = require('supertest');
  3. var _supertest2 = _interopRequireDefault(_supertest);
  4. var _assert = require('assert');
  5. var _assert2 = _interopRequireDefault(_assert);
  6. var _listen = require('./helpers/listen');
  7. var _listen2 = _interopRequireDefault(_listen);
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. function testRoutes() {
  10. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  11. var _ref$prefix = _ref.prefix;
  12. var prefix = _ref$prefix === undefined ? '' : _ref$prefix;
  13. var buildUrl = function buildUrl(url) {
  14. return prefix ? '/' + prefix + url : url;
  15. };
  16. describe('GET /', function () {
  17. it('respond with nothing, but respond', function (done) {
  18. (0, _supertest2.default)(this.server).get(buildUrl('/')).expect('Content-Type', /json/).expect(/\{"tinylr":"Welcome","version":"[\d].[\d].[\d]+"\}/).expect(200, done);
  19. });
  20. it('unknown route respond with proper 404 and error message', function (done) {
  21. (0, _supertest2.default)(this.server).get(buildUrl('/whatev')).expect('Content-Type', /json/).expect('{"error":"not_found","reason":"no such route"}').expect(404, done);
  22. });
  23. });
  24. describe('GET /changed', function () {
  25. it('with no clients, no files', function (done) {
  26. (0, _supertest2.default)(this.server).get(buildUrl('/changed')).expect('Content-Type', /json/).expect(/"clients":\[\]/).expect(/"files":\[\]/).expect(200, done);
  27. });
  28. it('with no clients, some files', function (done) {
  29. (0, _supertest2.default)(this.server).get(buildUrl('/changed?files=gonna.css,test.css,it.css')).expect('Content-Type', /json/).expect('{"clients":[],"files":["gonna.css","test.css","it.css"]}').expect(200, done);
  30. });
  31. });
  32. describe('POST /changed', function () {
  33. it('with no clients, no files', function (done) {
  34. (0, _supertest2.default)(this.server).post(buildUrl('/changed')).expect('Content-Type', /json/).expect(/"clients":\[\]/).expect(/"files":\[\]/).expect(200, done);
  35. });
  36. it('with no clients, some files', function (done) {
  37. var data = { clients: [], files: ['cat.css', 'sed.css', 'ack.js'] };
  38. (0, _supertest2.default)(this.server).post(buildUrl('/changed'))
  39. // .type('json')
  40. .send({ files: data.files }).expect('Content-Type', /json/).expect(JSON.stringify(data)).expect(200, done);
  41. });
  42. });
  43. describe('POST /alert', function () {
  44. it('with no clients, no message', function (done) {
  45. var data = { clients: [] };
  46. (0, _supertest2.default)(this.server).post(buildUrl('/alert')).expect('Content-Type', /json/).expect(JSON.stringify(data)).expect(200, done);
  47. });
  48. it('with no clients, some message', function (done) {
  49. var message = 'Hello Client!';
  50. var data = { clients: [], message: message };
  51. (0, _supertest2.default)(this.server).post(buildUrl('/alert')).send({ message: message }).expect('Content-Type', /json/).expect(JSON.stringify(data)).expect(200, done);
  52. });
  53. });
  54. describe('GET /livereload.js', function () {
  55. it('respond with livereload script', function (done) {
  56. (0, _supertest2.default)(this.server).get(buildUrl('/livereload.js')).expect(/LiveReload/).expect(200, done);
  57. });
  58. });
  59. describe('GET /kill', function () {
  60. it('shutdown the server', function (done) {
  61. var srv = this.server;
  62. (0, _supertest2.default)(srv).get(buildUrl('/kill')).expect(200, function (err) {
  63. if (err) return done(err);
  64. _assert2.default.ok(!srv._handle);
  65. done();
  66. });
  67. });
  68. });
  69. }
  70. describe('Server', function () {
  71. context('with no options', function () {
  72. before((0, _listen2.default)());
  73. testRoutes();
  74. });
  75. context('with prefix option', function () {
  76. var options = {
  77. prefix: 'tiny-lr'
  78. };
  79. before((0, _listen2.default)(options));
  80. testRoutes(options);
  81. });
  82. });