refactor to read more from package.json
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import { ScriptStub } from './../stubs/ScriptStub';
|
||||
import { CategoryStub } from './../stubs/CategoryStub';
|
||||
import { Application } from './../../../src/domain/Application';
|
||||
import { Application } from '@/domain/Application';
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { ProjectInformation } from '@/domain/ProjectInformation';
|
||||
import { IProjectInformation } from '@/domain/IProjectInformation';
|
||||
|
||||
describe('Application', () => {
|
||||
it('getRecommendedScripts returns as expected', () => {
|
||||
@@ -11,53 +13,56 @@ describe('Application', () => {
|
||||
new ScriptStub('S3').withIsRecommended(true),
|
||||
new ScriptStub('S4').withIsRecommended(true),
|
||||
];
|
||||
const sut = new Application('name', 'repo', '0.1.0', [
|
||||
const sut = new Application(createInformation(), [
|
||||
new CategoryStub(3).withScripts(expected[0], new ScriptStub('S1').withIsRecommended(false)),
|
||||
new CategoryStub(2).withScripts(expected[1], new ScriptStub('S2').withIsRecommended(false)),
|
||||
]);
|
||||
|
||||
// act
|
||||
const actual = sut.getRecommendedScripts();
|
||||
|
||||
// assert
|
||||
expect(expected[0]).to.deep.equal(actual[0]);
|
||||
expect(expected[1]).to.deep.equal(actual[1]);
|
||||
});
|
||||
it('cannot construct without categories', () => {
|
||||
// arrange
|
||||
const categories = [];
|
||||
|
||||
// act
|
||||
function construct() { return new Application('name', 'repo', '0.1.0', categories); }
|
||||
|
||||
// assert
|
||||
expect(construct).to.throw('Application must consist of at least one category');
|
||||
});
|
||||
it('cannot construct without scripts', () => {
|
||||
// arrange
|
||||
const categories = [
|
||||
new CategoryStub(3),
|
||||
new CategoryStub(2),
|
||||
];
|
||||
|
||||
// act
|
||||
function construct() { return new Application('name', 'repo', '0.1.0', categories); }
|
||||
|
||||
// assert
|
||||
expect(construct).to.throw('Application must consist of at least one script');
|
||||
});
|
||||
it('cannot construct without any recommended scripts', () => {
|
||||
// arrange
|
||||
const categories = [
|
||||
new CategoryStub(3).withScripts(new ScriptStub('S1').withIsRecommended(false)),
|
||||
new CategoryStub(2).withScripts(new ScriptStub('S2').withIsRecommended(false)),
|
||||
];
|
||||
|
||||
// act
|
||||
function construct() { return new Application('name', 'repo', '0.1.0', categories); }
|
||||
|
||||
// assert
|
||||
expect(construct).to.throw('Application must consist of at least one recommended script');
|
||||
describe('parameter validation', () => {
|
||||
it('cannot construct without categories', () => {
|
||||
// arrange
|
||||
const categories = [];
|
||||
// act
|
||||
function construct() { return new Application(createInformation(), categories); }
|
||||
// assert
|
||||
expect(construct).to.throw('Application must consist of at least one category');
|
||||
});
|
||||
it('cannot construct without scripts', () => {
|
||||
// arrange
|
||||
const categories = [
|
||||
new CategoryStub(3),
|
||||
new CategoryStub(2),
|
||||
];
|
||||
// act
|
||||
function construct() { return new Application(createInformation(), categories); }
|
||||
// assert
|
||||
expect(construct).to.throw('Application must consist of at least one script');
|
||||
});
|
||||
it('cannot construct without any recommended scripts', () => {
|
||||
// arrange
|
||||
const categories = [
|
||||
new CategoryStub(3).withScripts(new ScriptStub('S1').withIsRecommended(false)),
|
||||
new CategoryStub(2).withScripts(new ScriptStub('S2').withIsRecommended(false)),
|
||||
];
|
||||
// act
|
||||
function construct() { return new Application(createInformation(), categories); }
|
||||
// assert
|
||||
expect(construct).to.throw('Application must consist of at least one recommended script');
|
||||
});
|
||||
it('cannot construct without information', () => {
|
||||
// arrange
|
||||
const categories = [new CategoryStub(1).withScripts(new ScriptStub('S1').withIsRecommended(true))];
|
||||
const information = undefined;
|
||||
// act
|
||||
function construct() { return new Application(information, categories); }
|
||||
// assert
|
||||
expect(construct).to.throw('info is undefined');
|
||||
});
|
||||
});
|
||||
it('totalScripts counts right', () => {
|
||||
// arrange
|
||||
@@ -67,9 +72,9 @@ describe('Application', () => {
|
||||
new CategoryStub(3).withCategories(new CategoryStub(4).withScripts(new ScriptStub('S4'))),
|
||||
];
|
||||
// act
|
||||
const application = new Application('name', 'repo', '0.1.0', categories);
|
||||
const sut = new Application(createInformation(), categories);
|
||||
// assert
|
||||
expect(application.totalScripts).to.equal(4);
|
||||
expect(sut.totalScripts).to.equal(4);
|
||||
});
|
||||
it('totalCategories counts right', () => {
|
||||
// arrange
|
||||
@@ -79,8 +84,22 @@ describe('Application', () => {
|
||||
new CategoryStub(3).withCategories(new CategoryStub(4).withScripts(new ScriptStub('S4'))),
|
||||
];
|
||||
// act
|
||||
const application = new Application('name', 'repo', '0.1.0', categories);
|
||||
const sut = new Application(createInformation(), categories);
|
||||
// assert
|
||||
expect(application.totalCategories).to.equal(4);
|
||||
expect(sut.totalCategories).to.equal(4);
|
||||
});
|
||||
it('sets information as expected', () => {
|
||||
// arrange
|
||||
const expected = createInformation();
|
||||
// act
|
||||
const sut = new Application(
|
||||
expected,
|
||||
[new CategoryStub(1).withScripts(new ScriptStub('S1').withIsRecommended(true))]);
|
||||
// assert
|
||||
expect(sut.info).to.deep.equal(expected);
|
||||
});
|
||||
});
|
||||
|
||||
function createInformation(): IProjectInformation {
|
||||
return new ProjectInformation('name', 'repo', '0.1.0', 'homepage');
|
||||
}
|
||||
|
||||
128
tests/unit/domain/ProjectInformation.spec.ts
Normal file
128
tests/unit/domain/ProjectInformation.spec.ts
Normal file
@@ -0,0 +1,128 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { ProjectInformation } from '@/domain/ProjectInformation';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
|
||||
describe('ProjectInformation', () => {
|
||||
it('sets name as expected', () => {
|
||||
// arrange
|
||||
const expected = 'expected-name';
|
||||
const sut = new ProjectInformation(expected, 'version', 'repositoryUrl', 'homepage');
|
||||
// act
|
||||
const actual = sut.name;
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
it('sets version as expected', () => {
|
||||
// arrange
|
||||
const expected = 'expected-version';
|
||||
const sut = new ProjectInformation('name', expected, 'repositoryUrl', 'homepage');
|
||||
// act
|
||||
const actual = sut.version;
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
it('sets repositoryUrl as expected', () => {
|
||||
// arrange
|
||||
const expected = 'expected-repository-url';
|
||||
const sut = new ProjectInformation('name', 'version', expected, 'homepage');
|
||||
// act
|
||||
const actual = sut.repositoryUrl;
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
describe('sets repositoryWebUrl as expected', () => {
|
||||
it('sets repositoryUrl when it does not end with .git', () => {
|
||||
// arrange
|
||||
const expected = 'expected-repository-url';
|
||||
const sut = new ProjectInformation('name', 'version', expected, 'homepage');
|
||||
// act
|
||||
const actual = sut.repositoryWebUrl;
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
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');
|
||||
// act
|
||||
const actual = sut.repositoryWebUrl;
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
});
|
||||
it('sets homepage as expected', () => {
|
||||
// arrange
|
||||
const expected = 'expected-homepage';
|
||||
const sut = new ProjectInformation('name', 'version', 'repositoryUrl', expected);
|
||||
// act
|
||||
const actual = sut.homepage;
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
it('sets feedbackUrl to github issues page', () => {
|
||||
// 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');
|
||||
// act
|
||||
const actual = sut.feedbackUrl;
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
it('sets releaseUrl to github releases page', () => {
|
||||
// arrange
|
||||
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');
|
||||
// act
|
||||
const actual = sut.releaseUrl;
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
describe('getDownloadUrl', () => {
|
||||
it('gets expected url for macOS', () => {
|
||||
// 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 sut = new ProjectInformation('name', version, repositoryUrl, 'homepage');
|
||||
// act
|
||||
const actual = sut.getDownloadUrl(OperatingSystem.macOS);
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
it('gets expected url for Linux', () => {
|
||||
// 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 sut = new ProjectInformation('name', version, repositoryUrl, 'homepage');
|
||||
// act
|
||||
const actual = sut.getDownloadUrl(OperatingSystem.Linux);
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
it('gets expected url for Windows', () => {
|
||||
// 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 sut = new ProjectInformation('name', version, repositoryUrl, 'homepage');
|
||||
// act
|
||||
const actual = sut.getDownloadUrl(OperatingSystem.Windows);
|
||||
// assert
|
||||
expect(actual).to.equal(expected);
|
||||
});
|
||||
it('throws when OS is unknown', () => {
|
||||
// arrange
|
||||
const sut = new ProjectInformation('name', 'version', 'repositoryUrl', 'homepage');
|
||||
const os = OperatingSystem.Unknown;
|
||||
// act
|
||||
const act = () => sut.getDownloadUrl(os);
|
||||
// assert
|
||||
expect(act).to.throw(`Unsupported os: ${OperatingSystem[os]}`);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user