Utils.spec.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import { assert } from 'chai';
  2. import { Utils } from '../../../src/utils/Utils';
  3. describe('Utils', () => {
  4. describe('extractDomainFrom', () => {
  5. describe('Variant #1: simple url', () => {
  6. const url: string = 'http://google.ru';
  7. const expectedDomain: string = 'google.ru';
  8. let domain: string;
  9. before(() => {
  10. domain = Utils.extractDomainFrom(url);
  11. });
  12. it('should extract domain from the given URL', () => {
  13. assert.equal(domain, expectedDomain);
  14. });
  15. });
  16. describe('Variant #2: url with `www` part', () => {
  17. const url: string = 'http://www.google.ru';
  18. const expectedDomain: string = 'www.google.ru';
  19. let domain: string;
  20. before(() => {
  21. domain = Utils.extractDomainFrom(url);
  22. });
  23. it('should extract domain from the given URL', () => {
  24. assert.equal(domain, expectedDomain);
  25. });
  26. });
  27. describe('Variant #3: url with `https` protocol and port', () => {
  28. const url: string = 'https://www.google.ru:9000';
  29. const expectedDomain: string = 'www.google.ru';
  30. let domain: string;
  31. before(() => {
  32. domain = Utils.extractDomainFrom(url);
  33. });
  34. it('should extract domain from the given URL', () => {
  35. assert.equal(domain, expectedDomain);
  36. });
  37. });
  38. describe('Variant #4: protocol-wide url and route', () => {
  39. const url: string = '//google.ru/abc';
  40. const expectedDomain: string = 'google.ru';
  41. let domain: string;
  42. before(() => {
  43. domain = Utils.extractDomainFrom(url);
  44. });
  45. it('should extract domain from the given URL', () => {
  46. assert.equal(domain, expectedDomain);
  47. });
  48. });
  49. describe('Variant #5: protocol-wide url, `localhost` and port', () => {
  50. const url: string = '//localhost:9000';
  51. const expectedDomain: string = 'localhost';
  52. let domain: string;
  53. before(() => {
  54. domain = Utils.extractDomainFrom(url);
  55. });
  56. it('should extract domain from the given URL', () => {
  57. assert.equal(domain, expectedDomain);
  58. });
  59. });
  60. });
  61. describe('buildVersionMessage', () => {
  62. describe('Variant #1: version and build timestamp are set', () => {
  63. const expectedVersionMessage: string = '0.1.0_2020-01-01T00:00:00.000Z';
  64. let versionMessage: string;
  65. before(() => {
  66. versionMessage = Utils.buildVersionMessage('0.1.0', '1577836800000');
  67. });
  68. it('should build version message', () => {
  69. assert.equal(versionMessage, expectedVersionMessage);
  70. });
  71. });
  72. describe('Variant #2: version is not set set', () => {
  73. const expectedVersionMessage: string = 'unknown';
  74. let versionMessage: string;
  75. before(() => {
  76. versionMessage = Utils.buildVersionMessage(undefined, '1577836800000');
  77. });
  78. it('should build version message', () => {
  79. assert.equal(versionMessage, expectedVersionMessage);
  80. });
  81. });
  82. describe('Variant #3: build timestamp is not set set', () => {
  83. const expectedVersionMessage: string = 'unknown';
  84. let versionMessage: string;
  85. before(() => {
  86. versionMessage = Utils.buildVersionMessage('0.1.0', undefined);
  87. });
  88. it('should build version message', () => {
  89. assert.equal(versionMessage, expectedVersionMessage);
  90. });
  91. });
  92. });
  93. });