forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrocodoc_document_spec.rb
More file actions
162 lines (140 loc) · 5.19 KB
/
Copy pathcrocodoc_document_spec.rb
File metadata and controls
162 lines (140 loc) · 5.19 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
#
# Copyright (C) 2012 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe 'CrocodocDocument' do
before :once do
Setting.set 'crocodoc_counter', 0
PluginSetting.create! :name => 'crocodoc',
:settings => { :api_key => "blahblahblahblahblah" }
end
before :each do
Crocodoc::API.any_instance.stubs(:upload).returns 'uuid' => '1234567890'
end
context 'permissions_for_user' do
before :once do
teacher_in_course(:active_all => true)
student_in_course
ta_in_course
@submitter = @student
student_in_course
@other_student = @student
@assignment = @course.assignments.create! name: "a1"
attachment = crocodocable_attachment_model(context: @submitter)
@submission = @assignment.submit_homework @submitter,
submission_type: "online_upload",
attachments: [attachment]
@crocodoc = attachment.crocodoc_document
end
it "should let the teacher view all annotations" do
expect(@crocodoc.permissions_for_user(@teacher)).to eq({
:filter => 'all',
:admin => true,
:editable => true,
})
end
it "should only include ids specified in the whitelist" do
expect(@crocodoc.permissions_for_user(@teacher, [@teacher.crocodoc_id!, @submitter.crocodoc_id!])).to eq({
:filter => "#{@teacher.crocodoc_id!},#{@submitter.crocodoc_id!}",
:admin => true,
:editable => true,
})
end
it "should set :admin and :editable to false if the calling user isn't whitelisted" do
expect(@crocodoc.permissions_for_user(@submitter, [@teacher.crocodoc_id!])).to eq({
:filter => "#{@teacher.crocodoc_id!}",
:admin => false,
:editable => false,
})
end
context "submitter permissions" do
it "should see everything (unless the assignment is muted)" do
expect(@crocodoc.permissions_for_user(@submitter)).to eq({
:filter => 'all',
:admin => false,
:editable => true,
})
end
it "should only see their own annotations when assignment is muted" do
@assignment.mute!
expect(@crocodoc.permissions_for_user(@submitter)).to eq({
:filter => @submitter.crocodoc_id,
:admin => false,
:editable => true,
})
end
end
it "should only allow classmates to see their own annotations" do
expect(@crocodoc.permissions_for_user(@other_student)).to eq({
:filter => @other_student.crocodoc_id!,
:admin => false,
:editable => true,
})
end
it "should not allow annotations if no user is given" do
expect(@crocodoc.permissions_for_user(nil)).to eq({
:filter => 'none',
:admin => false,
:editable => false,
})
end
it "should not allow annotations if anonymous_peer_reviews" do
@submission.assignment.update_attributes anonymous_peer_reviews: true,
peer_reviews: true
expect(@crocodoc.permissions_for_user(@student)).to eq({
:filter => 'none',
:admin => false,
:editable => false,
})
end
it "returns permissions for older submission versions" do
attachment = crocodocable_attachment_model(context: @submitter)
submission2 = @assignment.submit_homework @submitter,
submission_type: "online_upload",
attachments: [attachment]
cd1 = @crocodoc
cd2 = attachment.crocodoc_document
[cd1, cd2].each { |cd|
expect(cd.permissions_for_user(@submitter)).to eq({
filter: 'all',
admin: false,
editable: true,
})
}
end
context "#upload" do
it "raises exception on timeout cutoff" do
Canvas.stubs(:timeout_protection).raises Canvas::TimeoutCutoff.new(5)
@crocodoc.update_attribute(:uuid, nil)
expect { @crocodoc.upload }.to raise_exception(Canvas::Crocodoc::CutoffError)
end
it "raises exception on timeout" do
Canvas.stubs(:timeout_protection).raises Timeout::Error
@crocodoc.update_attribute(:uuid, nil)
expect { @crocodoc.upload }.to raise_exception(Canvas::Crocodoc::TimeoutError)
end
end
end
context 'update_process_states' do
it "should honor the batch size setting" do
Setting.set('crocodoc_status_check_batch_size', 2)
4.times { CrocodocDocument.create!(:process_state => "QUEUED") }
Crocodoc::API.any_instance.expects(:status).times(2).returns []
CrocodocDocument.update_process_states
end
end
end