singapore_cpf_calculator 1.3.4 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +37 -0
  3. data/.rubocop.yml +81 -0
  4. data/.rubocop_todo.yml +326 -0
  5. data/README.md +2 -0
  6. data/lib/singapore_cpf_calculator/age_group.rb +27 -5
  7. data/lib/singapore_cpf_calculator/base_calculator.rb +14 -2
  8. data/lib/singapore_cpf_calculator/requirements/group_above_65_to_70_years.rb +13 -0
  9. data/lib/singapore_cpf_calculator/requirements/group_above_70_years.rb +13 -0
  10. data/lib/singapore_cpf_calculator/requirements.rb +3 -0
  11. data/lib/singapore_cpf_calculator/residency_module_common.rb +5 -1
  12. data/lib/singapore_cpf_calculator/version.rb +1 -1
  13. data/lib/singapore_cpf_calculator/year_2016.rb +2 -2
  14. data/lib/singapore_cpf_calculator/year_2022/citizen_or_spr_3/age_55_below_contribution_calculator.rb +8 -0
  15. data/lib/singapore_cpf_calculator/year_2022/citizen_or_spr_3/age_55_to_60_contribution_calculator.rb +32 -0
  16. data/lib/singapore_cpf_calculator/year_2022/citizen_or_spr_3/age_60_to_65_contribution_calculator.rb +32 -0
  17. data/lib/singapore_cpf_calculator/year_2022/citizen_or_spr_3/age_65_to_70_contribution_calculator.rb +32 -0
  18. data/lib/singapore_cpf_calculator/year_2022/citizen_or_spr_3/age_70_up_contribution_calculator.rb +32 -0
  19. data/lib/singapore_cpf_calculator/year_2022/citizen_or_spr_3/citizen_or_spr3_base.rb +9 -0
  20. data/lib/singapore_cpf_calculator/year_2022/citizen_or_spr_3.rb +40 -0
  21. data/lib/singapore_cpf_calculator/year_2022/spr_1_fg/age_55_below_contribution_calculator.rb +11 -0
  22. data/lib/singapore_cpf_calculator/year_2022/spr_1_fg/age_55_to_60_contribution_calculator.rb +32 -0
  23. data/lib/singapore_cpf_calculator/year_2022/spr_1_fg/age_60_to_65_contribution_calculator.rb +32 -0
  24. data/lib/singapore_cpf_calculator/year_2022/spr_1_fg/age_65_to_70_contribution_calculator.rb +32 -0
  25. data/lib/singapore_cpf_calculator/year_2022/spr_1_fg/age_70_up_contribution_calculator.rb +32 -0
  26. data/lib/singapore_cpf_calculator/year_2022/spr_1_fg.rb +40 -0
  27. data/lib/singapore_cpf_calculator/year_2022/spr_1_gg/age_55_below_contribution_calculator.rb +11 -0
  28. data/lib/singapore_cpf_calculator/year_2022/spr_1_gg/age_55_to_60_contribution_calculator.rb +12 -0
  29. data/lib/singapore_cpf_calculator/year_2022/spr_1_gg/age_60_to_65_contribution_calculator.rb +11 -0
  30. data/lib/singapore_cpf_calculator/year_2022/spr_1_gg/age_65_up_contribution_calculator.rb +14 -0
  31. data/lib/singapore_cpf_calculator/year_2022/spr_1_gg.rb +34 -0
  32. data/lib/singapore_cpf_calculator/year_2022/spr_2_fg/age_55_below_contribution_calculator.rb +11 -0
  33. data/lib/singapore_cpf_calculator/year_2022/spr_2_fg/age_55_to_60_contribution_calculator.rb +32 -0
  34. data/lib/singapore_cpf_calculator/year_2022/spr_2_fg/age_60_to_65_contribution_calculator.rb +32 -0
  35. data/lib/singapore_cpf_calculator/year_2022/spr_2_fg/age_65_to_70_contribution_calculator.rb +32 -0
  36. data/lib/singapore_cpf_calculator/year_2022/spr_2_fg/age_70_up_contribution_calculator.rb +32 -0
  37. data/lib/singapore_cpf_calculator/year_2022/spr_2_fg.rb +40 -0
  38. data/lib/singapore_cpf_calculator/year_2022/spr_2_gg/age_55_below_contribution_calculator.rb +11 -0
  39. data/lib/singapore_cpf_calculator/year_2022/spr_2_gg/age_55_to_60_contribution_calculator.rb +11 -0
  40. data/lib/singapore_cpf_calculator/year_2022/spr_2_gg/age_60_to_65_contribution_calculator.rb +11 -0
  41. data/lib/singapore_cpf_calculator/year_2022/spr_2_gg/age_65_up_contribution_calculator.rb +11 -0
  42. data/lib/singapore_cpf_calculator/year_2022/spr_2_gg.rb +34 -0
  43. data/lib/singapore_cpf_calculator/year_2022.rb +35 -0
  44. data/lib/singapore_cpf_calculator/year_2023/citizen_or_spr_3/age_55_below_contribution_calculator.rb +8 -0
  45. data/lib/singapore_cpf_calculator/year_2023/citizen_or_spr_3/age_55_to_60_contribution_calculator.rb +32 -0
  46. data/lib/singapore_cpf_calculator/year_2023/citizen_or_spr_3/age_60_to_65_contribution_calculator.rb +32 -0
  47. data/lib/singapore_cpf_calculator/year_2023/citizen_or_spr_3/age_65_to_70_contribution_calculator.rb +32 -0
  48. data/lib/singapore_cpf_calculator/year_2023/citizen_or_spr_3/age_70_up_contribution_calculator.rb +9 -0
  49. data/lib/singapore_cpf_calculator/year_2023/citizen_or_spr_3/citizen_or_spr3_base.rb +8 -0
  50. data/lib/singapore_cpf_calculator/year_2023/citizen_or_spr_3.rb +40 -0
  51. data/lib/singapore_cpf_calculator/year_2023/spr_1_fg/age_55_below_contribution_calculator.rb +11 -0
  52. data/lib/singapore_cpf_calculator/year_2023/spr_1_fg/age_55_to_60_contribution_calculator.rb +32 -0
  53. data/lib/singapore_cpf_calculator/year_2023/spr_1_fg/age_60_to_65_contribution_calculator.rb +32 -0
  54. data/lib/singapore_cpf_calculator/year_2023/spr_1_fg/age_65_to_70_contribution_calculator.rb +32 -0
  55. data/lib/singapore_cpf_calculator/year_2023/spr_1_fg/age_70_up_contribution_calculator.rb +8 -0
  56. data/lib/singapore_cpf_calculator/year_2023/spr_1_fg.rb +40 -0
  57. data/lib/singapore_cpf_calculator/year_2023/spr_1_gg.rb +29 -0
  58. data/lib/singapore_cpf_calculator/year_2023/spr_2_fg/age_55_below_contribution_calculator.rb +11 -0
  59. data/lib/singapore_cpf_calculator/year_2023/spr_2_fg/age_55_to_60_contribution_calculator.rb +32 -0
  60. data/lib/singapore_cpf_calculator/year_2023/spr_2_fg/age_60_to_65_contribution_calculator.rb +32 -0
  61. data/lib/singapore_cpf_calculator/year_2023/spr_2_fg/age_65_to_70_contribution_calculator.rb +32 -0
  62. data/lib/singapore_cpf_calculator/year_2023/spr_2_fg/age_70_up_contribution_calculator.rb +8 -0
  63. data/lib/singapore_cpf_calculator/year_2023/spr_2_fg.rb +40 -0
  64. data/lib/singapore_cpf_calculator/year_2023/spr_2_gg.rb +29 -0
  65. data/lib/singapore_cpf_calculator/year_2023/year_2023.rb +35 -0
  66. data/lib/singapore_cpf_calculator/year_2023.rb +35 -0
  67. data/lib/singapore_cpf_calculator.rb +10 -1
  68. data/singapore_cpf_calculator.gemspec +5 -3
  69. data/spec/singapore_cpf_calculator/age_group_spec.rb +15 -3
  70. data/spec/singapore_cpf_calculator/year_2016/citizen_or_spr_3/age_55_to_60_contribution_calculator_spec.rb +1 -1
  71. data/spec/singapore_cpf_calculator/year_2016/citizen_or_spr_3/age_60_to_65_contribution_calculator_spec.rb +2 -2
  72. data/spec/singapore_cpf_calculator/year_2016/citizen_or_spr_3_spec.rb +3 -3
  73. data/spec/singapore_cpf_calculator/year_2016/spr_1_fg/age_55_to_60_contribution_calculator_spec.rb +1 -1
  74. data/spec/singapore_cpf_calculator/year_2016/spr_1_fg/age_60_to_65_contribution_calculator_spec.rb +1 -1
  75. data/spec/singapore_cpf_calculator/year_2016/spr_2_fg/age_60_to_65_contribution_calculator_spec.rb +1 -1
  76. data/spec/singapore_cpf_calculator/year_2022/citizen_or_spr_3/age_55_below_contribution_calculator_spec.rb +63 -0
  77. data/spec/singapore_cpf_calculator/year_2022/citizen_or_spr_3/age_55_to_60_contribution_calculator_spec.rb +63 -0
  78. data/spec/singapore_cpf_calculator/year_2022/citizen_or_spr_3/age_60_to_65_contribution_calculator_spec.rb +63 -0
  79. data/spec/singapore_cpf_calculator/year_2022/citizen_or_spr_3/age_65_to_70_contribution_calculator_spec.rb +63 -0
  80. data/spec/singapore_cpf_calculator/year_2022/citizen_or_spr_3/age_70_up_contribution_spec.rb +63 -0
  81. data/spec/singapore_cpf_calculator/year_2022/citizen_or_spr_3_spec.rb +242 -0
  82. data/spec/singapore_cpf_calculator/year_2022/spr_1_fg/age_55_below_contribution_calculator_spec.rb +63 -0
  83. data/spec/singapore_cpf_calculator/year_2022/spr_1_fg/age_55_to_60_contribution_calculator_spec.rb +63 -0
  84. data/spec/singapore_cpf_calculator/year_2022/spr_1_fg/age_60_to_65_contribution_calculator_spec.rb +63 -0
  85. data/spec/singapore_cpf_calculator/year_2022/spr_1_fg/age_65_to_70_contribution_calculator_spec.rb +63 -0
  86. data/spec/singapore_cpf_calculator/year_2022/spr_1_fg/age_70_up_contribution_calculator_spec.rb +63 -0
  87. data/spec/singapore_cpf_calculator/year_2022/spr_1_fg_spec.rb +176 -0
  88. data/spec/singapore_cpf_calculator/year_2022/spr_1_gg/age_55_below_contribution_calculator_spec.rb +63 -0
  89. data/spec/singapore_cpf_calculator/year_2022/spr_1_gg/age_55_to_60_contribution_calculator_spec.rb +63 -0
  90. data/spec/singapore_cpf_calculator/year_2022/spr_1_gg/age_60_to_65_contribution_calculator_spec.rb +63 -0
  91. data/spec/singapore_cpf_calculator/year_2022/spr_1_gg/age_65_up_contribution_calculator_spec.rb +63 -0
  92. data/spec/singapore_cpf_calculator/year_2022/spr_1_gg_spec.rb +158 -0
  93. data/spec/singapore_cpf_calculator/year_2022/spr_2_fg/age_55_below_contribution_calculator_spec.rb +63 -0
  94. data/spec/singapore_cpf_calculator/year_2022/spr_2_fg/age_55_to_60_contribution_calculator_spec.rb +63 -0
  95. data/spec/singapore_cpf_calculator/year_2022/spr_2_fg/age_60_to_65_contribution_calculator_spec.rb +63 -0
  96. data/spec/singapore_cpf_calculator/year_2022/spr_2_fg/age_65_to_70_contribution_calculator_spec.rb +63 -0
  97. data/spec/singapore_cpf_calculator/year_2022/spr_2_fg/age_70_up_contribution_calculator_spec.rb +63 -0
  98. data/spec/singapore_cpf_calculator/year_2022/spr_2_fg_spec.rb +176 -0
  99. data/spec/singapore_cpf_calculator/year_2022/spr_2_gg/age_55_below_contribution_calculator_spec.rb +63 -0
  100. data/spec/singapore_cpf_calculator/year_2022/spr_2_gg/age_55_to_60_contribution_calculator_spec.rb +63 -0
  101. data/spec/singapore_cpf_calculator/year_2022/spr_2_gg/age_60_to_65_contribution_calculator_spec.rb +63 -0
  102. data/spec/singapore_cpf_calculator/year_2022/spr_2_gg/age_65_up_contribution_calculator_spec.rb +63 -0
  103. data/spec/singapore_cpf_calculator/year_2022/spr_2_gg_spec.rb +158 -0
  104. data/spec/singapore_cpf_calculator/year_2022_spec.rb +192 -0
  105. data/spec/singapore_cpf_calculator/year_2023/citizen_or_spr_3/age_55_below_contribution_calculator_spec.rb +63 -0
  106. data/spec/singapore_cpf_calculator/year_2023/citizen_or_spr_3/age_55_to_60_contribution_calculator_spec.rb +63 -0
  107. data/spec/singapore_cpf_calculator/year_2023/citizen_or_spr_3/age_60_to_65_contribution_calculator_spec.rb +63 -0
  108. data/spec/singapore_cpf_calculator/year_2023/citizen_or_spr_3/age_65_to_70_contribution_calculator_spec.rb +63 -0
  109. data/spec/singapore_cpf_calculator/year_2023/citizen_or_spr_3/age_70_up_contribution_spec.rb +63 -0
  110. data/spec/singapore_cpf_calculator/year_2023/citizen_or_spr_3_spec.rb +242 -0
  111. data/spec/singapore_cpf_calculator/year_2023/spr_1_fg/age_55_below_contribution_calculator_spec.rb +63 -0
  112. data/spec/singapore_cpf_calculator/year_2023/spr_1_fg/age_55_to_60_contribution_calculator_spec.rb +63 -0
  113. data/spec/singapore_cpf_calculator/year_2023/spr_1_fg/age_60_to_65_contribution_calculator_spec.rb +63 -0
  114. data/spec/singapore_cpf_calculator/year_2023/spr_1_fg/age_65_to_70_contribution_calculator_spec.rb +63 -0
  115. data/spec/singapore_cpf_calculator/year_2023/spr_1_fg/age_70_up_contribution_calculator_spec.rb +63 -0
  116. data/spec/singapore_cpf_calculator/year_2023/spr_1_fg_spec.rb +176 -0
  117. data/spec/singapore_cpf_calculator/year_2023/spr_1_gg_spec.rb +158 -0
  118. data/spec/singapore_cpf_calculator/year_2023/spr_2_fg/age_55_below_contribution_calculator_spec.rb +63 -0
  119. data/spec/singapore_cpf_calculator/year_2023/spr_2_fg/age_55_to_60_contribution_calculator_spec.rb +63 -0
  120. data/spec/singapore_cpf_calculator/year_2023/spr_2_fg/age_60_to_65_contribution_calculator_spec.rb +63 -0
  121. data/spec/singapore_cpf_calculator/year_2023/spr_2_fg/age_65_to_70_contribution_calculator_spec.rb +63 -0
  122. data/spec/singapore_cpf_calculator/year_2023/spr_2_fg/age_70_up_contribution_calculator_spec.rb +63 -0
  123. data/spec/singapore_cpf_calculator/year_2023/spr_2_fg_spec.rb +176 -0
  124. data/spec/singapore_cpf_calculator/year_2023/spr_2_gg_spec.rb +158 -0
  125. data/spec/singapore_cpf_calculator/year_2023_spec.rb +193 -0
  126. data/spec/singapore_cpf_calculator_spec.rb +58 -20
  127. data/spec/spec_helper.rb +6 -1
  128. metadata +148 -104
  129. data/.travis.yml +0 -15
