add support for different recommendation levels: strict and standard

This commit is contained in:
undergroundwires
2020-10-19 14:51:42 +01:00
parent 978bab0b81
commit 14be3017c5
20 changed files with 954 additions and 654 deletions

View File

@@ -1,6 +1,7 @@
import 'mocha';
import { expect } from 'chai';
import { Script } from '@/domain/Script';
import { RecommendationLevelNames, RecommendationLevel } from '@/domain/RecommendationLevel';
describe('Script', () => {
describe('ctor', () => {
@@ -13,6 +14,11 @@ describe('Script', () => {
const code = 'duplicate\n\n\ntest\nduplicate';
expect(() => createWithCode(code)).to.throw();
});
it('sets as expected', () => {
const expected = 'expected-revert';
const sut = createWithCode(expected);
expect(sut.code).to.equal(expected);
});
});
describe('revertCode', () => {
it('cannot construct with duplicate lines', () => {
@@ -27,6 +33,11 @@ describe('Script', () => {
const code = 'REM';
expect(() => createWithCode(code, code)).to.throw();
});
it('sets as expected', () => {
const expected = 'expected-revert';
const sut = createWithCode('abc', expected);
expect(sut.revertCode).to.equal(expected);
});
});
describe('canRevert', () => {
it('returns false without revert code', () => {
@@ -38,9 +49,28 @@ describe('Script', () => {
expect(sut.canRevert()).to.equal(true);
});
});
describe('level', () => {
it('cannot construct with invalid wrong value', () => {
expect(() => createWithLevel(55)).to.throw('invalid level');
});
it('sets undefined as expected', () => {
const sut = createWithLevel(undefined);
expect(sut.level).to.equal(undefined);
});
it('sets as expected', () => {
for (const expected of RecommendationLevelNames) {
const sut = createWithLevel(RecommendationLevel[expected]);
const actual = RecommendationLevel[sut.level];
expect(actual).to.equal(expected);
}
});
});
});
});
function createWithCode(code: string, revertCode?: string): Script {
return new Script('name', code, revertCode, [], false);
return new Script('name', code, revertCode, [], RecommendationLevel.Standard);
}
function createWithLevel(level: RecommendationLevel): Script {
return new Script('name', 'code', 'revertCode', [], level);
}