url-helper.test.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import * as urlHelper from '../src/url-helper'
  2. describe('getServerUrl tests', () => {
  3. it('basics', async () => {
  4. // Note that URL::toString will append a trailing / when passed just a domain name ...
  5. expect(urlHelper.getServerUrl().toString()).toBe('https://github.com/')
  6. expect(urlHelper.getServerUrl(' ').toString()).toBe('https://github.com/')
  7. expect(urlHelper.getServerUrl(' ').toString()).toBe('https://github.com/')
  8. expect(urlHelper.getServerUrl('http://contoso.com').toString()).toBe(
  9. 'http://contoso.com/'
  10. )
  11. expect(urlHelper.getServerUrl('https://contoso.com').toString()).toBe(
  12. 'https://contoso.com/'
  13. )
  14. expect(urlHelper.getServerUrl('https://contoso.com/').toString()).toBe(
  15. 'https://contoso.com/'
  16. )
  17. // ... but can't make that same assumption when passed an URL that includes some deeper path.
  18. expect(urlHelper.getServerUrl('https://contoso.com/a/b').toString()).toBe(
  19. 'https://contoso.com/a/b'
  20. )
  21. })
  22. })
  23. describe('isGhes tests', () => {
  24. it('basics', async () => {
  25. expect(urlHelper.isGhes()).toBeFalsy()
  26. expect(urlHelper.isGhes('https://github.com')).toBeFalsy()
  27. expect(urlHelper.isGhes('https://contoso.ghe.com')).toBeFalsy()
  28. expect(urlHelper.isGhes('https://test.github.localhost')).toBeFalsy()
  29. expect(urlHelper.isGhes('https://src.onpremise.fabrikam.com')).toBeTruthy()
  30. })
  31. })
  32. describe('getServerApiUrl tests', () => {
  33. it('basics', async () => {
  34. expect(urlHelper.getServerApiUrl()).toBe('https://api.github.com')
  35. expect(urlHelper.getServerApiUrl('https://github.com')).toBe(
  36. 'https://api.github.com'
  37. )
  38. expect(urlHelper.getServerApiUrl('https://GitHub.com')).toBe(
  39. 'https://api.github.com'
  40. )
  41. expect(urlHelper.getServerApiUrl('https://contoso.ghe.com')).toBe(
  42. 'https://api.contoso.ghe.com'
  43. )
  44. expect(urlHelper.getServerApiUrl('https://fabrikam.GHE.COM')).toBe(
  45. 'https://api.fabrikam.ghe.com'
  46. )
  47. expect(
  48. urlHelper.getServerApiUrl('https://src.onpremise.fabrikam.com')
  49. ).toBe('https://src.onpremise.fabrikam.com/api/v3')
  50. })
  51. })