@@ -0,0 +1,176 @@
1
+ require 'spec_helper'
2
+
3
+ describe SingaporeCPFCalculator::Year2023::SPR2FG do
4
+
5
+ subject(:mod) { described_class }
6
+
7
+ describe ".applies_to?" do
8
+ let(:current_date) { Date.new(2023, 7, 1) }
9
+ let(:spr_start_date) { nil }
10
+ let(:employee_contribution_type) { nil }
11
+ let(:employer_contribution_type) { nil }
12
+
13
+ let(:result) {
14
+ mod.applies_to? status: status,
15
+ current_date: current_date,
16
+ spr_start_date: spr_start_date,
17
+ employee_contribution_type: employee_contribution_type,
18
+ employer_contribution_type: employer_contribution_type
19
+ }
20
+
21
+ context "when the employee is a citizen" do
22
+ let(:status) { "citizen" }
23
+ it { expect( result ).to be_falsey }
24
+ end
25
+
26
+ context "when the employee is a permanent resident on their 3rd year" do
27
+ let(:status) { "permanent_resident" }
28
+ let(:spr_start_date) { Date.new(2021, 6, 20) }
29
+ it { expect( result ).to be_falsey }
30
+ end
31
+
32
+ context "when the employee is a permanent resident on their 2nd year" do
33
+ let(:status) { "permanent_resident" }
34
+ let(:spr_start_date) { Date.new(2022, 6, 20) }
35
+
36
+ context "for full employer and employee contribution type" do
37
+ let(:employee_contribution_type) { "full" }
38
+ let(:employer_contribution_type) { "full" }
39
+ it { expect( result ).to be_falsey }
40
+ end
41
+
42
+ context "for graduated employer and employee contribution type" do
43
+ let(:employee_contribution_type) { "graduated" }
44
+ let(:employer_contribution_type) { "graduated" }
45
+ it { expect( result ).to be_falsey }
46
+ end
47
+
48
+ context "for full employer and graduated employee contribution type" do
49
+ let(:employee_contribution_type) { "graduated" }
50
+ let(:employer_contribution_type) { "full" }
51
+ it { expect( result ).to be_truthy }
52
+ end
53
+ end
54
+
55
+ context "when the employee is a permanent resident on their 1st year" do
56
+ let(:status) { "permanent_resident" }
57
+ let(:spr_start_date) { Date.new(2023, 6, 20) }
58
+
59
+ context "for full employer and employee contribution type" do
60
+ let(:employee_contribution_type) { "full" }
61
+ let(:employer_contribution_type) { "full" }
62
+ it { expect( result ).to be_falsey }
63
+ end
64
+
65
+ context "for graduated employer and employee contribution type" do
66
+ let(:employee_contribution_type) { "graduated" }
67
+ let(:employer_contribution_type) { "graduated" }
68
+ it { expect( result ).to be_falsey }
69
+ end
70
+
71
+ context "for full employer and graduated employee contribution type" do
72
+ let(:employee_contribution_type) { "graduated" }
73
+ let(:employer_contribution_type) { "full" }
74
+ it { expect( result ).to be_falsey }
75
+ end
76
+ end
77
+
78
+ end
79
+
80
+ describe "calculator_for" do
81
+ let(:calculator) { mod.calculator_for(current_date, birthdate: birthdate) }
82
+ let(:current_date) { Date.new(2023, 9, 15) }
83
+
84
+ context "when the employee's age is 55 or below" do
85
+ context "lower limit" do
86
+ let(:birthdate) { Date.new(1999, 8, 15) }
87
+
88
+ it {
89
+ expect( calculator ).
90
+ to be SingaporeCPFCalculator::Year2023::SPR2FG::Age55BelowContributionCalculator
91
+ }
92
+ end
93
+
94
+ context "upper limit" do
95
+ let(:birthdate) { Date.new(1974, 9, 15) }
96
+ it {
97
+ expect( calculator ).
98
+ to be SingaporeCPFCalculator::Year2023::SPR2FG::Age55BelowContributionCalculator
99
+ }
100
+ end
101
+ end
102
+
103
+ context "when the employee's age is above 55 to 60" do
104
+ context "lower limit" do
105
+ let(:birthdate) { Date.new(1967, 8, 15) }
106
+ it {
107
+ expect( calculator ).
108
+ to be SingaporeCPFCalculator::Year2023::SPR2FG::Age55To60ContributionCalculator
109
+ }
110
+ end
111
+
112
+ context "upper limit" do
113
+ let(:birthdate) { Date.new(1963, 9, 15) }
114
+ it {
115
+ expect( calculator ).
116
+ to be SingaporeCPFCalculator::Year2023::SPR2FG::Age55To60ContributionCalculator
117
+ }
118
+ end
119
+ end
120
+
121
+ context "when the employee's age is above 60 to 65" do
122
+ context "lower limit" do
123
+ let(:birthdate) { Date.new(1962, 8, 15) }
124
+ it {
125
+ expect( calculator ).
126
+ to be SingaporeCPFCalculator::Year2023::SPR2FG::Age60To65ContributionCalculator
127
+ }
128
+ end
129
+
130
+ context "upper limit" do
131
+ let(:birthdate) { Date.new(1958, 9, 15) }
132
+ it {
133
+ expect( calculator ).
134
+ to be SingaporeCPFCalculator::Year2023::SPR2FG::Age60To65ContributionCalculator
135
+ }
136
+ end
137
+ end
138
+
139
+ context "when the employee's age is 65 to 70" do
140
+ context "lower limit" do
141
+ let(:birthdate) { Date.new(1957, 8, 15) }
142
+ it {
143
+ expect( calculator ).
144
+ to be SingaporeCPFCalculator::Year2023::SPR2FG::Age65To70ContributionCalculator
145
+ }
146
+ end
147
+
148
+ context "upper limit" do
149
+ let(:birthdate) { Date.new(1953, 9, 15) }
150
+ it {
151
+ expect( calculator ).
152
+ to be SingaporeCPFCalculator::Year2023::SPR2FG::Age65To70ContributionCalculator
153
+ }
154
+ end
155
+ end
156
+
157
+ context "when the employee's age is 70 and above" do
158
+ context "lower limit" do
159
+ let(:birthdate) { Date.new(1953, 8, 15) }
160
+ it {
161
+ expect( calculator ).
162
+ to be SingaporeCPFCalculator::Year2023::SPR2FG::Age70UpContributionCalculator
163
+ }
164
+ end
165
+
166
+ context "upper limit" do
167
+ let(:birthdate) { Date.new(1951, 9, 15) }
168
+ it {
169
+ expect( calculator ).
170
+ to be SingaporeCPFCalculator::Year2023::SPR2FG::Age70UpContributionCalculator
171
+ }
172
+ end
173
+ end
174
+ end
175
+
176
+ end
@@ -0,0 +1,158 @@
1
+ require 'spec_helper'
2
+
3
+ describe SingaporeCPFCalculator::Year2023::SPR2GG do
4
+
5
+ subject(:mod) { described_class }
6
+
7
+ describe ".applies_to?" do
8
+ let(:current_date) { Date.new(2023, 7, 1) }
9
+ let(:spr_start_date) { nil }
10
+ let(:employee_contribution_type) { nil }
11
+ let(:employer_contribution_type) { nil }
12
+
13
+ let(:result) {
14
+ mod.applies_to? status: status,
15
+ current_date: current_date,
16
+ spr_start_date: spr_start_date,
17
+ employee_contribution_type: employee_contribution_type,
18
+ employer_contribution_type: employer_contribution_type
19
+ }
20
+
21
+ context "when the employee is a citizen" do
22
+ let(:status) { "citizen" }
23
+ it { expect( result ).to be_falsey }
24
+ end
25
+
26
+ context "when the employee is a permanent resident on their 3rd year" do
27
+ let(:status) { "permanent_resident" }
28
+ let(:spr_start_date) { Date.new(2021, 6, 20) }
29
+ it { expect( result ).to be_falsey }
30
+ end
31
+
32
+ context "when the employee is a permanent resident on their 2nd year" do
33
+ let(:status) { "permanent_resident" }
34
+ let(:spr_start_date) { Date.new(2022, 6, 20) }
35
+
36
+ context "for full employer and employee contribution type" do
37
+ let(:employee_contribution_type) { "full" }
38
+ let(:employer_contribution_type) { "full" }
39
+ it { expect( result ).to be_falsey }
40
+ end
41
+
42
+ context "for graduated employer and employee contribution type" do
43
+ let(:employee_contribution_type) { "graduated" }
44
+ let(:employer_contribution_type) { "graduated" }
45
+ it { expect( result ).to be_truthy }
46
+ end
47
+
48
+ context "for full employer and graduated employee contribution type" do
49
+ let(:employee_contribution_type) { "graduated" }
50
+ let(:employer_contribution_type) { "full" }
51
+ it { expect( result ).to be_falsey }
52
+ end
53
+ end
54
+
55
+ context "when the employee is a permanent resident on their 1st year" do
56
+ let(:status) { "permanent_resident" }
57
+ let(:spr_start_date) { Date.new(2023, 6, 20) }
58
+
59
+ context "for full employer and employee contribution type" do
60
+ let(:employee_contribution_type) { "full" }
61
+ let(:employer_contribution_type) { "full" }
62
+ it { expect( result ).to be_falsey }
63
+ end
64
+
65
+ context "for graduated employer and employee contribution type" do
66
+ let(:employee_contribution_type) { "graduated" }
67
+ let(:employer_contribution_type) { "graduated" }
68
+ it { expect( result ).to be_falsey }
69
+ end
70
+
71
+ context "for full employer and graduated employee contribution type" do
72
+ let(:employee_contribution_type) { "graduated" }
73
+ let(:employer_contribution_type) { "full" }
74
+ it { expect( result ).to be_falsey }
75
+ end
76
+ end
77
+
78
+ end
79
+
80
+ describe "calculator_for" do
81
+ let(:calculator) { mod.calculator_for(current_date, birthdate: birthdate) }
82
+ let(:current_date) { Date.new(2023, 9, 15) }
83
+
84
+ context "when the employee's age is 55 or below" do
85
+ context "lower limit" do
86
+ let(:birthdate) { Date.new(1999, 8, 15) }
87
+
88
+ it {
89
+ expect( calculator ).
90
+ to be SingaporeCPFCalculator::Year2022::SPR2GG::Age55BelowContributionCalculator
91
+ }
92
+ end
93
+
94
+ context "upper limit" do
95
+ let(:birthdate) { Date.new(1968, 9, 15) }
96
+ it {
97
+ expect( calculator ).
98
+ to be SingaporeCPFCalculator::Year2022::SPR2GG::Age55BelowContributionCalculator
99
+ }
100
+ end
101
+ end
102
+
103
+ context "when the employee's age is above 55 to 60" do
104
+ context "lower limit" do
105
+ let(:birthdate) { Date.new(1967, 8, 15) }
106
+ it {
107
+ expect( calculator ).
108
+ to be SingaporeCPFCalculator::Year2022::SPR2GG::Age55To60ContributionCalculator
109
+ }
110
+ end
111
+
112
+ context "upper limit" do
113
+ let(:birthdate) { Date.new(1963, 9, 15) }
114
+ it {
115
+ expect( calculator ).
116
+ to be SingaporeCPFCalculator::Year2022::SPR2GG::Age55To60ContributionCalculator
117
+ }
118
+ end
119
+ end
120
+
121
+ context "when the employee's age is above 60 to 65" do
122
+ context "lower limit" do
123
+ let(:birthdate) { Date.new(1962, 8, 15) }
124
+ it {
125
+ expect( calculator ).
126
+ to be SingaporeCPFCalculator::Year2022::SPR2GG::Age60To65ContributionCalculator
127
+ }
128
+ end
129
+
130
+ context "upper limit" do
131
+ let(:birthdate) { Date.new(1958, 9, 15) }
132
+ it {
133
+ expect( calculator ).
134
+ to be SingaporeCPFCalculator::Year2022::SPR2GG::Age60To65ContributionCalculator
135
+ }
136
+ end
137
+ end
138
+
139
+ context "when the employee's age is 65 or above" do
140
+ context "lower limit" do
141
+ let(:birthdate) { Date.new(1957, 8, 15) }
142
+ it {
143
+ expect( calculator ).
144
+ to be SingaporeCPFCalculator::Year2022::SPR2GG::Age65UpContributionCalculator
145
+ }
146
+ end
147
+
148
+ context "upper limit" do
149
+ let(:birthdate) { Date.new(1917, 8, 15) }
150
+ it {
151
+ expect( calculator ).
152
+ to be SingaporeCPFCalculator::Year2022::SPR2GG::Age65UpContributionCalculator
153
+ }
154
+ end
155
+ end
156
+ end
157
+
158
+ end
@@ -0,0 +1,193 @@
1
+ require 'spec_helper'
2
+
3
+ describe SingaporeCPFCalculator::Year2023 do
4
+
5
+ subject(:year_module) { described_class }
6
+
7
+ describe ".applies_to?" do
8
+ context "when the date falls into the year 2014" do
9
+ let(:date) { Date.new(2014, 11, 15) }
10
+ it { expect( year_module.applies_to?(date) ).to be_falsey }
11
+ end
12
+
13
+ context "when the date falls into the year 2015" do
14
+ let(:date) { Date.new(2015, 1, 1) }
15
+ it { expect( year_module.applies_to?(date) ).to be_falsey }
16
+ end
17
+
18
+ context "when the date falls into the year 2016" do
19
+ let(:date) { Date.new(2016, 1, 1) }
20
+ it { expect( year_module.applies_to?(date) ).to be_falsey }
21
+ end
22
+
23
+ context "when the date falls into the year 2022" do
24
+ let(:date) { Date.new(2022, 1, 1) }
25
+ it { expect( year_module.applies_to?(date) ).to be_falsey }
26
+ end
27
+
28
+ context "when the date falls into the year 2023" do
29
+ let(:date) { Date.new(2023, 1, 1) }
30
+ it { expect( year_module.applies_to?(date) ).to be_truthy }
31
+ end
32
+ end
33
+
34
+ describe ".module_for_residency" do
35
+
36
+ let(:mod) {
37
+ year_module.module_for_residency status: status,
38
+ current_date: current_date,
39
+ spr_start_date: spr_start_date,
40
+ employee_contribution_type: employee_contribution_type,
41
+ employer_contribution_type: employer_contribution_type
42
+ }
43
+
44
+ let(:current_date) { Date.new(2023, 11, 15) }
45
+ let(:employee_contribution_type) { nil }
46
+ let(:employer_contribution_type) { nil }
47
+
48
+ context "when the employee is a citizen" do
49
+ let(:status) { "citizen" }
50
+ let(:spr_start_date) { nil }
51
+
52
+ it { expect(mod).to be SingaporeCPFCalculator::Year2023::CitizenOrSPR3 }
53
+ end
54
+
55
+ context "when the employee is a permanent resident" do
56
+ let(:status) { "permanent_resident" }
57
+
58
+ context "when the employee is in their year 1 of permanent residency" do
59
+ context "on the start of the SPR1" do
60
+ let(:spr_start_date) { Date.new(2023, 6, 20) }
61
+ let(:current_date) { Date.new(2023, 6, 20) }
62
+
63
+ context "when the employer pays partial contribution" do
64
+ let(:employer_contribution_type) { "graduated" }
65
+
66
+ context "when employee pays partial" do
67
+ let(:employee_contribution_type) { "graduated" }
68
+ it { expect(mod).to be SingaporeCPFCalculator::Year2023::SPR1GG }
69
+ end
70
+ end
71
+
72
+ context "when the employer pays full contribution" do
73
+ let(:employer_contribution_type) { "full" }
74
+
75
+ context "when employee pays partial" do
76
+ let(:employee_contribution_type) { "graduated" }
77
+ it { expect(mod).to be SingaporeCPFCalculator::Year2023::SPR1FG }
78
+ end
79
+
80
+ context "when employee pays full" do
81
+ let(:employee_contribution_type) { "full" }
82
+ it { expect(mod).to be SingaporeCPFCalculator::Year2023::CitizenOrSPR3 }
83
+ end
84
+ end
85
+ end
86
+
87
+ context "on the end of the SPR1" do
88
+ let(:spr_start_date) { Date.new(2022, 6, 20) }
89
+ let(:current_date) { Date.new(2023, 6, 30) }
90
+
91
+ context "when the employer pays partial contribution" do
92
+ let(:employer_contribution_type) { "graduated" }
93
+
94
+ context "when employee pays partial" do
95
+ let(:employee_contribution_type) { "graduated" }
96
+ it { expect(mod).to be SingaporeCPFCalculator::Year2023::SPR1GG }
97
+ end
98
+ end
99
+
100
+ context "when the employer pays full contribution" do
101
+ let(:employer_contribution_type) { "full" }
102
+
103
+ context "when employee pays partial" do
104
+ let(:employee_contribution_type) { "graduated" }
105
+ it { expect(mod).to be SingaporeCPFCalculator::Year2023::SPR1FG }
106
+ end
107
+
108
+ context "when employee pays full" do
109
+ let(:employee_contribution_type) { "full" }
110
+ it { expect(mod).to be SingaporeCPFCalculator::Year2023::CitizenOrSPR3 }
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ context "when the employee is in their year 2 of permanent residency" do
117
+ context "on the start of the SPR2" do
118
+ let(:spr_start_date) { Date.new(2022, 6, 20) }
119
+ let(:current_date) { Date.new(2023, 7, 1) }
120
+
121
+ context "when the employer pays partial contribution" do
122
+ let(:employer_contribution_type) { "graduated" }
123
+
124
+ context "when employee pays partial" do
125
+ let(:employee_contribution_type) { "graduated" }
126
+ it { expect(mod).to be SingaporeCPFCalculator::Year2023::SPR2GG }
127
+ end
128
+ end
129
+
130
+ context "when the employer pays full contribution" do
131
+ let(:employer_contribution_type) { "full" }
132
+
133
+ context "when employee pays partial" do
134
+ let(:employee_contribution_type) { "graduated" }
135
+ it { expect(mod).to be SingaporeCPFCalculator::Year2023::SPR2FG }
136
+ end
137
+
138
+ context "when employee pays full" do
139
+ let(:employee_contribution_type) { "full" }
140
+ it { expect(mod).to be SingaporeCPFCalculator::Year2023::CitizenOrSPR3 }
141
+ end
142
+ end
143
+ end
144
+
145
+ context "on the end of the SPR2" do
146
+ let(:spr_start_date) { Date.new(2021, 6, 20) }
147
+ let(:current_date) { Date.new(2023, 6, 30) }
148
+
149
+ context "when the employer pays partial contribution" do
150
+ let(:employer_contribution_type) { "graduated" }
151
+
152
+ context "when employee pays partial" do
153
+ let(:employee_contribution_type) { "graduated" }
154
+ it { expect(mod).to be SingaporeCPFCalculator::Year2023::SPR2GG }
155
+ end
156
+ end
157
+
158
+ context "when the employer pays full contribution" do
159
+ let(:employer_contribution_type) { "full" }
160
+
161
+ context "when employee pays partial" do
162
+ let(:employee_contribution_type) { "graduated" }
163
+ it { expect(mod).to be SingaporeCPFCalculator::Year2023::SPR2FG }
164
+ end
165
+
166
+ context "when employee pays full" do
167
+ let(:employee_contribution_type) { "full" }
168
+ it { expect(mod).to be SingaporeCPFCalculator::Year2023::CitizenOrSPR3 }
169
+ end
170
+ end
171
+ end
172
+ end
173
+
174
+ context "when the employee is in their year 3 of permanent residency" do
175
+ context "on the start of the SPR3" do
176
+ let(:spr_start_date) { Date.new(2021, 6, 20) }
177
+ let(:current_date) { Date.new(2023, 7, 1) }
178
+
179
+ it { expect(mod).to be SingaporeCPFCalculator::Year2023::CitizenOrSPR3 }
180
+ end
181
+
182
+ context "on SPR3 period" do
183
+ let(:spr_start_date) { Date.new(2019, 6, 20) }
184
+ let(:current_date) { Date.new(2023, 6, 30) }
185
+
186
+ it { expect(mod).to be SingaporeCPFCalculator::Year2023::CitizenOrSPR3 }
187
+ end
188
+ end
189
+
190
+ end
191
+
192
+ end
193
+ end
@@ -26,7 +26,6 @@ describe SingaporeCPFCalculator do
26
26
 
