|
| 1 | +const { expect } = require('chai'); |
| 2 | +const { trimPrefixRefsHeads, trimTrailingDotGit } = require('../src/db/helper'); |
| 3 | + |
| 4 | +describe('db helpers', () => { |
| 5 | + describe('trimPrefixRefsHeads', () => { |
| 6 | + it('removes `refs/heads/`', () => { |
| 7 | + const res = trimPrefixRefsHeads('refs/heads/test'); |
| 8 | + expect(res).to.equal('test'); |
| 9 | + }); |
| 10 | + |
| 11 | + it('removes only one `refs/heads/`', () => { |
| 12 | + const res = trimPrefixRefsHeads('refs/heads/refs/heads/'); |
| 13 | + expect(res).to.equal('refs/heads/'); |
| 14 | + }); |
| 15 | + |
| 16 | + it('removes only the first `refs/heads/`', () => { |
| 17 | + const res = trimPrefixRefsHeads('refs/heads/middle/refs/heads/end/refs/heads/'); |
| 18 | + expect(res).to.equal('middle/refs/heads/end/refs/heads/'); |
| 19 | + }); |
| 20 | + |
| 21 | + it('handles empty string', () => { |
| 22 | + const res = trimPrefixRefsHeads(''); |
| 23 | + expect(res).to.equal(''); |
| 24 | + }); |
| 25 | + |
| 26 | + it("doesn't remove `refs/heads`", () => { |
| 27 | + const res = trimPrefixRefsHeads('refs/headstest'); |
| 28 | + expect(res).to.equal('refs/headstest'); |
| 29 | + }); |
| 30 | + |
| 31 | + it("doesn't remove `/refs/heads/`", () => { |
| 32 | + const res = trimPrefixRefsHeads('/refs/heads/test'); |
| 33 | + expect(res).to.equal('/refs/heads/test'); |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + describe('trimTrailingDotGit', () => { |
| 38 | + it('removes `.git`', () => { |
| 39 | + const res = trimTrailingDotGit('test.git'); |
| 40 | + expect(res).to.equal('test'); |
| 41 | + }); |
| 42 | + |
| 43 | + it('removes only one `.git`', () => { |
| 44 | + const res = trimTrailingDotGit('.git.git'); |
| 45 | + expect(res).to.equal('.git'); |
| 46 | + }); |
| 47 | + |
| 48 | + it('removes only the last `.git`', () => { |
| 49 | + const res = trimTrailingDotGit('.git-middle.git-end.git'); |
| 50 | + expect(res).to.equal('.git-middle.git-end'); |
| 51 | + }); |
| 52 | + |
| 53 | + it('handles empty string', () => { |
| 54 | + const res = trimTrailingDotGit(''); |
| 55 | + expect(res).to.equal(''); |
| 56 | + }); |
| 57 | + |
| 58 | + it("doesn't remove just `git`", () => { |
| 59 | + const res = trimTrailingDotGit('testgit'); |
| 60 | + expect(res).to.equal('testgit'); |
| 61 | + }); |
| 62 | + }); |
| 63 | +}); |
0 commit comments