-
-
Notifications
You must be signed in to change notification settings - Fork 573
Expand file tree
/
Copy pathpartner_system_spec.rb
More file actions
818 lines (662 loc) · 32.7 KB
/
partner_system_spec.rb
File metadata and controls
818 lines (662 loc) · 32.7 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
Capybara.using_wait_time 10 do # allow up to 10 seconds for content to load in the test
RSpec.describe "Partner management", type: :system, js: true do
let(:organization) { create(:organization) }
let(:user) { create(:user, organization: organization) }
let(:organization_admin) { create(:organization_admin, organization: organization) }
let(:partner) { create(:partner, organization: organization) }
before do
sign_in(user)
end
let!(:page_content_wait) { 10 } # allow up to 10 seconds for content to load in the test
describe 'approving a partner that is awaiting approval' do
let!(:partner_awaiting_approval) { create(:partner, :awaiting_review) }
before do
expect(partner_awaiting_approval.status).not_to eq(:approved)
end
context 'when the approval succeeds' do
it 'should approve the partner' do
visit partners_path
assert page.has_content? partner_awaiting_approval.name
click_on "Review Applicant's Profile"
assert page.has_content?('Partner Profile')
click_on 'Approve Partner'
assert page.has_content? 'Partner approved!'
expect(partner_awaiting_approval.reload.approved?).to eq(true)
end
it 'Double clicking approval button does not result in the partner attemping to be approved twice' do
visit partners_path
assert page.has_content? partner_awaiting_approval.name
click_on "Review Applicant's Profile"
# Make sure the button is there before trying to double click it
expect(page.find('a.btn.btn-success.btn-md[href*="/approve_application"]')).to have_content("Approve Partner")
# Double click on the Distribution complete button
ferrum_double_click('a.btn.btn-success.btn-md[href*="/approve_application"]')
# Capybara will be quick to determine that a screen doesn't have content.
# Make some positive assertions that only appears on the new screen to make
# sure it's loaded before asserting something isn't there.
expect(page).to have_content("Partner Agencies for")
# If it tries to mark the partner as approved twice, the second time
# will fail (the partner is already approved) and show this error
expect(page).not_to have_content('Failed to approve partner because: ["partner is not waiting for approval"]')
end
end
context 'when the approval does not succeed' do
let(:fake_error_msg) { Faker::Games::ElderScrolls.dragon }
before do
allow_any_instance_of(PartnerApprovalService).to receive(:call)
allow_any_instance_of(PartnerApprovalService).to receive_message_chain(:errors, :none?).and_return(false)
allow_any_instance_of(PartnerApprovalService).to receive_message_chain(:errors, :full_messages).and_return(fake_error_msg)
end
it 'should show an error message and not approve the partner' do
visit partners_path
assert page.has_content? partner_awaiting_approval.name
click_on "Review Applicant's Profile"
click_on 'Approve Partner'
assert page.has_content? "Failed to approve partner because: #{fake_error_msg}"
expect(partner_awaiting_approval.reload.approved?).to eq(false)
end
end
end
describe 'adding a new partner and inviting them' do
context 'when adding & inviting a partner successfully' do
let(:partner_attributes) do
{
name: Faker::Name.name,
email: Faker::Internet.email,
quota: Faker::Number.within(range: 5..100),
notes: Faker::Lorem.paragraph,
info_for_partner: Faker::Lorem.paragraph
}
end
before do
visit partners_path
assert page.has_content? "Partner Agencies for #{organization.name}"
click_on 'New Partner Agency'
fill_in 'Name *', with: partner_attributes[:name]
fill_in 'E-mail *', with: partner_attributes[:email]
fill_in 'Quota', with: partner_attributes[:quota]
fill_in 'Notes', with: partner_attributes[:notes]
fill_in 'Partner specific information', with: partner_attributes[:info_for_partner]
find('button', text: 'Add Partner Agency').click
assert page.has_content? "Partner #{partner_attributes[:name]} added!"
accept_confirm do
find('tr', text: partner_attributes[:name]).find_button('Invite').click
end
assert page.has_content? "Partner #{partner_attributes[:name]} invited!"
end
it 'should have added the partner and invited them' do
expect(Partner.find_by(email: partner_attributes[:email]).status).to eq('invited')
end
end
context 'when adding a partner incorrectly' do
let(:partner_attributes) do
{
name: Faker::Name.name
}
end
before do
visit partners_path
assert page.has_content? "Partner Agencies for #{organization.name}"
click_on 'New Partner Agency'
fill_in 'Name *', with: partner_attributes[:name]
find('button', text: 'Add Partner Agency').click
end
it 'should have not added a new partner and indicate the failure' do
assert page.has_content? "Failed to add partner due to: "
assert page.has_content? "New Partner for #{organization.name}"
partner = Partner.find_by(name: partner_attributes[:name])
expect(partner).to eq(nil)
end
end
end
describe "one step inviting a partner" do
before do
Partner.delete_all # ensure no pre created partner
end
let!(:uninvited_partner) { create(:partner, :uninvited) }
context "when partner is uninvited and one step partner invite setting is on" do
it "shows Invite and Approve button and approves the partner when clicked" do
organization.update!(one_step_partner_invite: true)
visit partners_path
assert page.has_content? "Invite and Approve"
expect do
click_on "Invite and Approve"
end.to change { uninvited_partner.reload.status }.from("uninvited").to("approved")
end
end
context "when one step partner invite setting is off" do
it "does not show invite and approve button" do
organization.update!(one_step_partner_invite: false)
visit partners_path
expect(page).to_not have_content "Invite and Approve"
end
end
end
describe 'requesting recertification of a partner' do
context 'GIVEN a user goes through the process of requesting recertification of partner' do
let!(:partner_to_request_recertification) { create(:partner, status: 'approved') }
before do
sign_in(user)
visit partners_path
end
it 'should notify the user that its been successful and change the partner status' do
accept_confirm do
find_button('Request Recertification').click
end
expect(page).to have_content "#{partner_to_request_recertification.name} recertification successfully requested!"
expect(partner_to_request_recertification.reload.recertification_required?).to eq(true)
end
end
end
describe "#index" do
before(:each) do
@uninvited = create(:partner, name: "Bcd", status: :uninvited, organization: organization)
@invited = create(:partner, name: "Abc", status: :invited, organization: organization)
@approved = create(:partner, :approved, name: "Cde", status: :approved, organization: organization)
@deactivated = create(:partner, name: "Def", status: :deactivated, organization: organization)
visit partners_path
end
it "displays the partner agency names in alphabetical order" do
expect(page).to have_css("table tr", count: 4, wait: page_content_wait)
expect(page.find(:xpath, "//table/tbody/tr[1]/td[1]")).to have_content(@invited.name)
expect(page.find(:xpath, "//table/tbody/tr[3]/td[1]")).to have_content(@approved.name)
expect(page.find(:xpath, %(//*[@id="partner-status"]))).to have_content("3 Active")
expect(page.find(:xpath, %(//*[@id="partner-status"]))).to have_content("1 Deactivated")
end
it "allows a user to invite a partner", js: true do
partner = create(:partner, name: 'Charities', organization: organization)
partner.primary_user.delete
visit partners_path
accept_alert("Send an invitation to #{partner.name} to create their profile for approval?") do
ele = find('tr', text: partner.name)
within(ele) { click_on "Invite" }
end
expect(page).to have_content "Partner #{partner.name} invited!", wait: page_content_wait
expect(page.find(".alert")).to have_content "invited!", wait: page_content_wait
end
it "shows invite button only for unapproved partners" do
expect(page.find('tr', text: 'Abc')).to have_content('Invited')
expect(page.find('tr', text: 'Bcd')).to have_content('Invite')
expect(page.find('tr', text: 'Cde')).to have_no_content('Invite')
end
context "when filtering" do
it "allows the user to click on one of the statuses at the top to filter the results" do
approved_count = Partner.approved.count
within "table tbody" do
expect(page).to have_css("tr", count: Partner.active.count)
end
within "#partner-status" do
click_on "Approved"
end
within "table tbody" do
expect(page).to have_css("tr", count: approved_count)
end
end
end
context "when exporting as CSV" do
context "when filtering" do
it "preserves the filter constraints in the CSV output" do
approved_partners = Partner.approved.to_a
within "#partner-status" do
click_on "Approved"
end
page.find 'a.filtering', text: /Approved/
click_on "Export Partner Agencies"
wait_for_download
expect(downloads.length).to eq(1)
expect(download).to match(/.*\.csv/)
rows = download_content.split("\n").slice(1..)
expect(rows.size).to eq(approved_partners.size)
expect(rows.first).to match(/#{approved_partners.first.email}/)
end
end
end
end
describe "#show" do
context "when viewing an uninvited partner" do
let(:uninvited) { create(:partner, name: "Uninvited Partner", status: :uninvited) }
subject { partner_path(uninvited.id) }
it 'only has an edit option available' do
visit subject
expect(page).to have_selector(:link_or_button, 'Edit details')
expect(page).to_not have_selector(:link_or_button, 'View')
expect(page).to_not have_selector(:link_or_button, 'Add/Remind Partner')
end
end
context "when viewing an invited partner as a partner" do
let(:partner) { create(:partner, name: "Invited Partner", status: :invited) }
before do
sign_out(user)
sign_in(partner.users.first)
end
it "redirects user to partners page root page (dashboard) with error message" do
visit partner_path(partner.id)
expect(page).to have_content("Dashboard - #{partner.name}")
expect(page.find(".alert-danger")).to have_content("You must be logged in as the essentials bank's organization administrator to approve partner applications.")
end
end
context "when viewing a deactivated partner" do
let(:deactivated) { create(:partner, name: "Deactivated Partner", status: :deactivated) }
subject { partner_path(deactivated.id) }
it 'allows reactivation ' do
visit subject
expect(page).to have_selector(:link_or_button, 'Reactivate')
end
end
context "when exporting as CSV" do
subject { partner_path(partner.id) }
let(:partner) do
partner = create(:partner, :approved)
partner.distributions << create(:distribution, :with_items, item_quantity: 1231)
partner.distributions << create(:distribution, :with_items, item_quantity: 4564)
partner.distributions << create(:distribution, :with_items, item_quantity: 7897)
partner
end
let(:fake_get_return) do
{ "agency" => {
"families_served" => Faker::Number.number,
"children_served" => Faker::Number.number,
"family_zipcodes" => Faker::Number.number,
"family_zipcodes_list" => [Faker::Number.number]
} }.to_json
end
context "when filtering" do
it "preserves the filter constraints in the CSV output" do
visit subject
click_on "Export Partner Distributions"
wait_for_download
expect(downloads.length).to eq(1)
expect(download).to match(/.*\.csv/)
rows = download_content.split("\n").slice(1..)
expect(rows.size).to eq(partner.distributions.size)
expect(rows.join).to have_text('1231', count: 2)
expect(rows.join).to have_text('4564', count: 2)
expect(rows.join).to have_text('7897', count: 2)
end
end
end
end
describe "#new" do
subject { new_partner_path }
it "User can add a new partner" do
visit subject
fill_in "Name", with: "Frank"
fill_in "E-mail", with: "frank@frank.com"
check 'send_reminders'
click_button "Add Partner Agency"
expect(page.find(".alert")).to have_content "added"
end
it "disallows a user from creating a new partner with empty name" do
visit subject
click_button "Add Partner Agency"
expect(page.find(".alert")).to have_content "Failed to add partner due to:"
end
it "should not display inactive storage locations in dropdown" do
create(:storage_location, name: "Inactive R Us", discarded_at: Time.zone.now)
visit subject
expect(page).to have_no_content "Inactive R Us"
end
end
describe "#edit" do
let!(:partner) { create(:partner, name: "Frank") }
subject { edit_partner_path(partner.id) }
it "User can update a partner" do
visit subject
name = Faker::Name.first_name
fill_in "Name", with: name
click_button "Update Partner"
expect(page).to have_current_path(partner_path(partner.id))
partner.reload
expect(partner.name).to eq(name)
end
it "prevents a user from updating a partner with empty name" do
visit subject
fill_in "Name", with: ""
click_button "Update Partner"
expect(page.find(".alert")).to have_content "Something didn't work quite right -- try again?"
end
it "User can uncheck send_reminders" do
visit subject
uncheck 'send_reminders'
click_button "Update Partner"
expect(page.find(".alert")).to have_content "updated"
partner.reload
expect(partner.send_reminders).to be false
end
it "allows documents to be uploaded" do
document_1 = Rails.root.join("spec/fixtures/files/distribution_program_address.pdf")
document_2 = Rails.root.join("spec/fixtures/files/distribution_same_address.pdf")
documents = [document_1, document_2]
# Upload the documents
visit subject
attach_file(documents, make_visible: true) do
page.find('input#partner_documents').click
end
# Save Progress
click_button "Update Partner"
# Expect documents to exist on show partner page
expect(page).to have_current_path(partner_path(partner.id))
expect(page).to have_link("distribution_program_address.pdf")
expect(page).to have_link("distribution_same_address.pdf")
# Expect documents to exist on edit partner page
visit subject
expect(page).to have_link("distribution_program_address.pdf")
expect(page).to have_link("distribution_same_address.pdf")
end
it "allows documents to be uploaded and persists documents across multiple refreshes", :aggregate_failures do
document_1 = Rails.root.join("spec/fixtures/files/distribution_program_address.pdf")
document_2 = Rails.root.join("spec/fixtures/files/distribution_same_address.pdf")
documents = [document_1, document_2]
# Upload the documents
visit subject
attach_file(documents, make_visible: true) do
page.find('input#partner_documents').click
end
# Test document persistence across multiple refresh cycles
3.times do |iteration|
# Save progress
click_button "Update Partner"
# Verify documents on show page
expect(page).to have_current_path(partner_path(partner.id))
expect(page).to have_link("distribution_program_address.pdf")
expect(page).to have_link("distribution_same_address.pdf")
# Visit edit page and verify documents persist
visit subject
expect(page).to have_link("distribution_program_address.pdf")
expect(page).to have_link("distribution_same_address.pdf")
end
end
end
describe "#edit_profile" do
let!(:partner) { create(:partner, name: "Frank") }
subject { edit_profile_path(partner.id) }
context "when step-wise editing is enabled" do
before do
Flipper.enable(:partner_step_form)
visit subject
end
it "displays all sections in a closed state by default" do
within ".accordion" do
expect(page).to have_css("#agency_information.accordion-collapse.collapse", visible: false)
expect(page).to have_css("#program_delivery_address.accordion-collapse.collapse", visible: false)
partner.partials_to_show.each do |partial|
expect(page).to have_css("##{partial}.accordion-collapse.collapse", visible: false)
end
end
end
it "allows sections to be opened, closed, filled in any order, and reviewed" do
# Media
find("button[data-bs-target='#media_information']").click
expect(page).to have_css("#media_information.accordion-collapse.collapse.show", visible: true)
within "#media_information" do
fill_in "Website", with: "https://www.example.com"
end
find("button[data-bs-target='#media_information']").click
expect(page).to have_css("#media_information.accordion-collapse.collapse", visible: false)
# Contacts
find("button[data-bs-target='#contacts']").click
expect(page).to have_css("#contacts.accordion-collapse.collapse.show", visible: true)
within "#contacts" do
fill_in "Executive Director Name", with: "Lisa Smith"
end
# Save Progress
all("input[type='submit'][value='Save Progress']").last.click
expect(page).to have_css(".alert-success", text: "Details were successfully updated.")
# Save and Review
all("input[type='submit'][value='Save and Review']").last.click
expect(current_path).to eq(partner_path(partner.id))
expect(page).to have_css(".alert-success", text: "Details were successfully updated.")
end
it "displays the edit view with sections containing validation errors expanded" do
# Open up Media section and clear out website value
find("button[data-bs-target='#media_information']").click
within "#media_information" do
fill_in "Website", with: ""
uncheck "No Social Media Presence"
end
# Open Pick up person section and fill in 4 email addresses
find("button[data-bs-target='#pick_up_person']").click
within "#pick_up_person" do
fill_in "Pick Up Person's Email", with: "email1@example.com, email2@example.com, email3@example.com, email4@example.com"
end
# Open Partner Settings section and uncheck all options
find("button[data-bs-target='#partner_settings']").click
within "#partner_settings" do
uncheck "Enable Quantity-based Requests" if has_checked_field?("Enable Quantity-based Requests")
uncheck "Enable Child-based Requests (unclick if you only do bulk requests)" if has_checked_field?("Enable Child-based Requests (unclick if you only do bulk requests)")
uncheck "Enable Requests for Individuals" if has_checked_field?("Enable Requests for Individuals")
end
# Save Progress
all("input[type='submit'][value='Save Progress']").last.click
# Expect an alert-danger message containing validation errors
expect(page).to have_css(".alert-danger", text: /There is a problem/)
expect(page).to have_content("No social media presence must be checked if you have not provided any of Website, Twitter, Facebook, or Instagram.")
expect(page).to have_content("Enable child based requests At least one request type must be set")
expect(page).to have_content("Pick up email can't have more than three email addresses")
# Expect media section, pick up person section, and partner settings section to be opened
expect(page).to have_css("#media_information.accordion-collapse.collapse.show", visible: true)
expect(page).to have_css("#pick_up_person.accordion-collapse.collapse.show", visible: true)
expect(page).to have_css("#partner_settings.accordion-collapse.collapse.show", visible: true)
# Try to Submit and Review from error state
all("input[type='submit'][value='Save and Review']").last.click
# Expect an alert-danger message containing validation errors
expect(page).to have_css(".alert-danger", text: /There is a problem/)
expect(page).to have_content("No social media presence must be checked if you have not provided any of Website, Twitter, Facebook, or Instagram.")
expect(page).to have_content("Enable child based requests At least one request type must be set")
expect(page).to have_content("Pick up email can't have more than three email addresses")
# Expect media section, pick up person section, and partner settings section to be opened
expect(page).to have_css("#media_information.accordion-collapse.collapse.show", visible: true)
expect(page).to have_css("#pick_up_person.accordion-collapse.collapse.show", visible: true)
expect(page).to have_css("#partner_settings.accordion-collapse.collapse.show", visible: true)
end
end
end
describe "#approve_partner" do
let(:tooltip_message) do
"Partner has not requested approval yet. Partners are able to request approval by going into 'My Organization' and clicking 'Request Approval' button."
end
let!(:invited_partner) { create(:partner, name: "Amelia Ebonheart", status: :invited) }
let!(:awaiting_review_partner) { create(:partner, name: "Beau Brummel", status: :awaiting_review) }
context "when partner has :invited status" do
before { visit_approval_page(partner_name: invited_partner.name) }
it { expect(page).to have_selector(:link_or_button, 'Approve Partner') }
end
context "when viewing a partner's users" do
subject { partner_users_path(partner) }
let(:partner) { create(:partner, name: "Partner") }
let(:partner_user) { partner.users.first }
let(:invitation_sent_at) { partner_user.invitation_sent_at.to_fs(:date_picker) }
let(:last_sign_in_at) { partner_user.last_sign_in_at.to_fs(:date_picker) }
before do
sign_out(user)
sign_in(organization_admin)
end
it 'can show users of a partner' do
visit subject
expect(page).to have_content(partner_user.name)
expect(page).to have_content(partner_user.email)
end
end
context "when partner has :awaiting_review status" do
before { visit_approval_page(partner_name: awaiting_review_partner.name) }
it { expect(page).to have_selector(:link_or_button, 'Approve Partner') }
end
end
describe 'changing partner group association' do
before do
sign_in(user)
visit partner_path(partner.id)
end
let!(:existing_partner_group) { create(:partner_group) }
context 'when the partner has no partner group' do
before do
expect(partner.partner_group).to be_nil
end
it 'it should say they can request every item' do
assert page.has_content? 'All Items Requestable'
assert page.has_content? 'Settings'
end
end
context 'when a partner is assigned to partner group' do
before do
assert page.has_content? 'All Items Requestable'
partner.update!(partner_group: nil)
end
context 'that has requestable item categories' do
let!(:item_category) do
ic = create(:item_category, organization: organization)
existing_partner_group.item_categories << ic
ic
end
let!(:items_in_category) { create_list(:item, 3, item_category_id: item_category.id) }
before do
click_on 'Edit details'
select existing_partner_group.name
click_on 'Update Partner'
end
it 'should properly indicate the requestable items and adjust the partners requestable items' do
assert page.has_content? item_category.name
expect { partner.reload }.to change(partner, :requestable_items).from([]).to(match_array(items_in_category))
end
end
context 'that has no requestable item categories' do
before do
expect(existing_partner_group.item_categories).to be_empty
click_on 'Edit details'
select existing_partner_group.name
click_on 'Update Partner'
end
it 'should properly indicate the requestable items and adjust the partners requestable items' do
assert page.has_content? 'No Items Requestable'
expect { partner.reload }.to change(partner, :requestable_items).from([]).to([])
end
end
end
end
describe "partner group management", type: :system, js: true do
before do
sign_in(user)
end
let!(:item_category_1) { create(:item_category, organization: organization) }
let!(:item_category_2) { create(:item_category, organization: organization) }
let!(:items_in_category_1) { create_list(:item, 3, item_category_id: item_category_1.id) }
let!(:items_in_category_2) { create_list(:item, 3, item_category_id: item_category_2.id) }
describe 'viewing the partner groups' do
let!(:partner_group_1) { create(:partner_group, organization: organization) }
let!(:partner_1) { create(:partner, partner_group: partner_group_1) }
before do
partner_group_1.item_categories << item_category_1
end
context "with a reminder schedule" do
before do
travel_to Time.zone.local(2020, 10, 10)
valid_reminder_schedule = ReminderScheduleService.new({
by_month_or_week: "day_of_month",
every_nth_month: 1,
day_of_month: 20
}).to_ical
partner_group_1.update(
send_reminders: true,
deadline_day: 25,
reminder_schedule_definition: valid_reminder_schedule
)
end
it "reports the next date a reminder email will be sent the deadline date that will be included in the next reminder email" do
visit partners_path
click_on 'Groups'
expect(page).to have_content("Your next reminder date is Tue Oct 20 2020.")
expect(page).to have_content("The deadline on your next reminder email will be Sun Oct 25 2020.")
end
end
end
describe 'creating a new partner group' do
it 'should allow creating a new partner group with item categories' do
travel_to Time.zone.local(2020, 10, 10)
visit partners_path
click_on 'Groups'
click_on 'New Partner Group'
fill_in 'Name *', with: 'Test Group'
# Click on the second item category
find("input#partner_group_item_category_ids_#{item_category_2.id}").click
# Opt in to sending deadline reminders
check 'Yes'
choose 'Day of Month'
fill_in "partner_group_reminder_schedule_service_day_of_month", with: 1
fill_in "partner_group_deadline_day", with: 25
find_button('Add Partner Group').click
assert page.has_content? 'Group Name', wait: page_content_wait
assert page.has_content? 'Test Group'
assert page.has_content? item_category_2.name
expect(page).to have_content("Your next reminder date is Sun Nov 01 2020.")
expect(page).to have_content("The deadline on your next reminder email will be Wed Nov 25 2020.")
end
end
describe 'editing a existing partner group' do
let!(:existing_partner_group) { create(:partner_group, organization: organization) }
before do
existing_partner_group.item_categories << item_category_1
end
it 'should allow updating the partner name' do
visit partners_path
click_on 'Groups'
assert page.has_content? existing_partner_group.name, wait: page_content_wait
assert page.has_content? item_category_1.name
click_on 'Edit'
fill_in 'Name *', with: 'New Group Name'
# Unset the existing category
find("input#partner_group_item_category_ids_#{item_category_1.id}").click
# Set a new one on the category
find("input#partner_group_item_category_ids_#{item_category_2.id}").click
find_button('Update Partner Group').click
assert page.has_content? 'New Group Name', wait: page_content_wait
refute page.has_content? item_category_1.name
assert page.has_content? item_category_2.name
end
describe "editing a custom reminder schedule" do
def post_refresh
# Opt in to sending deadline reminders
check 'Yes'
end
before do
partner.update!(partner_group: existing_partner_group)
visit partners_path
click_on 'Groups'
assert page.has_content? existing_partner_group.name, wait: page_content_wait
click_on 'Edit'
post_refresh
end
it_behaves_like "deadline and reminder form", "partner_group", "Update Partner Group", nil, :post_refresh
it "the deadline day form's reminder and deadline dates are consistent with the dates calculated by the FetchPartnersToRemindNowService and DeadlineService" do
travel_to Time.zone.local(2025, 9, 30)
refresh
post_refresh
choose "Day of Month"
fill_in "partner_group_reminder_schedule_service_day_of_month", with: safe_add_days(Time.zone.now, 1).day
fill_in "Deadline day in reminder email", with: safe_add_days(Time.zone.now, 2).day
reminder_text = find('small[data-deadline-day-target="reminderText"]').text
reminder_text.slice!("Your next reminder date is ")
reminder_text.slice!(".")
shown_recurrence_date = Time.zone.strptime(reminder_text, "%a %b %d %Y")
deadline_text = find('small[data-deadline-day-target="deadlineText"]').text
deadline_text.slice!("The deadline on your next reminder email will be ")
deadline_text.slice!(".")
shown_deadline_date = Time.zone.strptime(deadline_text, "%a %b %d %Y")
click_on "Update Partner Group"
existing_partner_group.reload
expect(Partners::FetchPartnersToRemindNowService.new.fetch).to_not include(partner)
travel_to shown_recurrence_date
expect(Partners::FetchPartnersToRemindNowService.new.fetch).to include(partner)
expect(DeadlineService.new(deadline_day: DeadlineService.get_deadline_for_partner(partner)).next_deadline.in_time_zone(Time.zone)).to be_within(1.second).of shown_deadline_date
expect(page).to have_content("Your next reminder date is #{reminder_text}.")
expect(page).to have_content("The deadline on your next reminder email will be #{deadline_text}.")
end
end
end
end
end
end
def visit_approval_page(partner_name:)
visit partners_path
ele = find('tr', text: partner_name)
within(ele) { click_on "Review Applicant's Profile" }
end