27
27
  describe "27 years old permanent resident from 2nd day of payroll" do
28
28
  let(:birthdate) { Date.new(1992, 5, 27) }
29
- let(:date) { Date.new(2019, 5, 31) }
30
29
  let(:residency_status) { "permanent_resident" }
31
30
  let(:spr_start_date) { Date.new(2019, 5, 2) }
32
31
  let(:ordinary_wages) { 1652.17 }
@@ -34,33 +33,72 @@ describe SingaporeCPFCalculator do
34
33
  let(:employee_contribution_type) { "graduated" }
35
34
  let(:employer_contribution_type) { "graduated" }
36
35
 
37
- it { expect(result).to equal_cpf total: 157.00, employee: 86.00, employer: 71.00, ow: 1652.17, aw: 87.69 }
36
+ context "for a date in 2019" do
37
+ let(:date) { Date.new(2019, 5, 31) }
38
38
 
39
- context "ordinary_wages is somehow higher" do
40
- let(:ordinary_wages) { 1734.78 }
41
- it { expect(result).to equal_cpf total: 164.00, employee: 91.00, employer: 71.00, ow: 1734.78, aw: 87.69 }
39
+ it { expect(result).to equal_cpf total: 157.00, employee: 86.00, employer: 71.00, ow: 1652.17, aw: 87.69 }
40
+
41
+ context "ordinary_wages is somehow higher" do
42
+ let(:ordinary_wages) { 1734.78 }
43
+ it { expect(result).to equal_cpf total: 164.00, employee: 91.00, employer: 73.00, ow: 1734.78, aw: 87.69 }
44
+
45
+ context "may first is not taken into account" do
46
+ let(:effective_portion) { 0.9565217391304348 }
47
+ let(:ordinary_wages) { 1734.78 * effective_portion }
48
+ let(:ow_value) { 1659.3547826086956 }
49
+ it { expect(result).to equal_cpf total: 157.00, employee: 87.00, employer: 70.00, ow: ow_value, aw: 87.69 }
50
+ end
51
+ end
52
+
53
+ describe "with year to date data" do
54
+ let(:ytd_ow_subject_to_cpf) { BigDecimal("1659.3548") }
55
+ let(:ytd_additional_wages) { BigDecimal("83.8774") }
56
+ let(:estimated_yearly_ow) { BigDecimal("22800.0") }
57
+ it { expect(result).to equal_cpf total: 157.00, employee: 86.00, employer: 71.00, ow: 1652.17, aw: 87.69 }
42
58
 
