-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: started adding git unit tests
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Git } from '../../../../../src/utils/git/impl/git'; | ||
import { loggerFactory } from '../../../../common/logger'; | ||
import { Checkout, Commit, Repository, Reset } from 'nodegit'; | ||
|
||
describe(`git`, () => { | ||
const openMock = jest.fn(); | ||
const repositorySpy = { | ||
open: openMock, | ||
}; | ||
const resetMock = jest.fn(); | ||
const resetSpy = { | ||
reset: resetMock, | ||
}; | ||
const checkoutSpy = {}; | ||
const commitSpy = ({ | ||
id: () => { | ||
return { | ||
tostrS: () => { | ||
return `test-commit-sha`; | ||
}, | ||
}; | ||
}, | ||
} as any) as Commit; | ||
const nodeGitSpy = { | ||
Repository: repositorySpy, | ||
Reset: resetSpy, | ||
Checkout: checkoutSpy, | ||
} as any; | ||
const git = new Git(nodeGitSpy, loggerFactory); | ||
|
||
beforeEach(() => { | ||
resetMock.mockReset(); | ||
openMock.mockReset(); | ||
}); | ||
|
||
describe(`checkout commit`, () => { | ||
it(`should open checkout commit`, async () => { | ||
const repoPlaceholder = ({} as any) as Repository; | ||
resetMock.mockResolvedValue(undefined); | ||
await git.checkoutCommit({ | ||
repo: repoPlaceholder, | ||
commit: commitSpy, | ||
}); | ||
expect(resetMock).toHaveBeenCalledTimes(1); | ||
expect(resetMock).toHaveBeenCalledWith(repoPlaceholder, commitSpy, Reset.TYPE.HARD, { | ||
checkoutStrategy: Checkout.STRATEGY.SAFE, | ||
}); | ||
}); | ||
}); | ||
|
||
describe(`open repo`, () => { | ||
it(`should open existing repo`, async () => { | ||
const path = `/path/to/repo`; | ||
const repoPlaceholder = {}; | ||
openMock.mockResolvedValue(repoPlaceholder); | ||
const repo = await git.openRepo({ | ||
path, | ||
}); | ||
expect(repo).toBe(repoPlaceholder); | ||
expect(openMock).toHaveBeenCalledTimes(1); | ||
expect(openMock).toHaveBeenCalledWith(path); | ||
}); | ||
}); | ||
}); |