import 'mocha' ; import { expect } from 'chai' ; import { ProjectInformation } from '@/domain/ProjectInformation' ; import { OperatingSystem } from '@/domain/OperatingSystem' ; import { EnumRangeTestRunner } from '@tests/unit/application/Common/EnumRangeTestRunner' ; describe ( 'ProjectInformation' , ( ) => { it ( 'sets name as expected' , ( ) => { const expected = 'expected-name' ; const sut = new ProjectInformation ( expected , 'version' , 'repositoryUrl' , 'homepage' ) ; const actual = sut . name ; expect ( actual ) . to . equal ( expected ) ; } ) ; it ( 'sets version as expected' , ( ) => { const expected = 'expected-version' ; const sut = new ProjectInformation ( 'name' , expected , 'repositoryUrl' , 'homepage' ) ; const actual = sut . version ; expect ( actual ) . to . equal ( expected ) ; } ) ; it ( 'sets repositoryUrl as expected' , ( ) => { const expected = 'expected-repository-url' ; const sut = new ProjectInformation ( 'name' , 'version' , expected , 'homepage' ) ; const actual = sut . repositoryUrl ; expect ( actual ) . to . equal ( expected ) ; } ) ; describe ( 'sets repositoryWebUrl as expected' , ( ) => { it ( 'sets repositoryUrl when it does not end with .git' , ( ) => { const expected = 'expected-repository-url' ; const sut = new ProjectInformation ( 'name' , 'version' , expected , 'homepage' ) ; const actual = sut . repositoryWebUrl ; expect ( actual ) . to . equal ( expected ) ; } ) ; it ( 'removes ".git" from the end when it ends with ".git"' , ( ) => { const expected = 'expected-repository-url' ; const sut = new ProjectInformation ( 'name' , 'version' , `${ expected }.git` , 'homepage' ) ; const actual = sut . repositoryWebUrl ; expect ( actual ) . to . equal ( expected ) ; } ) ; } ) ; it ( 'sets homepage as expected' , ( ) => { const expected = 'expected-homepage' ; const sut = new ProjectInformation ( 'name' , 'version' , 'repositoryUrl' , expected ) ; const actual = sut . homepage ; expect ( actual ) . to . equal ( expected ) ; } ) ; it ( 'sets feedbackUrl to github issues page' , ( ) => { 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 actual = sut . feedbackUrl ; expect ( actual ) . to . equal ( expected ) ; } ) ; it ( 'sets releaseUrl to github releases page' , ( ) => { const repositoryUrl = 'https://github.com/undergroundwires/privacy.sexy.git' ; const version = '0.7.2' ; const expected = 'https://github.com/undergroundwires/privacy.sexy/releases/tag/0.7.2' ; const sut = new ProjectInformation ( 'name' , version , repositoryUrl , 'homepage' ) ; const actual = sut . releaseUrl ; expect ( actual ) . to . equal ( expected ) ; } ) ; describe ( 'getDownloadUrl' , ( ) => { it ( 'gets expected url for macOS' , ( ) => { 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 sut = new ProjectInformation ( 'name' , version , repositoryUrl , 'homepage' ) ; const actual = sut . getDownloadUrl ( OperatingSystem . macOS ) ; expect ( actual ) . to . equal ( expected ) ; } ) ; it ( 'gets expected url for Linux' , ( ) => { 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 sut = new ProjectInformation ( 'name' , version , repositoryUrl , 'homepage' ) ; const actual = sut . getDownloadUrl ( OperatingSystem . Linux ) ; expect ( actual ) . to . equal ( expected ) ; } ) ; it ( 'gets expected url for Windows' , ( ) => { 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 sut = new ProjectInformation ( 'name' , version , repositoryUrl , 'homepage' ) ; const actual = sut . getDownloadUrl ( OperatingSystem . Windows ) ; expect ( actual ) . to . equal ( expected ) ; } ) ; describe ( 'throws when os is invalid' , ( ) => { const sut = new ProjectInformation ( 'name' , 'version' , 'repositoryUrl' , 'homepage' ) ; const act = ( os ) => sut . getDownloadUrl ( os ) ; new EnumRangeTestRunner ( act ) . testOutOfRangeThrows ( ) . testUndefinedValueThrows ( ) . testInvalidValueThrows ( OperatingSystem . KaiOS , `Unsupported os: ${ OperatingSystem [ OperatingSystem . KaiOS ] }` ) ; } ) ; } ) ; } ) ;