github-url.spec.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { GitHubUrl } from './github-url';
  2. describe('GitHubUrl Constructor throws an error when the url string is', () => {
  3. it.concurrent.each`
  4. url
  5. ${'//example.com/org/repos'}
  6. ${'https://example.com'}
  7. ${'https://github.com/org/repos/foo'}
  8. `("'$url'", ({ url }) => {
  9. // when
  10. const caller = () => new GitHubUrl(url);
  11. // then
  12. expect(caller).toThrowError(`The specified URL is invalid. : url='${url}'`);
  13. });
  14. });
  15. describe('The constructor is successfully processed', () => {
  16. it('with http schemed url', () => {
  17. // when
  18. const githubUrl = new GitHubUrl('http://github.com/org/repos');
  19. // then
  20. expect(githubUrl).not.toBeNull();
  21. expect(githubUrl.organizationName).toEqual('org');
  22. expect(githubUrl.reposName).toEqual('repos');
  23. expect(githubUrl.branchName).toEqual('main');
  24. });
  25. it('with https schemed url', () => {
  26. // when
  27. const githubUrl = new GitHubUrl('https://github.com/org/repos');
  28. // then
  29. expect(githubUrl).not.toBeNull();
  30. expect(githubUrl.organizationName).toEqual('org');
  31. expect(githubUrl.reposName).toEqual('repos');
  32. expect(githubUrl.branchName).toEqual('main');
  33. });
  34. it('with branchName', () => {
  35. // when
  36. const githubUrl = new GitHubUrl('https://github.com/org/repos', 'fix/bug');
  37. // then
  38. expect(githubUrl).not.toBeNull();
  39. expect(githubUrl.organizationName).toEqual('org');
  40. expect(githubUrl.reposName).toEqual('repos');
  41. expect(githubUrl.branchName).toEqual('fix/bug');
  42. });
  43. });
  44. describe('archiveUrl()', () => {
  45. it('returns zip url', () => {
  46. // setup
  47. const githubUrl = new GitHubUrl('https://github.com/org/repos', 'fix/bug');
  48. // when
  49. const { archiveUrl } = githubUrl;
  50. // then
  51. expect(archiveUrl).toEqual('https://github.com/org/repos/archive/refs/heads/fix/bug.zip');
  52. });
  53. });