forked from brendon1982/ts-mocking-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
04_class_dependency_initialized_within_sut.jasmine.ts
58 lines (52 loc) · 1.65 KB
/
04_class_dependency_initialized_within_sut.jasmine.ts
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
55
56
57
58
import { ItemPriceAdjusterVersion2 } from '../tests-to-implement/04_class_dependency_initialized_within_sut'
import { Item } from "../dependencies/Item"
import { PricingService } from '../dependencies/PricingService'
describe('ItemPriceAdjusterVersion2', () => {
let createItem = (price: number): Item => {
return {
id: "id",
name: "name",
price: price,
description: "description",
created: new Date()
}
}
let createSut = () => {
return new ItemPriceAdjusterVersion2();
}
describe('price is less than 100', () => {
it('marks item price up by the markup percentage', async () => {
// Arrange
let item = createItem(30);
spyOn(PricingService.prototype, 'getMarkUpPercentage').and.resolveTo(100);
let sut = createSut();
// Act
let adjustedItem = await sut.adjustPrice(item);
// Assert
expect(adjustedItem.price).toEqual(60);
})
})
describe('price is greater than 100', () => {
it('marks item price down by the markdown percentage', async () => {
// Arrange
let item = createItem(140);
spyOn(PricingService.prototype, 'getMarkDownPercentage').and.resolveTo(50);
let sut = createSut();
// Act
let adjustedItem = await sut.adjustPrice(item);
// Assert
expect(adjustedItem.price).toEqual(70);
})
})
describe('price is equal to 100', () => {
it('will not alter the price', async () => {
// Arrange
let item = createItem(100);
let sut = createSut();
// Act
let adjustedItem = await sut.adjustPrice(item);
// Assert
expect(adjustedItem.price).toEqual(100);
})
})
})