Skip to content

Commit

Permalink
more version update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Jun 11, 2020
1 parent a68f9b1 commit 11fdaac
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/isVersionUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { Version } from './types';
/**
* Returns true if versionB is an update over versionA
*/
export function isVersionUpdate(versionA: Version, versionB: Version): boolean {
if (versionB.major > versionA.major) {
export function isVersionUpdate(base: Version, update: Version): boolean {
if (update.major > base.major) {
return true;
}
if (versionB.major < versionA.major) {
if (update.major < base.major) {
return false;
}
if (versionB.minor > versionA.minor) {
if (update.minor > base.minor) {
return true;
}
if (versionB.minor < versionA.minor) return false;
return versionB.patch > versionA.patch;
if (update.minor < base.minor) return false;
return update.patch > base.patch;
}
28 changes: 26 additions & 2 deletions test/isVersionUpdate.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isVersionUpdate } from '../src';

describe('#isVersionUpdate', () => {
it('major version increase', () => {
it('major version', () => {
expect(
isVersionUpdate(
{ major: 1, minor: 0, patch: 0 },
Expand All @@ -26,9 +26,21 @@ describe('#isVersionUpdate', () => {
{ major: 2, minor: 0, patch: 0 }
)
).toEqual(true);
expect(
isVersionUpdate(
{ major: 1, minor: 0, patch: 2 },
{ major: 1, minor: 0, patch: 1 }
)
).toEqual(false);
expect(
isVersionUpdate(
{ major: 1, minor: 0, patch: 2 },
{ major: 1, minor: 0, patch: 2 }
)
).toEqual(false);
});

it('minor version increase', () => {
it('minor version', () => {
expect(
isVersionUpdate(
{ major: 1, minor: 0, patch: 0 },
Expand Down Expand Up @@ -80,5 +92,17 @@ describe('#isVersionUpdate', () => {
{ major: 1, minor: 2, patch: 0 }
)
).toEqual(true);
expect(
isVersionUpdate(
{ major: 1, minor: 1, patch: 1 },
{ major: 2, minor: 1, patch: 1 }
)
).toEqual(true);
expect(
isVersionUpdate(
{ major: 2, minor: 1, patch: 1 },
{ major: 1, minor: 1, patch: 2 }
)
).toEqual(false);
});
});

0 comments on commit 11fdaac

Please sign in to comment.