Refactor to use version object #59

Enable writing safer version aware logic.
This commit is contained in:
undergroundwires
2022-02-26 17:15:30 +01:00
parent d6bc33ec86
commit eeb1d5b0c4
14 changed files with 198 additions and 35 deletions

View File

@@ -3,12 +3,13 @@ import { expect } from 'chai';
import { ProjectInformation } from '@/domain/ProjectInformation';
import { OperatingSystem } from '@/domain/OperatingSystem';
import { EnumRangeTestRunner } from '@tests/unit/application/Common/EnumRangeTestRunner';
import { VersionStub } from '@tests/unit/shared/Stubs/VersionStub';
describe('ProjectInformation', () => {
it('sets name as expected', () => {
// arrange
const expected = 'expected-name';
const sut = new ProjectInformation(expected, 'version', 'repositoryUrl', 'homepage');
const sut = new ProjectInformation(expected, new VersionStub('0.7.2'), 'repositoryUrl', 'homepage');
// act
const actual = sut.name;
// assert
@@ -16,17 +17,17 @@ describe('ProjectInformation', () => {
});
it('sets version as expected', () => {
// arrange
const expected = 'expected-version';
const expected = new VersionStub('0.11.3');
const sut = new ProjectInformation('name', expected, 'repositoryUrl', 'homepage');
// act
const actual = sut.version;
// assert
expect(actual).to.equal(expected);
expect(actual).to.deep.equal(expected);
});
it('sets repositoryUrl as expected', () => {
// arrange
const expected = 'expected-repository-url';
const sut = new ProjectInformation('name', 'version', expected, 'homepage');
const sut = new ProjectInformation('name', new VersionStub('0.7.2'), expected, 'homepage');
// act
const actual = sut.repositoryUrl;
// assert
@@ -36,7 +37,7 @@ describe('ProjectInformation', () => {
it('sets repositoryUrl when it does not end with .git', () => {
// arrange
const expected = 'expected-repository-url';
const sut = new ProjectInformation('name', 'version', expected, 'homepage');
const sut = new ProjectInformation('name', new VersionStub('0.7.2'), expected, 'homepage');
// act
const actual = sut.repositoryWebUrl;
// assert
@@ -45,7 +46,7 @@ describe('ProjectInformation', () => {
it('removes ".git" from the end when it ends with ".git"', () => {
// arrange
const expected = 'expected-repository-url';
const sut = new ProjectInformation('name', 'version', `${expected}.git`, 'homepage');
const sut = new ProjectInformation('name', new VersionStub('0.7.2'), `${expected}.git`, 'homepage');
// act
const actual = sut.repositoryWebUrl;
// assert
@@ -55,7 +56,7 @@ describe('ProjectInformation', () => {
it('sets homepage as expected', () => {
// arrange
const expected = 'expected-homepage';
const sut = new ProjectInformation('name', 'version', 'repositoryUrl', expected);
const sut = new ProjectInformation('name', new VersionStub('0.7.2'), 'repositoryUrl', expected);
// act
const actual = sut.homepage;
// assert
@@ -65,7 +66,7 @@ describe('ProjectInformation', () => {
// arrange
const repositoryUrl = 'https://github.com/undergroundwires/privacy.sexy.git';
const expected = 'https://github.com/undergroundwires/privacy.sexy/issues';
const sut = new ProjectInformation('name', 'version', repositoryUrl, 'homepage');
const sut = new ProjectInformation('name', new VersionStub('0.7.2'), repositoryUrl, 'homepage');
// act
const actual = sut.feedbackUrl;
// assert
@@ -74,7 +75,7 @@ describe('ProjectInformation', () => {
it('sets releaseUrl to github releases page', () => {
// arrange
const repositoryUrl = 'https://github.com/undergroundwires/privacy.sexy.git';
const version = '0.7.2';
const version = new VersionStub('0.7.2');
const expected = 'https://github.com/undergroundwires/privacy.sexy/releases/tag/0.7.2';
const sut = new ProjectInformation('name', version, repositoryUrl, 'homepage');
// act
@@ -87,7 +88,7 @@ describe('ProjectInformation', () => {
// arrange
const expected = 'https://github.com/undergroundwires/privacy.sexy/releases/download/0.7.2/privacy.sexy-0.7.2.dmg';
const repositoryUrl = 'https://github.com/undergroundwires/privacy.sexy.git';
const version = '0.7.2';
const version = new VersionStub('0.7.2');
const sut = new ProjectInformation('name', version, repositoryUrl, 'homepage');
// act
const actual = sut.getDownloadUrl(OperatingSystem.macOS);
@@ -98,7 +99,7 @@ describe('ProjectInformation', () => {
// arrange
const expected = 'https://github.com/undergroundwires/privacy.sexy/releases/download/0.7.2/privacy.sexy-0.7.2.AppImage';
const repositoryUrl = 'https://github.com/undergroundwires/privacy.sexy.git';
const version = '0.7.2';
const version = new VersionStub('0.7.2');
const sut = new ProjectInformation('name', version, repositoryUrl, 'homepage');
// act
const actual = sut.getDownloadUrl(OperatingSystem.Linux);
@@ -109,7 +110,7 @@ describe('ProjectInformation', () => {
// arrange
const expected = 'https://github.com/undergroundwires/privacy.sexy/releases/download/0.7.2/privacy.sexy-Setup-0.7.2.exe';
const repositoryUrl = 'https://github.com/undergroundwires/privacy.sexy.git';
const version = '0.7.2';
const version = new VersionStub('0.7.2');
const sut = new ProjectInformation('name', version, repositoryUrl, 'homepage');
// act
const actual = sut.getDownloadUrl(OperatingSystem.Windows);
@@ -118,7 +119,7 @@ describe('ProjectInformation', () => {
});
describe('throws when os is invalid', () => {
// arrange
const sut = new ProjectInformation('name', 'version', 'repositoryUrl', 'homepage');
const sut = new ProjectInformation('name', new VersionStub(), 'repositoryUrl', 'homepage');
// act
const act = (os: OperatingSystem) => sut.getDownloadUrl(os);
// assert