43
- context "may first is not taken into account" do
44
- let(:effective_portion) { 0.9565217391304348 }
45
- let(:ordinary_wages) { 1734.78 * effective_portion }
46
- it { expect(result).to equal_cpf total: 157.00, employee: 87.00, employer: 70.00, ow: 1659.3547826086956, aw: 87.69 }
59
+ context "if it had received his PR few days before" do
60
+ let(:spr_start_date) { Date.new(2019, 4, 25) }
61
+ it { expect(result).to equal_cpf total: 157.00, employee: 86.00, employer: 71.00, ow: 1652.17, aw: 87.69 }
62
+ end
63
+
64
+ context "if it had received his PR few days after" do
65
+ let(:spr_start_date) { Date.new(2019, 5, 9) }
66
+ it { expect(result).to equal_cpf total: 157.00, employee: 86.00, employer: 71.00, ow: 1652.17, aw: 87.69 }
67
+ end
47
68
  end
48
69
  end
49
70
 
50
- describe "with year to date data" do
51
- let(:ytd_ow_subject_to_cpf) { BigDecimal("1659.3548") }
52
- let(:ytd_additional_wages) { BigDecimal("83.8774") }
53
- let(:estimated_yearly_ow) { BigDecimal("22800.0") }
54
- it { expect(result).to equal_cpf total: 157.00, employee: 86.00, employer: 71.00, ow: 1652.17, aw: 87.69 }
71
+ context "for a date in 2022" do
72
+ let(:date) { Date.new(2022, 5, 31) }
55
73
 
