|
1 | 1 | require 'forms_helper' |
2 | 2 |
|
3 | 3 | describe 'Reference Card Form', type: :request do |
| 4 | + include ActiveJob::TestHelper |
| 5 | + after { clear_enqueued_jobs } |
| 6 | + |
4 | 7 | attr_reader :patron_id |
5 | 8 | attr_reader :patron |
6 | 9 | attr_reader :user |
|
26 | 29 |
|
27 | 30 | it 'rejects a submission with a captcha verification error' do |
28 | 31 | expect_any_instance_of(Recaptcha::Verify).to receive(:verify_recaptcha).and_raise(Recaptcha::RecaptchaError) |
| 32 | + |
29 | 33 | params = { |
30 | 34 | reference_card_form: { |
31 | 35 | email: 'jrdoe@affiliate.test', |
|
37 | 41 | local_id: '123456789' |
38 | 42 | } |
39 | 43 | } |
| 44 | + |
40 | 45 | post('/forms/reference-card', params:) |
41 | 46 | expect(response).to redirect_to(action: :new, params:) |
| 47 | + |
42 | 48 | get response.header['Location'] |
43 | 49 | expect(response.body).to match('RECaptcha Error') |
44 | 50 | end |
45 | 51 |
|
46 | | - it 'accepts a submission with a valid date' do |
| 52 | + it 'accepts a submission with a valid date and enqueues email' do |
47 | 53 | params = { |
48 | 54 | reference_card_form: { |
49 | 55 | email: 'jrdoe@affiliate.test', |
|
55 | 61 | local_id: '123456789' |
56 | 62 | } |
57 | 63 | } |
58 | | - post('/forms/reference-card', params:) |
| 64 | + |
| 65 | + expect { post('/forms/reference-card', params:) }.to have_enqueued_job(ActionMailer::MailDeliveryJob) |
| 66 | + |
59 | 67 | expect(response).to have_http_status :created |
60 | 68 | end |
61 | 69 |
|
62 | 70 | it 'rejects a submission with a requested end date before the start date' do |
63 | 71 | params = { |
64 | 72 | reference_card_form: { |
65 | | - email: 'jrdoe@affiliate.test', |
66 | | - name: 'Jane R. Doe', |
| 73 | + email: 'jrdupree@affiliate.test', |
| 74 | + name: 'Jane R. Duprie', |
67 | 75 | affiliation: 'nowhere', |
68 | 76 | research_desc: 'research goes here....', |
69 | 77 | pass_date: Date.current, |
70 | 78 | pass_date_end: Date.current - 5.days, |
71 | 79 | local_id: '123456789' |
72 | 80 | } |
73 | 81 | } |
| 82 | + |
74 | 83 | post('/forms/reference-card', params:) |
75 | 84 | expect(response).to have_http_status :found |
| 85 | + |
76 | 86 | follow_redirect! |
77 | 87 | expect(response.body).to include('Requested access end date must not precede access start date') |
78 | 88 | end |
|
86 | 96 | end |
87 | 97 |
|
88 | 98 | it 'renders process form for unprocessed request' do |
89 | | - form = ReferenceCardForm.create(id: 1, email: 'openreq@test.com', name: 'John Doe', |
| 99 | + form = ReferenceCardForm.create(id: 1, email: 'openreq@test.com', name: 'John Testy', |
90 | 100 | pass_date: Date.current, pass_date_end: Date.current + 1, |
91 | 101 | research_desc: 'This is research', affiliation: 'Affiliation 1', |
92 | 102 | local_id: '8675309') |
| 103 | + |
93 | 104 | get "/forms/reference-card/#{form.id}" |
94 | 105 | expect(response.body).to include('<h3>This Reference Card request needs to be processed.</h3>') |
95 | 106 | end |
96 | 107 |
|
97 | 108 | it 'renders processed page for processed request' do |
98 | 109 | form = ReferenceCardForm.create( |
99 | | - email: 'closedreq@test.com', name: 'Jane Doe', |
| 110 | + email: 'closedreq@test.com', name: 'Jane Testy', |
100 | 111 | pass_date: Date.current, pass_date_end: Date.current + 1, |
101 | 112 | research_desc: 'This is research', affiliation: 'Affiliation 1', |
102 | 113 | local_id: '8675309', |
103 | 114 | approvedeny: true, processed_by: 'Test Admin' |
104 | 115 | ) |
| 116 | + |
105 | 117 | get "/forms/reference-card/#{form.id}" |
106 | 118 | expect(response.body).to include('<h2>This request has been processed</h2>') |
107 | 119 | end |
|
112 | 124 | expect(response.body).to include(path) |
113 | 125 | end |
114 | 126 |
|
115 | | - it 'allows an admin to deny a request' do |
| 127 | + it 'allows an admin to deny a request and enqueues denial email' do |
116 | 128 | form = ReferenceCardForm.create(email: 'openreq@test.com', name: 'John Doe', |
117 | | - affiliation: 'Red Bull', pass_date: Date.current, pass_date_end: Date.current + 1, local_id: '8675309') |
| 129 | + affiliation: 'Red Bull', |
| 130 | + pass_date: Date.current, |
| 131 | + pass_date_end: Date.current + 1, |
| 132 | + local_id: '8675309') |
118 | 133 |
|
119 | | - params = { |
120 | | - 'stack_pass_[approve_deny]' => false, |
121 | | - 'processed_by' => 'ADMIN USER', |
122 | | - 'denial_reason' => 'Item listed at another library' |
123 | | - } |
124 | | - patch("/forms/reference-card/#{form.id}", params:) |
125 | | - expect(response).to redirect_to(action: :show, id: 1) |
| 134 | + expect do |
| 135 | + patch("/forms/reference-card/#{form.id}", params: { |
| 136 | + 'stack_pass_[approve_deny]' => false, |
| 137 | + 'processed_by' => 'ADMIN USER', |
| 138 | + 'denial_reason' => 'Item listed at another library' |
| 139 | + }) |
| 140 | + end.to have_enqueued_job(ActionMailer::MailDeliveryJob) |
| 141 | + |
| 142 | + expect(response).to redirect_to(action: :show, id: form.id) |
126 | 143 |
|
127 | 144 | get(response.headers['Location']) |
128 | | - expect(response.body).to include(params['denial_reason']) |
| 145 | + expect(response.body).to include('Item listed at another library') |
129 | 146 | expect(response.body).to include('This request has been processed') |
130 | 147 | end |
131 | 148 |
|
132 | | - end |
| 149 | + it 'enqueues approval email when admin approves request' do |
| 150 | + form = ReferenceCardForm.create(email: 'openreq@test.com', name: 'John Doe', |
| 151 | + affiliation: 'Test', |
| 152 | + pass_date: Date.current, |
| 153 | + pass_date_end: Date.current + 1, |
| 154 | + local_id: '8675309') |
133 | 155 |
|
| 156 | + expect do |
| 157 | + patch("/forms/reference-card/#{form.id}", params: { |
| 158 | + 'stack_pass_[approve_deny]' => true, |
| 159 | + 'processed_by' => 'ADMIN USER' |
| 160 | + }) |
| 161 | + end.to have_enqueued_job(ActionMailer::MailDeliveryJob) |
| 162 | + end |
| 163 | + end |
134 | 164 | end |
0 commit comments