github-url.spec.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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(
  52. 'https://github.com/org/repos/archive/refs/heads/fix%2Fbug.zip',
  53. );
  54. });
  55. });
  56. describe('extractedArchiveDirName()', () => {
  57. describe('certain characters in the branch name are converted to slashes, and if they are consecutive, they become a single hyphen', () => {
  58. it.concurrent.each`
  59. branchName
  60. ${'a"\'!,;-=@`]<>|&{}()$%+#/b'}
  61. ${'a---b'}
  62. `("'$branchName'", ({ branchName }) => {
  63. // setup
  64. const githubUrl = new GitHubUrl(
  65. 'https://github.com/org/repos',
  66. branchName,
  67. );
  68. // when
  69. const { extractedArchiveDirName } = githubUrl;
  70. // then
  71. expect(extractedArchiveDirName).toEqual('a-b');
  72. });
  73. });
  74. describe('when no certain characters in the branch name', () => {
  75. it.concurrent.each`
  76. branchName
  77. ${'a.b'}
  78. ${'a_b'}
  79. `("'$branchName'", ({ branchName }) => {
  80. // setup
  81. const githubUrl = new GitHubUrl(
  82. 'https://github.com/org/repos',
  83. branchName,
  84. );
  85. // when
  86. const { extractedArchiveDirName } = githubUrl;
  87. // then
  88. expect(extractedArchiveDirName).toEqual(branchName);
  89. });
  90. });
  91. });