-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChainPatternDemo.spec.ts
More file actions
executable file
·56 lines (43 loc) · 1.68 KB
/
ChainPatternDemo.spec.ts
File metadata and controls
executable file
·56 lines (43 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import {
describe,
it,
expect,
} from 'angular2/testing';
import {AbstractPurchasePower} from './AbstractPurchasePower';
import {ManagerPurchasePower} from './ManagerPurchasePower';
import {DirectorPurchasePower} from './DirectorPurchasePower';
import {PresidentPurchasePower} from './PresidentPurchasePower';
import {PurchaseRequest} from './PurchaseRequest';
function getInitiator() {
let manager: AbstractPurchasePower = new ManagerPurchasePower();
let director: AbstractPurchasePower = new DirectorPurchasePower();
let president: AbstractPurchasePower = new PresidentPurchasePower();
manager.setSuccessor(director);
director.setSuccessor(president);
return manager;
}
export function main() {
describe('ChainOfResponsibility', () => {
let initiator: AbstractPurchasePower = getInitiator();
it('Should be approved by manager', () => {
let request = new PurchaseRequest(8000);
initiator.processRequest(request);
expect(request.getApprovedBy() instanceof ManagerPurchasePower).toEqual(true);
});
it('Should be approved by director', () => {
let request = new PurchaseRequest(16000);
initiator.processRequest(request);
expect(request.getApprovedBy() instanceof DirectorPurchasePower).toEqual(true);
});
it('Should be approved by president', () => {
let request = new PurchaseRequest(26000);
initiator.processRequest(request);
expect(request.getApprovedBy() instanceof PresidentPurchasePower).toEqual(true);
});
it('Should be not approved', () => {
let request = new PurchaseRequest(50000);
initiator.processRequest(request);
expect(request.getApprovedBy()).toBeNull();
});
});
}