56
- context "if it had received his PR few days before" do
57
- let(:spr_start_date) { Date.new(2019, 4, 25) }
58
- it { expect(result).to equal_cpf total: 157.00, employee: 86.00, employer: 71.00, ow: 1652.17, aw: 87.69 }
74
+ it { expect(result).to equal_cpf total: 644.00, employee: 347.00, ow: 1652.17, aw: 87.69 }
75
+
76
+ context "ordinary_wages is somehow higher" do
77
+ let(:ordinary_wages) { 1734.78 }
78
+ it { expect(result).to equal_cpf total: 674.00, employee: 364.00, ow: 1734.78, aw: 87.69 }
79
+
80
+ context "may first is not taken into account" do
81
+ let(:effective_portion) { 0.9565217391304348 }
82
+ let(:ordinary_wages) { 1734.78 * effective_portion }
83
+ it { expect(result).to equal_cpf total: 646.00, employee: 349.00, ow: 1659.3547826086956, aw: 87.69 }
84
+ end
59
85
  end
60
86
 
61
- context "if it had received his PR few days after" do
62
- let(:spr_start_date) { Date.new(2019, 5, 9) }
63
- it { expect(result).to equal_cpf total: 157.00, employee: 86.00, employer: 71.00, ow: 1652.17, aw: 87.69 }
87
+ describe "with year to date data" do
88
+ let(:ytd_ow_subject_to_cpf) { BigDecimal("1659.3548") }
89
+ let(:ytd_additional_wages) { BigDecimal("83.8774") }
90
+ let(:estimated_yearly_ow) { BigDecimal("22800.0") }
91
+ it { expect(result).to equal_cpf total: 644.00, employee: 347.00, ow: 1652.17, aw: 87.69 }
92
+
93
+ context "if it had received his PR few days before" do
94
+ let(:spr_start_date) { Date.new(2019, 4, 25) }
95
+ it { expect(result).to equal_cpf total: 644.00, employee: 347.00, ow: 1652.17, aw: 87.69 }
96
+ end
97
+
98
+ context "if it had received his PR few days after" do
99
+ let(:spr_start_date) { Date.new(2019, 5, 9) }
100
+ it { expect(result).to equal_cpf total: 644.00, employee: 347.00, ow: 1652.17, aw: 87.69 }
101
+ end
64
102
  end
65
103
  end
66
104
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  require "csv"
2
+ require 'simplecov'
3
+ SimpleCov.minimum_coverage 99.94 unless RUBY_ENGINE == 'jruby'
4
+ SimpleCov.start
2
5
  require "singapore_cpf_calculator"
3
6
 
4
7
  # This file was generated by the `rspec --init` command. Conventionally, all
@@ -108,9 +111,11 @@ RSpec::Matchers.define :equal_cpf do |expected|
108
111
  def is_cpf_equal?(actual)
109
112
  total = expected.fetch(:total)
110
113
  employee = expected.fetch(:employee)
114
+ employer = expected.fetch(:employer, nil)
111
115
  ow = expected.fetch(:ow, nil)
112
116
  aw = expected.fetch(:aw, nil)
113
- total == actual.total && employee = actual.employee &&
117
+ total == actual.total && employee == actual.employee &&
118
+ actual.employer == (employer.present? ? employer : total - employee ) &&
114
119
  (!ow.present? || ow == actual.ow_subject_to_cpf) &&
115
120
  (!aw.present? || aw == actual.aw_subject_to_cpf)
116
121
  end