-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreference_card_forms_request_spec.rb
More file actions
134 lines (118 loc) · 5.1 KB
/
reference_card_forms_request_spec.rb
File metadata and controls
134 lines (118 loc) · 5.1 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
require 'forms_helper'
describe 'Reference Card Form', type: :request do
attr_reader :patron_id
attr_reader :patron
attr_reader :user
context 'specs without admin privledges' do
before do
login_as_patron(Alma::NON_FRAMEWORK_ADMIN_ID)
allow_any_instance_of(User).to receive(:role?).with(Role.stackpass_admin).and_return(false)
end
it 'reference card index page redirects to form' do
get reference_card_forms_path
expect(response).to have_http_status :found
expect(response).to redirect_to(action: :new)
end
it 'requires login if user is not a stack pass admin' do
form = ReferenceCardForm.create(id: 1, email: 'openreq@test.com', name: 'John Doe',
pass_date: Date.current, pass_date_end: Date.current + 1)
get reference_card_form_path(id: form.id)
expect(response).to have_http_status :forbidden
end
it 'rejects a submission with a captcha verification error' do
expect_any_instance_of(Recaptcha::Verify).to receive(:verify_recaptcha).and_raise(Recaptcha::RecaptchaError)
params = {
reference_card_form: {
email: 'jrdoe@affiliate.test',
name: 'Jane R. Doe',
affiliation: 'nowhere',
research_desc: 'research goes here....',
pass_date: '04/13/1996',
pass_date_end: '04/15/1996',
local_id: '123456789'
}
}
post('/forms/reference-card', params:)
expect(response).to redirect_to(action: :new, params:)
get response.header['Location']
expect(response.body).to match('RECaptcha Error')
end
it 'accepts a submission with a valid date' do
params = {
reference_card_form: {
email: 'jrdoe@affiliate.test',
name: 'Jane R. Doe',
affiliation: 'nowhere',
research_desc: 'research goes here....',
pass_date: Date.current,
pass_date_end: Date.current,
local_id: '123456789'
}
}
post('/forms/reference-card', params:)
expect(response).to have_http_status :created
end
it 'rejects a submission with a requested end date before the start date' do
params = {
reference_card_form: {
email: 'jrdoe@affiliate.test',
name: 'Jane R. Doe',
affiliation: 'nowhere',
research_desc: 'research goes here....',
pass_date: Date.current,
pass_date_end: Date.current - 5.days,
local_id: '123456789'
}
}
post('/forms/reference-card', params:)
expect(response).to have_http_status :found
follow_redirect!
expect(response.body).to include('Requested access end date must not precede access start date')
end
end
context 'specs with admin privledges' do
before do
admin_user = User.new(display_name: 'Test Admin', uid: '1707532', affiliations: ['EMPLOYEE-TYPE-ACADEMIC'])
allow_any_instance_of(ReferenceCardFormsController).to receive(:current_user).and_return(admin_user)
allow_any_instance_of(StackRequestsController).to receive(:current_user).and_return(admin_user)
end
it 'renders process form for unprocessed request' do
form = ReferenceCardForm.create(id: 1, email: 'openreq@test.com', name: 'John Doe',
pass_date: Date.current, pass_date_end: Date.current + 1,
research_desc: 'This is research', affiliation: 'Affiliation 1',
local_id: '8675309')
get "/forms/reference-card/#{form.id}"
expect(response.body).to include('<h3>This Reference Card request needs to be processed.</h3>')
end
it 'renders processed page for processed request' do
form = ReferenceCardForm.create(
email: 'closedreq@test.com', name: 'Jane Doe',
pass_date: Date.current, pass_date_end: Date.current + 1,
research_desc: 'This is research', affiliation: 'Affiliation 1',
local_id: '8675309',
approvedeny: true, processed_by: 'Test Admin'
)
get "/forms/reference-card/#{form.id}"
expect(response.body).to include('<h2>This request has been processed</h2>')
end
it 'renders 404 if request does not exist' do
get(path = '/forms/reference-card/does-not-exist')
expect(response).to have_http_status :not_found
expect(response.body).to include(path)
end
it 'allows an admin to deny a request' do
form = ReferenceCardForm.create(email: 'openreq@test.com', name: 'John Doe',
affiliation: 'Red Bull', pass_date: Date.current, pass_date_end: Date.current + 1, local_id: '8675309')
params = {
'stack_pass_[approve_deny]' => false,
'processed_by' => 'ADMIN USER',
'denial_reason' => 'Item listed at another library'
}
patch("/forms/reference-card/#{form.id}", params:)
expect(response).to redirect_to(action: :show, id: 1)
get(response.headers['Location'])
expect(response.body).to include(params['denial_reason'])
expect(response.body).to include('This request has been processed')
end
end
end