-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreelancer-rates.spec.js
92 lines (76 loc) · 2.52 KB
/
freelancer-rates.spec.js
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// @ts-check
import {
dayRate,
daysInBudget,
priceWithMonthlyDiscount,
} from './freelancer-rates';
const DIFFERENCE_PRECISION_IN_DIGITS = 6;
describe('day rate', () => {
test('at 16/hour', () => {
const actual = dayRate(16);
expect(actual).toBe(128);
});
test('at 25/hour', () => {
const actual = dayRate(25);
expect(actual).toBe(200);
});
test('at 31.40/hour', () => {
const actual = dayRate(31.4);
expect(actual).toBeCloseTo(251.2, DIFFERENCE_PRECISION_IN_DIGITS);
});
test('at 89.89/hour', () => {
const actual = dayRate(89.89);
expect(actual).toBeCloseTo(719.12, DIFFERENCE_PRECISION_IN_DIGITS);
});
test('at 97.654321/hour', () => {
const actual = dayRate(97.654321);
expect(actual).toBeCloseTo(781.234568, DIFFERENCE_PRECISION_IN_DIGITS);
});
});
describe('days in budget', () => {
describe('with a budget of 1280', () => {
test('at 16/hour', () => {
const actual = daysInBudget(1280, 16);
const expected = 10;
expect(actual).toBeCloseTo(expected, DIFFERENCE_PRECISION_IN_DIGITS);
});
test('at 25/hour', () => {
const actual = daysInBudget(1280, 25);
const expected = 6;
expect(actual).toBeCloseTo(expected, DIFFERENCE_PRECISION_IN_DIGITS);
});
describe('with a budget of 835', () => {
test('at 12/hour', () => {
const actual = daysInBudget(835, 12);
const expected = 8;
expect(actual).toBeCloseTo(expected, DIFFERENCE_PRECISION_IN_DIGITS);
});
});
});
});
describe('cost with monthly discount', () => {
describe('at 16/hour', () => {
test('for 70 days', () => {
const actual = priceWithMonthlyDiscount(16, 70, 0);
const expected = 8960;
expect(actual).toBeCloseTo(expected, DIFFERENCE_PRECISION_IN_DIGITS);
});
test('for 130 days with 15% discount', () => {
const actual = priceWithMonthlyDiscount(16, 130, 0.15);
const expected = 14528;
expect(actual).toBeCloseTo(expected, DIFFERENCE_PRECISION_IN_DIGITS);
});
});
describe('at 29.654321/hour', () => {
test('for 220 days with 11.2%', () => {
const actual = priceWithMonthlyDiscount(29.654321, 220, 0.112);
const expected = 46347;
expect(actual).toBeCloseTo(expected, DIFFERENCE_PRECISION_IN_DIGITS);
});
test('for 155 days with 25.47% discount', () => {
const actual = priceWithMonthlyDiscount(29.654321, 155, 0.2547);
const expected = 27467;
expect(actual).toBeCloseTo(expected, DIFFERENCE_PRECISION_IN_DIGITS);
});
});
});