Skip to content

Commit

Permalink
test: add unit test with default config
Browse files Browse the repository at this point in the history
  • Loading branch information
saitho committed Nov 1, 2021
1 parent 5df3ec3 commit fb832d1
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/perform-backmerge.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {performBackmerge} from "../src/perform-backmerge";
import Git from "../src/helpers/git";
import {instance, mock, verify, when, anyString, anything} from "ts-mockito";
import {resolveConfig} from "../src/helpers/resolve-config";

class NullLogger {
log(message) {}
Expand All @@ -24,6 +25,33 @@ describe("perform-backmerge", () => {
performBackmerge(instance(mockedGit), {branches: ['develop']}, context)
.then(() => {
verify(mockedLogger.log('Performing back-merge into branch "develop".')).once();
verify(mockedLogger.error('Invalid branch configuration found and ignored.')).never();
verify(mockedGit.checkout('master')).once();
verify(mockedGit.configFetchAllRemotes()).once();
verify(mockedGit.fetch(context.options.repositoryUrl)).once();
verify(mockedGit.checkout('develop')).once();
verify(mockedGit.rebase('master')).once();
verify(mockedGit.push('my-repo', 'develop', false)).once();
done();
})
.catch((error) => done(error));
});

it("works with default configuration", (done) => {
const mockedGit = mock(Git);
const mockedLogger = mock(NullLogger);
when(mockedGit.checkout(anyString())).thenResolve();
when(mockedGit.configFetchAllRemotes()).thenResolve();
when(mockedGit.getStagedFiles()).thenResolve([]);
when(mockedGit.fetch()).thenResolve();
when(mockedGit.rebase(anyString())).thenResolve();
when(mockedGit.push(anyString(), anyString(), anything())).thenResolve();

const context = {logger: instance(mockedLogger), branch: {name: 'master'}, options: {repositoryUrl: 'my-repo'}};
performBackmerge(instance(mockedGit), resolveConfig({}), context)
.then(() => {
verify(mockedLogger.log('Performing back-merge into branch "develop".')).once();
verify(mockedLogger.error('Invalid branch configuration found and ignored.')).never();
verify(mockedGit.checkout('master')).once();
verify(mockedGit.configFetchAllRemotes()).once();
verify(mockedGit.fetch(context.options.repositoryUrl)).once();
Expand Down Expand Up @@ -368,6 +396,8 @@ describe("perform-backmerge to multiple branches", () => {
verify(mockedGit.fetch(context.options.repositoryUrl)).once();
verify(mockedGit.rebase('master')).twice();

verify(mockedLogger.error('Invalid branch configuration found and ignored.')).never();

verify(mockedLogger.log('Performing back-merge into branch "develop".')).once();
verify(mockedGit.checkout('develop')).once();
verify(mockedGit.push('my-repo', 'develop', false)).once();
Expand Down

0 comments on commit fb832d1

Please sign in to comment.