|
| 1 | +const { pricesForUsageOnTier } = require('../dist/index.js'); |
| 2 | + |
| 3 | +const tiers1 = [ |
| 4 | + { |
| 5 | + threshold: 0, |
| 6 | + price: 0, |
| 7 | + currency: 'EUR', |
| 8 | + }, |
| 9 | + { |
| 10 | + threshold: 2, |
| 11 | + price: 250, |
| 12 | + currency: 'EUR', |
| 13 | + }, |
| 14 | + { |
| 15 | + threshold: 20, |
| 16 | + price: 20, |
| 17 | + currency: 'EUR', |
| 18 | + }, |
| 19 | +]; |
| 20 | + |
| 21 | +const tiers2 = [ |
| 22 | + { |
| 23 | + threshold: 15, |
| 24 | + price: 500, |
| 25 | + currency: 'EUR', |
| 26 | + }, |
| 27 | + { |
| 28 | + threshold: 40, |
| 29 | + price: 100, |
| 30 | + currency: 'EUR', |
| 31 | + }, |
| 32 | + { |
| 33 | + threshold: 30, |
| 34 | + price: 300, |
| 35 | + currency: 'EUR', |
| 36 | + }, |
| 37 | +]; |
| 38 | + |
| 39 | +const tiers3 = [ |
| 40 | + { |
| 41 | + threshold: 0, |
| 42 | + price: 5, |
| 43 | + currency: 'EUR', |
| 44 | + }, |
| 45 | + { |
| 46 | + threshold: 3, |
| 47 | + price: 4, |
| 48 | + currency: 'EUR', |
| 49 | + }, |
| 50 | + { |
| 51 | + threshold: 15, |
| 52 | + price: 3, |
| 53 | + currency: 'EUR', |
| 54 | + }, |
| 55 | + { |
| 56 | + threshold: 25, |
| 57 | + price: 2, |
| 58 | + currency: 'EUR', |
| 59 | + }, |
| 60 | + { |
| 61 | + threshold: 50, |
| 62 | + price: 1, |
| 63 | + currency: 'EUR', |
| 64 | + }, |
| 65 | +]; |
| 66 | + |
| 67 | +const tiers4 = [ |
| 68 | + { |
| 69 | + threshold: 15, |
| 70 | + price: 3, |
| 71 | + currency: 'EUR', |
| 72 | + }, |
| 73 | + { |
| 74 | + threshold: 25, |
| 75 | + price: 2, |
| 76 | + currency: 'EUR', |
| 77 | + }, |
| 78 | + { |
| 79 | + threshold: 50, |
| 80 | + price: 1, |
| 81 | + currency: 'EUR', |
| 82 | + }, |
| 83 | +]; |
| 84 | + |
| 85 | +const tiers5 = [ |
| 86 | + { |
| 87 | + threshold: 75, |
| 88 | + price: 3, |
| 89 | + currency: 'EUR', |
| 90 | + }, |
| 91 | + { |
| 92 | + threshold: 25, |
| 93 | + price: 2, |
| 94 | + currency: 'EUR', |
| 95 | + }, |
| 96 | + { |
| 97 | + threshold: 50, |
| 98 | + price: 1, |
| 99 | + currency: 'EUR', |
| 100 | + }, |
| 101 | +]; |
| 102 | + |
| 103 | +test('Price For Volume', () => { |
| 104 | + expect(pricesForUsageOnTier(0, tiers1, 'volume')).toEqual({ EUR: 0 }); |
| 105 | + expect(pricesForUsageOnTier(2, tiers1, 'volume')).toEqual({ EUR: 500 }); |
| 106 | + expect(pricesForUsageOnTier(3, tiers1, 'volume')).toEqual({ EUR: 750 }); |
| 107 | + expect(pricesForUsageOnTier(20, tiers1, 'volume')).toEqual({ EUR: 400 }); |
| 108 | + expect(pricesForUsageOnTier(40, tiers1, 'volume')).toEqual({ EUR: 800 }); |
| 109 | + |
| 110 | + expect(pricesForUsageOnTier(3, tiers2, 'volume')).toEqual({ EUR: 0 }); |
| 111 | + expect(pricesForUsageOnTier(14, tiers2, 'volume')).toEqual({ EUR: 0 }); |
| 112 | + expect(pricesForUsageOnTier(15, tiers2, 'volume')).toEqual({ EUR: 7500 }); |
| 113 | + expect(pricesForUsageOnTier(16, tiers2, 'volume')).toEqual({ EUR: 8000 }); |
| 114 | + expect(pricesForUsageOnTier(30, tiers2, 'volume')).toEqual({ EUR: 9000 }); |
| 115 | + expect(pricesForUsageOnTier(31, tiers2, 'volume')).toEqual({ EUR: 9300 }); |
| 116 | + expect(pricesForUsageOnTier(40, tiers2, 'volume')).toEqual({ EUR: 4000 }); |
| 117 | + expect(pricesForUsageOnTier(41, tiers2, 'volume')).toEqual({ EUR: 4100 }); |
| 118 | + expect(pricesForUsageOnTier(131, tiers2, 'volume')).toEqual({ EUR: 13100 }); |
| 119 | +}); |
| 120 | + |
| 121 | +test('Price For Graduated', () => { |
| 122 | + expect(pricesForUsageOnTier(4, tiers3, 'graduated')).toEqual({ EUR: 19 }); |
| 123 | + expect(pricesForUsageOnTier(211, tiers3, 'graduated')).toEqual({ EUR: 368 }); |
| 124 | + expect(pricesForUsageOnTier(14, tiers4, 'graduated')).toEqual({ EUR: 0 }); |
| 125 | + expect(pricesForUsageOnTier(15, tiers5, 'graduated')).toEqual({ EUR: 0 }); |
| 126 | + expect(pricesForUsageOnTier(25, tiers5, 'graduated')).toEqual({ EUR: 2 }); |
| 127 | +}); |
0 commit comments