-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathactivities_helper_spec.rb
More file actions
1011 lines (820 loc) · 41.9 KB
/
Copy pathactivities_helper_spec.rb
File metadata and controls
1011 lines (820 loc) · 41.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
require "rails_helper"
RSpec.describe ActivitiesHelper do
include ActiveSupport::Testing::TimeHelpers
describe "#education_add_path" do
context "when NSC is not disabled" do
it "returns verify_activities_flow_education_index_path" do
expect(helper.education_add_path).to eq(verify_activities_flow_education_index_path)
end
end
context "when NSC is disabled" do
it "returns new_activities_flow_education_path" do
stub_environment_variable("NSC_DISABLED", "true") do
expect(helper.education_add_path).to eq(new_activities_flow_education_path)
end
end
end
end
describe "#show_activity?" do
context "in a pre-populated session" do
before do
flow = instance_double(ActivityFlow, pre_populated_session?: true, pre_populated_activity_types: [ :community_service, :education ])
assign(:flow, flow)
end
it "shows only the pre-filled activity types" do
expect(helper.show_activity?(:community_service)).to be true
expect(helper.show_activity?(:education)).to be true
end
it "hides activity types that were not pre-filled" do
expect(helper.show_activity?(:employment)).to be false
expect(helper.show_activity?(:work_programs)).to be false
end
end
context "in a non-pre-populated session" do
before do
assign(:flow, instance_double(ActivityFlow, pre_populated_session?: false))
end
it "falls back to activity_type_enabled?" do
allow(helper).to receive(:activity_type_enabled?).with(:employment).and_return(true)
allow(helper).to receive(:activity_type_enabled?).with(:education).and_return(false)
expect(helper.show_activity?(:employment)).to be true
expect(helper.show_activity?(:education)).to be false
end
end
end
describe "activity hub display helpers" do
describe "#activity_hub_state" do
let(:meeting_result) { instance_double(ActivityFlowProgressCalculator::MonthlyResult, meets_requirements: true) }
let(:not_meeting_result) { instance_double(ActivityFlowProgressCalculator::MonthlyResult, meets_requirements: false) }
it "returns empty when no activities are added" do
state = helper.activity_hub_state(
any_activities_added: false,
monthly_results: [ meeting_result ]
)
expect(state).to eq(:empty)
end
it "returns completed when all months meet requirements" do
state = helper.activity_hub_state(
any_activities_added: true,
monthly_results: [ meeting_result, meeting_result ]
)
expect(state).to eq(:completed)
end
it "returns in_progress when any month does not meet requirements" do
state = helper.activity_hub_state(
any_activities_added: true,
monthly_results: [ meeting_result, not_meeting_result ]
)
expect(state).to eq(:in_progress)
end
it "returns completed when complete months meet the required-month threshold" do
state = helper.activity_hub_state(
any_activities_added: true,
monthly_results: [ meeting_result, meeting_result, not_meeting_result ],
required_month_count: 2
)
expect(state).to eq(:completed)
end
end
describe "#activity_hub_title_key" do
it "maps empty state to empty-state title key" do
expect(helper.activity_hub_title_key(:empty)).to eq("activities.hub.empty_state_title")
end
it "maps completed state to completed-state title key" do
expect(helper.activity_hub_title_key(:completed)).to eq("activities.hub.completed_state_title")
end
it "maps in-progress state to in-progress title key" do
expect(helper.activity_hub_title_key(:in_progress)).to eq("activities.hub.in_progress_state_title")
end
end
describe "#activity_hub_description_key" do
it "maps completed state to completed-state description key" do
expect(helper.activity_hub_description_key(:completed)).to eq("activities.hub.completed_state_description")
end
it "maps in-progress state to in-progress description key" do
expect(helper.activity_hub_description_key(:in_progress)).to eq("activities.hub.in_progress_state_description")
end
it "maps empty state to in-progress description key" do
expect(helper.activity_hub_description_key(:empty)).to eq("activities.hub.in_progress_state_description")
end
end
end
describe "#community_service_cards" do
let(:flow) { create(:activity_flow, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0) }
let(:first_month) { flow.reporting_window_range.begin.beginning_of_month }
context "with community service activities" do
it "returns one card per activity" do
activity_1 = create(:volunteering_activity, activity_flow: flow, organization_name: "Food Pantry")
activity_2 = create(:volunteering_activity, activity_flow: flow, organization_name: "Food Pantry")
create(:volunteering_activity_month, volunteering_activity: activity_1, month: first_month, hours: 5)
create(:volunteering_activity_month, volunteering_activity: activity_2, month: first_month + 1.month, hours: 10)
result = helper.community_service_cards(flow.volunteering_activities)
expect(result.length).to eq(2)
expect(result.map { |c| c[:name] }).to all(eq("Food Pantry"))
end
it "includes the activity's name and hours" do
activity = create(:volunteering_activity, activity_flow: flow, organization_name: "Food Pantry")
create(:volunteering_activity_month, volunteering_activity: activity, month: first_month, hours: 5)
result = helper.community_service_cards(flow.volunteering_activities)
expect(result.first[:name]).to eq("Food Pantry")
expect(result.first[:months].first[:hours]).to eq(5)
expect(result.first[:months].first[:month]).to eq(first_month)
end
it "filters out months with no hours" do
activity = create(:volunteering_activity, activity_flow: flow, organization_name: "Food Pantry")
create(:volunteering_activity_month, volunteering_activity: activity, month: first_month, hours: 0)
create(:volunteering_activity_month, volunteering_activity: activity, month: first_month + 1.month, hours: 5)
result = helper.community_service_cards(flow.volunteering_activities)
expect(result.first[:months]).to eq([
{ month: first_month + 1.month, hours: 5 }
])
end
it "includes edit path to community service review with from_edit" do
activity = create(:volunteering_activity, activity_flow: flow, organization_name: "Food Pantry")
create(:volunteering_activity_month, volunteering_activity: activity, month: first_month, hours: 5)
result = helper.community_service_cards(flow.volunteering_activities)
expect(result.first[:edit_path]).to eq(
helper.review_activities_flow_community_service_path(id: activity.id, from_edit: 1)
)
end
it "returns empty array for empty input" do
result = helper.community_service_cards([])
expect(result).to eq([])
end
it "returns empty months for activities with no monthly entries" do
create(:volunteering_activity, activity_flow: flow, organization_name: "Food Pantry")
result = helper.community_service_cards(flow.volunteering_activities.reload)
expect(result.first[:months]).to be_empty
end
end
end
describe "#employment_activity_draft_cards" do
let(:flow) { create(:activity_flow, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0) }
it "returns a card with pre_populated: true and edit path pointing to employment edit page" do
activity = create(:employment_activity, :pre_populated_draft, activity_flow: flow, employer_name: "Acme Corp")
result = helper.employment_activity_draft_cards([ activity ])
expect(result.length).to eq(1)
expect(result.first).to include(
name: "Acme Corp",
months: [],
pre_populated: true
)
expect(result.first[:edit_path]).to eq(
helper.edit_activities_flow_income_employment_path(id: activity.id)
)
end
it "returns empty array for empty input" do
expect(helper.employment_activity_draft_cards([])).to eq([])
end
it "includes month data when employment_activity_months have hours or gross_income" do
activity = create(:employment_activity, :pre_populated_draft, activity_flow: flow, employer_name: "Acme Corp")
first_month = flow.reporting_months.first.beginning_of_month
create(:employment_activity_month, employment_activity: activity, month: first_month, hours: 20, gross_income: 500)
result = helper.employment_activity_draft_cards([ activity ])
expect(result.first[:months]).to eq([
{ month: first_month, gross_earnings: 50_000, hours: 20 }
])
end
it "excludes months where both hours and gross_income are zero" do
activity = create(:employment_activity, :pre_populated_draft, activity_flow: flow, employer_name: "Acme Corp")
first_month = flow.reporting_months.first.beginning_of_month
create(:employment_activity_month, employment_activity: activity, month: first_month, hours: 0, gross_income: 0)
result = helper.employment_activity_draft_cards([ activity ])
expect(result.first[:months]).to be_empty
end
end
describe "#education_activity_draft_cards" do
let(:flow) { create(:activity_flow, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0) }
let(:first_month) { flow.reporting_months.first.beginning_of_month }
it "returns a card with pre_populated: true and edit path pointing to education edit page" do
activity = create(:education_activity, :pre_populated_draft, activity_flow: flow, school_name: "Springfield Community College")
result = helper.education_activity_draft_cards([ activity ])
expect(result.length).to eq(1)
expect(result.first).to include(
name: "Springfield Community College",
months: [],
pre_populated: true
)
expect(result.first[:edit_path]).to eq(
helper.edit_activities_flow_education_path(id: activity.id)
)
end
it "includes month data when education_activity_months have hours" do
activity = create(:education_activity, :pre_populated_draft, activity_flow: flow, school_name: "Springfield Community College")
create(:education_activity_month, education_activity: activity, month: first_month, hours: 6)
result = helper.education_activity_draft_cards([ activity ])
expect(result.first[:months]).to eq([
{ month: first_month, credit_hours: 6, community_engagement_hours: 78 }
])
end
it "excludes months where hours are zero" do
activity = create(:education_activity, :pre_populated_draft, activity_flow: flow, school_name: "Springfield Community College")
create(:education_activity_month, education_activity: activity, month: first_month, hours: 0)
result = helper.education_activity_draft_cards([ activity ])
expect(result.first[:months]).to be_empty
end
end
describe "#community_service_draft_cards" do
let(:flow) { create(:activity_flow, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0) }
let(:first_month) { flow.reporting_window_range.begin.beginning_of_month }
it "filters out months with no hours" do
activity = create(:volunteering_activity, :pre_populated_draft, activity_flow: flow, organization_name: "Food Pantry")
create(:volunteering_activity_month, volunteering_activity: activity, month: first_month, hours: 0)
create(:volunteering_activity_month, volunteering_activity: activity, month: first_month + 1.month, hours: 5)
result = helper.community_service_draft_cards([ activity ])
expect(result.first).to include(
name: "Food Pantry",
months: [ { month: first_month + 1.month, hours: 5 } ],
edit_path: helper.edit_activities_flow_community_service_path(id: activity.id),
pre_populated: true
)
end
end
describe "#work_program_cards" do
let(:flow) { create(:activity_flow, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0) }
let(:first_month) { flow.reporting_months.first.beginning_of_month }
it "uses program_name as card name" do
activity = create(:job_training_activity, activity_flow: flow, program_name: "Career Prep", organization_address: "123 Main")
create(:job_training_activity_month, job_training_activity: activity, month: first_month, hours: 5)
result = helper.work_program_cards(flow.job_training_activities)
expect(result.first[:name]).to eq("Career Prep")
expect(result.first[:months].first[:hours]).to eq(5)
expect(result.first[:months].first[:month]).to eq(first_month)
end
it "filters out months with no hours" do
activity = create(:job_training_activity, activity_flow: flow, program_name: "Career Prep", organization_address: "123 Main")
create(:job_training_activity_month, job_training_activity: activity, month: first_month, hours: 0)
create(:job_training_activity_month, job_training_activity: activity, month: first_month + 1.month, hours: 8)
result = helper.work_program_cards(flow.job_training_activities)
expect(result.first[:months]).to eq([
{ month: first_month + 1.month, hours: 8 }
])
end
it "returns one card per activity even with same program name" do
activity_1 = create(:job_training_activity, activity_flow: flow, program_name: "Career Prep", organization_address: "123 Main")
activity_2 = create(:job_training_activity, activity_flow: flow, program_name: "Career Prep", organization_address: "123 Main")
create(:job_training_activity_month, job_training_activity: activity_1, month: first_month, hours: 5)
create(:job_training_activity_month, job_training_activity: activity_2, month: first_month + 1.month, hours: 8)
result = helper.work_program_cards(flow.job_training_activities)
expect(result.length).to eq(2)
end
it "includes edit path to job training review with from_edit" do
activity = create(:job_training_activity, activity_flow: flow, program_name: "Career Prep", organization_address: "123 Main")
create(:job_training_activity_month, job_training_activity: activity, month: first_month, hours: 5)
result = helper.work_program_cards(flow.job_training_activities)
expect(result.first[:edit_path]).to eq(
helper.review_activities_flow_job_training_path(id: activity.id, from_edit: 1)
)
end
end
describe "#work_program_draft_cards" do
let(:flow) { create(:activity_flow, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0) }
let(:first_month) { flow.reporting_months.first.beginning_of_month }
it "returns a card with pre_populated: true and edit path pointing to job training edit page" do
activity = create(:job_training_activity, :pre_populated_draft, activity_flow: flow, program_name: "Career Prep")
result = helper.work_program_draft_cards([ activity ])
expect(result.length).to eq(1)
expect(result.first).to include(
name: "Career Prep",
months: [],
pre_populated: true
)
expect(result.first[:edit_path]).to eq(
helper.edit_activities_flow_job_training_path(id: activity.id)
)
end
it "includes month data when job_training_activity_months have hours" do
activity = create(:job_training_activity, :pre_populated_draft, activity_flow: flow, program_name: "Career Prep")
create(:job_training_activity_month, job_training_activity: activity, month: first_month, hours: 10)
result = helper.work_program_draft_cards([ activity ])
expect(result.first[:months]).to eq([
{ month: first_month, hours: 10 }
])
end
it "excludes months where hours are zero" do
activity = create(:job_training_activity, :pre_populated_draft, activity_flow: flow, program_name: "Career Prep")
create(:job_training_activity_month, job_training_activity: activity, month: first_month, hours: 0)
result = helper.work_program_draft_cards([ activity ])
expect(result.first[:months]).to be_empty
end
end
describe "#education_cards" do
around { |example| travel_to(Date.new(2025, 11, 15)) { example.run } }
let(:flow) { create(:activity_flow, reporting_window_months: 2, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0) }
let(:first_month) { flow.reporting_window_range.begin }
let(:second_month) { first_month + 1.month }
let(:reporting_months) { [ first_month, second_month ] }
it "uses school name from enrollment term as card title" do
activity = create(:education_activity, activity_flow: flow)
create(:nsc_enrollment_term, education_activity: activity, school_name: "STATE UNIVERSITY", term_begin: first_month, term_end: second_month.end_of_month)
result = helper.education_cards([ activity.reload ], reporting_months)
expect(result.first[:name]).to eq("State University")
end
it "returns empty array when activity has no enrollment terms" do
activity = create(:education_activity, activity_flow: flow)
result = helper.education_cards([ activity ], reporting_months)
expect(result).to eq([])
end
it "shows enrollment status for months with overlapping terms" do
activity = create(:education_activity, activity_flow: flow)
create(:nsc_enrollment_term, education_activity: activity, school_name: "Test U", enrollment_status: "full_time", term_begin: first_month, term_end: second_month.end_of_month)
result = helper.education_cards([ activity.reload ], reporting_months)
expect(result.first[:months]).to eq([
{
month: first_month,
enrollment_status: I18n.t("components.enrollment_term_table_component.status.full_time")
},
{
month: second_month,
enrollment_status: I18n.t("components.enrollment_term_table_component.status.full_time")
}
])
end
it "does not include months without overlapping terms" do
activity = create(:education_activity, activity_flow: flow)
create(:nsc_enrollment_term, education_activity: activity, school_name: "Test U", enrollment_status: "half_time", term_begin: first_month, term_end: first_month.end_of_month)
result = helper.education_cards([ activity.reload ], reporting_months)
expect(result.first[:months]).to eq([
{
month: first_month,
enrollment_status: I18n.t("components.enrollment_term_table_component.status.half_time")
}
])
end
it "does not build a card for a term with no reporting-window overlap" do
activity = create(:education_activity, activity_flow: flow)
create(:nsc_enrollment_term,
education_activity: activity,
school_name: "Spring Only U",
enrollment_status: "half_time",
term_begin: first_month - 4.months,
term_end: first_month - 2.months)
create(:nsc_enrollment_term,
education_activity: activity,
school_name: "Summer U",
enrollment_status: "less_than_half_time",
term_begin: first_month,
term_end: second_month.end_of_month)
result = helper.education_cards([ activity.reload ], reporting_months)
expect(result.map { |card| card[:name] }).to eq([ "Summer U" ])
end
it "returns months in chronological order" do
activity = create(:education_activity, activity_flow: flow)
create(:nsc_enrollment_term, education_activity: activity, school_name: "Test U", term_begin: first_month, term_end: second_month.end_of_month)
result = helper.education_cards([ activity.reload ], reporting_months)
months = result.first[:months].map { |m| m[:month] }
expect(months).to eq(months.sort)
end
it "includes edit path to education review with from_edit for validated education" do
activity = create(:education_activity, activity_flow: flow)
create(:nsc_enrollment_term, education_activity: activity, school_name: "Test U", term_begin: first_month, term_end: second_month.end_of_month)
result = helper.education_cards([ activity.reload ], reporting_months)
expect(result.first[:edit_path]).to eq(
helper.review_activities_flow_education_path(id: activity.id, from_edit: 1)
)
end
it "includes edit path to education review for partially self-attested education" do
activity = create(:education_activity, activity_flow: flow, data_source: :partially_self_attested)
create(:nsc_enrollment_term, education_activity: activity, school_name: "Test U", enrollment_status: "less_than_half_time", term_begin: first_month, term_end: second_month.end_of_month)
result = helper.education_cards([ activity.reload ], reporting_months)
expect(result.first[:edit_path]).to eq(
helper.review_activities_flow_education_path(id: activity.id, from_edit: 1)
)
end
it "builds one partially self-attested card per school when a school has multiple terms" do
activity = create(:education_activity, activity_flow: flow, data_source: :partially_self_attested)
create(:nsc_enrollment_term, :less_than_half_time,
education_activity: activity,
school_name: "River College",
term_begin: first_month,
term_end: first_month.end_of_month,
credit_hours: 3)
create(:nsc_enrollment_term, :less_than_half_time,
education_activity: activity,
school_name: "River College",
term_begin: second_month,
term_end: second_month.end_of_month,
credit_hours: 5)
result = helper.education_cards([ activity.reload ], reporting_months)
expect(result.length).to eq(1)
expect(result.first[:name]).to eq("River College")
expect(result.first[:edit_path]).to eq(
helper.review_activities_flow_education_path(id: activity.id, from_edit: 1)
)
expect(result.first[:months]).to eq([
{
month: first_month,
enrollment_status: I18n.t("components.enrollment_term_table_component.status.less_than_half_time")
},
{
month: second_month,
enrollment_status: I18n.t("components.enrollment_term_table_component.status.less_than_half_time")
}
])
end
it "shows enrollment status only for partially self-attested months" do
activity = create(:education_activity, activity_flow: flow, data_source: :partially_self_attested)
create(
:nsc_enrollment_term,
education_activity: activity,
school_name: "Test U",
enrollment_status: "less_than_half_time",
term_begin: first_month,
term_end: second_month.end_of_month,
credit_hours: 6
)
result = helper.education_cards([ activity.reload ], reporting_months)
expect(result.first[:months]).to eq([
{
month: first_month,
enrollment_status: I18n.t("components.enrollment_term_table_component.status.less_than_half_time")
},
{
month: second_month,
enrollment_status: I18n.t("components.enrollment_term_table_component.status.less_than_half_time")
}
])
end
it "only includes overlapping months for partially self-attested terms" do
activity = create(:education_activity, activity_flow: flow, data_source: :partially_self_attested)
create(
:nsc_enrollment_term,
:less_than_half_time,
education_activity: activity,
school_name: "Test U",
term_begin: first_month,
term_end: first_month.end_of_month,
credit_hours: 4
)
result = helper.education_cards([ activity.reload ], reporting_months)
expect(result.first[:months].map { |m| m[:month] }).to eq([ first_month ])
expect(result.first[:months].first).to eq(
{
month: first_month,
enrollment_status: I18n.t("components.enrollment_term_table_component.status.less_than_half_time")
}
)
end
it "filters out partially self-attested education months with no credit hours" do
activity = create(:education_activity, activity_flow: flow, data_source: :partially_self_attested)
create(
:nsc_enrollment_term,
:less_than_half_time,
education_activity: activity,
school_name: "Test U",
term_begin: first_month,
term_end: first_month.end_of_month,
credit_hours: 0
)
create(
:nsc_enrollment_term,
:less_than_half_time,
education_activity: activity,
school_name: "Test U",
term_begin: second_month,
term_end: second_month.end_of_month,
credit_hours: 5
)
result = helper.education_cards([ activity.reload ], reporting_months)
expect(result.first[:months]).to eq([
{
month: second_month,
enrollment_status: I18n.t("components.enrollment_term_table_component.status.less_than_half_time")
}
])
end
it "shows enrollment status only for enrolled partially self-attested months" do
activity = create(:education_activity, activity_flow: flow, data_source: :partially_self_attested)
create(
:nsc_enrollment_term,
education_activity: activity,
school_name: "Test U",
enrollment_status: "enrolled",
term_begin: first_month,
term_end: second_month.end_of_month,
credit_hours: 5
)
result = helper.education_cards([ activity.reload ], reporting_months)
expect(result.first[:months]).to eq([
{
month: first_month,
enrollment_status: I18n.t("components.enrollment_term_table_component.status.enrolled")
},
{
month: second_month,
enrollment_status: I18n.t("components.enrollment_term_table_component.status.enrolled")
}
])
end
it "builds a fully self-attested card from activity months" do
activity = create(
:education_activity,
activity_flow: flow,
data_source: :fully_self_attested,
school_name: "Updated University of Illinois"
)
create(:education_activity_month, education_activity: activity, month: first_month.beginning_of_month, hours: 4)
create(:education_activity_month, education_activity: activity, month: second_month.beginning_of_month, hours: 6)
result = helper.education_cards([ activity.reload ], reporting_months)
expect(result).to contain_exactly(
{
name: "Updated University of Illinois",
months: [
{ month: first_month, credit_hours: 4, community_engagement_hours: 52 },
{ month: second_month, credit_hours: 6, community_engagement_hours: 78 }
],
edit_path: helper.review_activities_flow_education_path(id: activity.id, from_edit: 1)
}
)
end
it "filters out fully self-attested education months with no credit hours" do
activity = create(
:education_activity,
activity_flow: flow,
data_source: :fully_self_attested,
school_name: "Updated University of Illinois"
)
create(:education_activity_month, education_activity: activity, month: first_month.beginning_of_month, hours: 0)
create(:education_activity_month, education_activity: activity, month: second_month.beginning_of_month, hours: 6)
result = helper.education_cards([ activity.reload ], reporting_months)
expect(result.first[:months]).to eq([
{ month: second_month, credit_hours: 6, community_engagement_hours: 78 }
])
end
it "shows the spring enrollment status on the summer card when carryover applies" do
summer_flow = create(:activity_flow, reporting_window_months: 2, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0)
summer_flow.shift_reporting_window_start!("2025-07-01")
summer_months = summer_flow.reporting_months
activity = create(:education_activity, activity_flow: summer_flow, status: "succeeded")
create(:nsc_enrollment_term,
education_activity: activity,
school_name: "Coastal State College",
enrollment_status: "half_time",
term_begin: Date.new(2025, 3, 1),
term_end: Date.new(2025, 6, 15))
create(:nsc_enrollment_term,
education_activity: activity,
school_name: "Coastal State College",
enrollment_status: "less_than_half_time",
term_begin: Date.new(2025, 7, 1),
term_end: Date.new(2025, 8, 15))
result = helper.education_cards([ activity.reload ], summer_months)
expect(result.length).to eq(1)
expect(result.first[:months]).to eq([
{
month: Date.new(2025, 7, 1),
enrollment_status: I18n.t("components.enrollment_term_table_component.status.half_time")
},
{
month: Date.new(2025, 8, 1),
enrollment_status: I18n.t("components.enrollment_term_table_component.status.half_time")
}
])
end
it "shows the spring enrollment status on the summer card when no summer term exists" do
summer_flow = create(:activity_flow, reporting_window_months: 2, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0)
summer_flow.shift_reporting_window_start!("2025-07-01")
summer_months = summer_flow.reporting_months
activity = create(:education_activity, activity_flow: summer_flow, status: "succeeded")
create(:nsc_enrollment_term,
education_activity: activity,
school_name: "Coastal State College",
enrollment_status: "half_time",
term_begin: Date.new(2025, 3, 1),
term_end: Date.new(2025, 6, 15))
result = helper.education_cards([ activity.reload ], summer_months)
expect(result.length).to eq(1)
expect(result.first[:months]).to eq([
{
month: Date.new(2025, 7, 1),
enrollment_status: I18n.t("components.enrollment_term_table_component.status.half_time")
},
{
month: Date.new(2025, 8, 1),
enrollment_status: I18n.t("components.enrollment_term_table_component.status.half_time")
}
])
end
it "shows spring carryover on partially self-attested cards in a long reporting window" do
long_flow = create(:activity_flow, reporting_window_months: 12, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0)
long_flow.shift_reporting_window_start!("2025-01-01")
long_reporting_months = long_flow.reporting_months
activity = create(
:education_activity,
activity_flow: long_flow,
data_source: :partially_self_attested,
status: "succeeded"
)
create(:nsc_enrollment_term,
education_activity: activity,
school_name: "Coastal State College",
enrollment_status: "half_time",
term_begin: Date.new(2025, 3, 1),
term_end: Date.new(2025, 6, 15))
create(:nsc_enrollment_term,
:less_than_half_time,
education_activity: activity,
school_name: "Coastal State College",
term_begin: Date.new(2025, 7, 1),
term_end: Date.new(2025, 8, 15),
credit_hours: 0)
result = helper.education_cards([ activity.reload ], long_reporting_months)
half_time_status = I18n.t("components.enrollment_term_table_component.status.half_time")
expect(result.first[:months]).to include(
{
month: Date.new(2025, 7, 1),
enrollment_status: half_time_status
},
{
month: Date.new(2025, 8, 1),
enrollment_status: half_time_status
}
)
end
it "shows spring carryover months on partially self-attested cards when only spring and fall terms exist" do
spring_fall_flow = create(:activity_flow, reporting_window_months: 4, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0)
spring_fall_flow.shift_reporting_window_start!("2025-06-01")
spring_fall_reporting_months = spring_fall_flow.reporting_months
activity = create(
:education_activity,
activity_flow: spring_fall_flow,
data_source: :partially_self_attested,
status: "succeeded"
)
create(:nsc_enrollment_term,
education_activity: activity,
school_name: "Coastal State College",
enrollment_status: "half_time",
term_begin: Date.new(2025, 3, 1),
term_end: Date.new(2025, 6, 15))
create(:nsc_enrollment_term,
education_activity: activity,
school_name: "Coastal State College",
enrollment_status: "half_time",
term_begin: Date.new(2025, 9, 1),
term_end: Date.new(2025, 12, 15))
result = helper.education_cards([ activity.reload ], spring_fall_reporting_months)
half_time_status = I18n.t("components.enrollment_term_table_component.status.half_time")
expected_months = [
Date.new(2025, 6, 1),
Date.new(2025, 7, 1),
Date.new(2025, 8, 1),
Date.new(2025, 9, 1)
]
expect(result.first[:months]).to match_array(
expected_months.map { |month| { month: month, enrollment_status: half_time_status } }
)
end
it "builds one validated card when two terms overlap the same reporting month" do
june_flow = create(:activity_flow, reporting_window_months: 2, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0)
june_flow.shift_reporting_window_start!("2025-06-01")
june_months = june_flow.reporting_months
activity = create(:education_activity, activity_flow: june_flow, status: "succeeded")
create(:nsc_enrollment_term,
education_activity: activity,
school_name: "Test University",
enrollment_status: "half_time",
term_begin: Date.new(2025, 3, 1),
term_end: Date.new(2025, 6, 15))
create(:nsc_enrollment_term,
education_activity: activity,
school_name: "Test University",
enrollment_status: "less_than_half_time",
term_begin: Date.new(2025, 6, 1),
term_end: Date.new(2025, 7, 31))
result = helper.education_cards([ activity.reload ], june_months)
expect(result.length).to eq(1)
june_data = result.first[:months].find { |month| month[:month] == Date.new(2025, 6, 1) }
july_data = result.first[:months].find { |month| month[:month] == Date.new(2025, 7, 1) }
expect(june_data[:enrollment_status]).to eq(I18n.t("components.enrollment_term_table_component.status.half_time"))
expect(june_data).not_to have_key(:community_engagement_hours)
expect(july_data[:enrollment_status]).to eq(I18n.t("components.enrollment_term_table_component.status.half_time"))
expect(july_data).not_to have_key(:community_engagement_hours)
end
end
describe "#employment_cards" do
let(:flow) { create(:activity_flow, reporting_window_months: 1, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0) }
let(:reporting_range) { flow.reporting_window_range }
let(:first_month) { reporting_range.begin }
let(:month_key) { first_month.strftime("%Y-%m") }
let(:account_id) { "test-account-123" }
let(:mock_employment) { double(employer_name: "ACME Corp") }
let(:mock_account_report) { double(employment: mock_employment) }
let(:mock_report) do
instance_double(Aggregators::AggregatorReports::AggregatorReport).tap do |report|
allow(report).to receive(:find_account_report).with(account_id).and_return(mock_account_report)
allow(report).to receive(:summarize_by_month).and_return({
account_id => {
month_key => { accrued_gross_earnings: 2500_00, total_w2_hours: 80.0, total_gig_hours: 5.0 }
}
})
end
end
let(:payroll_account) { build(:payroll_account, :pinwheel_fully_synced, flow: flow, aggregator_account_id: account_id) }
it "returns employer name from aggregator report" do
result = helper.employment_cards([ payroll_account ], mock_report, reporting_range)
expect(result.first[:name]).to eq("ACME Corp")
end
it "includes edit path to payment details with from_edit" do
result = helper.employment_cards([ payroll_account ], mock_report, reporting_range)
expect(result.first[:edit_path]).to eq(
helper.activities_flow_income_payment_details_path(user: { account_id: account_id }, from_edit: 1)
)
end
it "returns monthly gross earnings in cents and combined hours" do
result = helper.employment_cards([ payroll_account ], mock_report, reporting_range)
month_data = result.first[:months].first
expect(month_data[:gross_earnings]).to eq(2500_00)
expect(month_data[:hours]).to eq(85)
end
it "filters inactive monthly data and preserves hundredths of an hour" do
second_month = first_month + 1.month
third_month = first_month + 2.months
allow(mock_report).to receive(:summarize_by_month).and_return({
account_id => {
third_month.strftime("%Y-%m") => { accrued_gross_earnings: 0, total_w2_hours: 0.0, total_gig_hours: 0.0 },
second_month.strftime("%Y-%m") => { accrued_gross_earnings: 0, total_w2_hours: 80.0, total_gig_hours: 5.45 },
month_key => { accrued_gross_earnings: 2500_00, total_w2_hours: 42.24, total_gig_hours: 0.0 }
}
})
result = helper.employment_cards([ payroll_account ], mock_report, reporting_range)
expect(result.first[:months]).to eq([
{ month: first_month, gross_earnings: 2500_00, hours: 42.24 },
{ month: second_month, gross_earnings: 0, hours: 85.45 }
])
end
it "returns empty array when aggregator report is nil" do
result = helper.employment_cards([ payroll_account ], nil, reporting_range)
expect(result).to eq([])
end
it "falls back to N/A when employer name is unavailable" do
allow(mock_report).to receive(:find_account_report).with(account_id).and_return(nil)
result = helper.employment_cards([ payroll_account ], mock_report, reporting_range)
expect(result.first[:name]).to eq(I18n.t("activities.employment.title"))
end
it "handles accounts with no monthly data" do
allow(mock_report).to receive(:summarize_by_month).and_return({})
result = helper.employment_cards([ payroll_account ], mock_report, reporting_range)
expect(result.first[:months]).to be_empty
end
end
describe "#employment_activity_cards" do
let(:flow) { create(:activity_flow, reporting_window_months: 2, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0) }
let(:activity) { create(:employment_activity, activity_flow: flow, employer_name: "Gainesville Wrecking") }
let(:first_month) { flow.reporting_months.first.beginning_of_month }
let(:second_month) { flow.reporting_months.second.beginning_of_month }
before do
create(:employment_activity_month, employment_activity: activity, month: first_month, gross_income: 500, hours: 40)
create(:employment_activity_month, employment_activity: activity, month: second_month, gross_income: 300, hours: 20)
end
it "returns card data with employer name, month entries, and edit path" do
result = helper.employment_activity_cards([ activity ])
expect(result.first[:name]).to eq("Gainesville Wrecking")
expect(result.first[:edit_path]).to eq(
helper.review_activities_flow_income_employment_path(id: activity.id, from_edit: 1)
)
expect(result.first[:months]).to eq([
{ month: first_month, gross_earnings: 50000, hours: 40 },
{ month: second_month, gross_earnings: 30000, hours: 20 }
])
end
it "filters out months with no income or hours" do
activity.employment_activity_months.find_by(month: second_month).update!(gross_income: 0, hours: 0)
result = helper.employment_activity_cards([ activity ])
expect(result.first[:months]).to eq([
{ month: first_month, gross_earnings: 50000, hours: 40 }
])
end
it "returns empty months when no monthly entries exist" do
activity.employment_activity_months.destroy_all
result = helper.employment_activity_cards([ activity ])
expect(result.first[:months]).to eq([])
end
end
describe "#combined_employment_card_data" do
let(:flow) { create(:activity_flow, reporting_window_months: 1, volunteering_activities_count: 0, job_training_activities_count: 0, education_activities_count: 0) }
let(:reporting_range) { flow.reporting_window_range }
let(:account_id) { "test-account-123" }
let(:payroll_account) { build(:payroll_account, :pinwheel_fully_synced, flow: flow, aggregator_account_id: account_id) }
let(:employment_activity) { create(:employment_activity, activity_flow: flow, employer_name: "Gainesville Wrecking") }
let(:mock_report) do
instance_double(Aggregators::AggregatorReports::AggregatorReport).tap do |report|
account_report = double(employment: double(employer_name: "ACME Corp"))
allow(report).to receive(:find_account_report).with(account_id).and_return(account_report)
allow(report).to receive(:summarize_by_month).and_return({ account_id => {} })
end
end
before do
create(:employment_activity_month, employment_activity:, month: flow.reporting_months.first.beginning_of_month, gross_income: 500, hours: 40)
end
it "combines payroll and self-attested employment cards" do