forked from jsmapr1/simplifying-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextend.spec.js
More file actions
75 lines (67 loc) · 1.9 KB
/
extend.spec.js
File metadata and controls
75 lines (67 loc) · 1.9 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import expect from 'expect';
import Coupon from './extend';
import { FlashCoupon } from './flash';
describe('coupon', () => {
it('should have rewards for users', () => {
const coupon = new Coupon(10);
const user = {
rewardsEligible: true,
active: true,
};
expect(coupon.price).toEqual(10);
coupon.getRewards(user);
expect(coupon.price).toEqual(9);
});
it('should not reward ineligible users', () => {
const coupon = new Coupon(10);
const user = {
rewardsEligible: true,
active: false,
};
expect(coupon.price).toEqual(10);
coupon.getRewards(user);
expect(coupon.price).toEqual(10);
});
});
describe('flash coupon', () => {
it('should call parent constructor', () => {
const flash = new FlashCoupon(5);
expect(flash.price).toEqual(5);
});
it('should inherit methods', () => {
const flash = new FlashCoupon(5);
expect(flash.getPriceText()).toEqual('$ 5');
});
it('should override parent methods', () => {
const flash = new FlashCoupon(5);
const message = 'This is a flash offer and expires in two hours.';
expect(flash.getExpirationMessage()).toEqual(message);
});
it('should call parent methods for user authentication', () => {
const flash = new FlashCoupon(100);
const user = {
rewardsEligible: true,
active: true,
};
flash.getRewards(user);
expect(flash.price).toEqual(80);
});
it('should not give rewards to inactive user', () => {
const flash = new FlashCoupon(100);
const user = {
rewardsEligible: true,
active: false,
};
flash.getRewards(user);
expect(flash.price).toEqual(100);
});
it('should not give rewards to user when price is too low', () => {
const flash = new FlashCoupon(10);
const user = {
rewardsEligible: true,
active: true,
};
flash.getRewards(user);
expect(flash.price).toEqual(10);
});
});