test.js 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. 'use strict';
  2. var jsc = require('jsverify'),
  3. jsdom = require('jsdom-global'),
  4. cleanup = jsdom();
  5. global.$ = global.jQuery = require('./jquery-3.1.1');
  6. global.sjcl = require('./sjcl-1.0.6');
  7. global.Base64 = require('./base64-2.1.9');
  8. global.RawDeflate = require('./rawdeflate-0.5');
  9. require('./rawinflate-0.3');
  10. require('./privatebin');
  11. describe('helper', function () {
  12. describe('secondsToHuman', function () {
  13. after(function () {
  14. cleanup();
  15. });
  16. jsc.property('returns an array with a number and a word', 'integer', function (number) {
  17. var result = $.PrivateBin.helper.secondsToHuman(number);
  18. return Array.isArray(result) &&
  19. result.length === 2 &&
  20. result[0] === parseInt(result[0], 10) &&
  21. typeof result[1] === 'string';
  22. });
  23. jsc.property('returns seconds on the first array position', 'integer 59', function (number) {
  24. return $.PrivateBin.helper.secondsToHuman(number)[0] === number;
  25. });
  26. jsc.property('returns seconds on the second array position', 'integer 59', function (number) {
  27. return $.PrivateBin.helper.secondsToHuman(number)[1] === 'second';
  28. });
  29. jsc.property('returns minutes on the first array position', 'integer 60 3599', function (number) {
  30. return $.PrivateBin.helper.secondsToHuman(number)[0] === Math.floor(number / 60);
  31. });
  32. jsc.property('returns minutes on the second array position', 'integer 60 3599', function (number) {
  33. return $.PrivateBin.helper.secondsToHuman(number)[1] === 'minute';
  34. });
  35. jsc.property('returns hours on the first array position', 'integer 3600 86399', function (number) {
  36. return $.PrivateBin.helper.secondsToHuman(number)[0] === Math.floor(number / (60 * 60));
  37. });
  38. jsc.property('returns hours on the second array position', 'integer 3600 86399', function (number) {
  39. return $.PrivateBin.helper.secondsToHuman(number)[1] === 'hour';
  40. });
  41. jsc.property('returns days on the first array position', 'integer 86400 5184000', function (number) {
  42. return $.PrivateBin.helper.secondsToHuman(number)[0] === Math.floor(number / (60 * 60 * 24));
  43. });
  44. jsc.property('returns days on the second array position', 'integer 86400 5184000', function (number) {
  45. return $.PrivateBin.helper.secondsToHuman(number)[1] === 'day';
  46. });
  47. // max safe integer as per http://ecma262-5.com/ELS5_HTML.htm#Section_8.5
  48. jsc.property('returns months on the first array position', 'integer 5184000 9007199254740991', function (number) {
  49. return $.PrivateBin.helper.secondsToHuman(number)[0] === Math.floor(number / (60 * 60 * 24 * 30));
  50. });
  51. jsc.property('returns months on the second array position', 'integer 5184000 9007199254740991', function (number) {
  52. return $.PrivateBin.helper.secondsToHuman(number)[1] === 'month';
  53. });
  54. });
  55. describe('scriptLocation', function () {
  56. after(function () {
  57. cleanup();
  58. });
  59. var a2zString = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'],
  60. alnumString = a2zString.concat(['0','1','2','3','4','5','6','7','8','9']),
  61. queryString = alnumString.concat(['+','%','&','.','*','-','_']);
  62. jsc.property(
  63. 'returns the URL without query & fragment',
  64. jsc.nearray(jsc.elements(a2zString)),
  65. jsc.nearray(jsc.elements(a2zString)),
  66. jsc.array(jsc.elements(queryString)),
  67. 'string',
  68. function (schema, address, query, fragment) {
  69. var expected = schema.join('') + '://' + address.join('') + '/',
  70. clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment}),
  71. result = $.PrivateBin.helper.scriptLocation();
  72. clean();
  73. return expected === result;
  74. }
  75. );
  76. });
  77. });