1
1
import each from "jest-each" ;
2
2
3
+ import GraduatedTier from "../src/GraduatedTier" ;
3
4
import GraduatedTieredPricing from "../src/GraduatedTieredPricing" ;
4
5
import NumberOfSubscriptionsNotAllowed from "../src/NumberOfSubscriptionsNotAllowed" ;
5
6
import Subscriptions from "../src/Subscriptions" ;
6
7
7
8
describe ( "Graduated tiered pricing should" , ( ) => {
9
+ const defaultTiers = ( ) : GraduatedTier [ ] => {
10
+ return [
11
+ new GraduatedTier ( 1 , 2 , 299 ) ,
12
+ new GraduatedTier ( 3 , 10 , 239 ) ,
13
+ new GraduatedTier ( 11 , 25 , 219 ) ,
14
+ new GraduatedTier ( 26 , 50 , 199 ) ,
15
+ new GraduatedTier ( 51 , Number . MAX_SAFE_INTEGER , 149 ) ,
16
+ ] ;
17
+ } ;
18
+
8
19
it ( "throw number of subscriptions not allowed for 0 subscriptions" , ( ) => {
9
- const pricing = new GraduatedTieredPricing ( null ) ;
20
+ const tiers = defaultTiers ( ) ;
21
+ const pricing = new GraduatedTieredPricing ( tiers ) ;
10
22
expect ( ( ) => pricing . priceFor ( new Subscriptions ( 0 ) ) ) . toThrow (
11
23
NumberOfSubscriptionsNotAllowed
12
24
) ;
@@ -23,7 +35,8 @@ describe("Graduated tiered pricing should", () => {
23
35
] ) . it (
24
36
"calculate the price for %i subscriptions" ,
25
37
( subscriptions : number , expectedPrice : number ) => {
26
- const pricing = new GraduatedTieredPricing ( null ) ;
38
+ const tiers = defaultTiers ( ) ;
39
+ const pricing = new GraduatedTieredPricing ( tiers ) ;
27
40
expect ( pricing . priceFor ( new Subscriptions ( subscriptions ) ) ) . toBe (
28
41
expectedPrice
29
42
) ;
0 commit comments