forked from brendon1982/ts-mocking-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
04_class_dependency_initialized_within_sut.test.ts
60 lines (54 loc) · 1.68 KB
/
04_class_dependency_initialized_within_sut.test.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
59
60
import { describe, it } from 'mocha'
import { expect } from 'chai'
import sinon from 'sinon'
import { ItemPriceAdjusterVersion2 } from '../tests-to-implement/04_class_dependency_initialized_within_sut'
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);
let sut = createSut();
sinon.stub(sut['pricingService'], 'getMarkUpPercentage').resolves(100);
// Act
let adjustedItem = await sut.adjustPrice(item);
// Assert
expect(adjustedItem.price).eqls(60);
})
})
describe('price is greater than 100', () => {
it('marks item price down by the markdown percentage', async () => {
// Arrange
let item = createItem(140);
let sut = createSut();
sinon.stub(sut['pricingService'], 'getMarkDownPercentage').resolves(50);
// Act
let adjustedItem = await sut.adjustPrice(item);
// Assert
expect(adjustedItem.price).eqls(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).eqls(100);
})
})
})