Utils.spec.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. describe('getIdentifiersPrefixForMultipleSources', () => {
  94. describe('Variant #1: should get identifiers prefix for identifiers prefix from options', () => {
  95. const expectedIdentifiersPrefix: string = 'foo1';
  96. let identifiersPrefix: string;
  97. before(() => {
  98. identifiersPrefix = Utils.getIdentifiersPrefixForMultipleSources(
  99. 'foo',
  100. 1
  101. );
  102. });
  103. it('should return correct identifiers prefix', () => {
  104. assert.equal(identifiersPrefix, expectedIdentifiersPrefix);
  105. });
  106. });
  107. describe('Variant #2: should get identifiers prefix for base identifiers prefix for multiple sources', () => {
  108. const expectedIdentifiersPrefix: string = 'a1';
  109. let identifiersPrefix: string;
  110. before(() => {
  111. identifiersPrefix = Utils.getIdentifiersPrefixForMultipleSources(
  112. undefined,
  113. 1
  114. );
  115. });
  116. it('should return correct identifiers prefix', () => {
  117. assert.equal(identifiersPrefix, expectedIdentifiersPrefix);
  118. });
  119. });
  120. });
  121. });