Skip to content

Commit

Permalink
Add tests for hasPreviousCommit
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Oct 9, 2023
1 parent a8e78e8 commit e6bcce9
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion node-src/git/git.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { execaCommand } from 'execa';
import { describe, expect, it, vi } from 'vitest';

import { getCommit, getSlug } from './git';
import { getCommit, getSlug, hasPreviousCommit } from './git';

vi.mock('execa');

Expand Down Expand Up @@ -62,3 +62,32 @@ describe('getSlug', () => {
expect(await getSlug()).toBe('foo/bar.baz');
});
});

describe('hasPreviousCommit', () => {
it('returns true if a commit is found', async () => {
command.mockImplementation(
() => Promise.resolve({ all: `19b6c9c5b3d34d9fc55627fcaf8a85bd5d5e5b2a` }) as any
);
expect(await hasPreviousCommit()).toEqual(true);
});

it('returns false if no commit is found', async () => {
command.mockImplementation(() => Promise.resolve({ all: `` }) as any);
expect(await hasPreviousCommit()).toEqual(false);
});

it('ignores gpg signature information', async () => {
command.mockImplementation(
() =>
Promise.resolve({
all: `
gpg: Signature made Fri Oct 6 12:40:14 2023 CEST
gpg: using RSA key 4AEE18F83AFDEB23
gpg: Can't check signature: No public key
19b6c9c5b3d34d9fc55627fcaf8a85bd5d5e5b2a
`.trim(),
}) as any
);
expect(await hasPreviousCommit()).toEqual(true);
});
});

0 comments on commit e6bcce9

Please sign in to comment.