1 # frozen_string_literal: true
5 class ChangesetCommentApiCapabilityTest < ActiveSupport::TestCase
6 test "as a normal user with permissionless token" do
7 token = create(:oauth_access_token)
8 capability = ApiCapability.new token
10 [:create, :destroy, :restore].each do |action|
11 assert capability.cannot? action, ChangesetComment
15 test "as a normal user with write_api token" do
16 token = create(:oauth_access_token, :scopes => %w[write_api])
17 capability = ApiCapability.new token
19 [:destroy, :restore].each do |action|
20 assert capability.cannot? action, ChangesetComment
23 [:create].each do |action|
24 assert capability.can? action, ChangesetComment
28 test "as a moderator with permissionless token" do
29 token = create(:oauth_access_token, :resource_owner_id => create(:moderator_user).id)
30 capability = ApiCapability.new token
32 [:create, :destroy, :restore].each do |action|
33 assert capability.cannot? action, ChangesetComment
37 test "as a moderator with write_api token" do
38 token = create(:oauth_access_token, :resource_owner_id => create(:moderator_user).id, :scopes => %w[write_api])
39 capability = ApiCapability.new token
41 [:create, :destroy, :restore].each do |action|
42 assert capability.can? action, ChangesetComment
47 class NoteApiCapabilityTest < ActiveSupport::TestCase
48 test "as a normal user with permissionless token" do
49 token = create(:oauth_access_token)
50 capability = ApiCapability.new token
52 [:create, :comment, :close, :reopen, :destroy].each do |action|
53 assert capability.cannot? action, Note
57 test "as a normal user with write_notes token" do
58 token = create(:oauth_access_token, :scopes => %w[write_notes])
59 capability = ApiCapability.new token
61 [:destroy].each do |action|
62 assert capability.cannot? action, Note
65 [:create, :comment, :close, :reopen].each do |action|
66 assert capability.can? action, Note
70 test "as a moderator with permissionless token" do
71 token = create(:oauth_access_token, :resource_owner_id => create(:moderator_user).id)
72 capability = ApiCapability.new token
74 [:destroy].each do |action|
75 assert capability.cannot? action, Note
79 test "as a moderator with write_notes token" do
80 token = create(:oauth_access_token, :resource_owner_id => create(:moderator_user).id, :scopes => %w[write_notes])
81 capability = ApiCapability.new token
83 [:destroy].each do |action|
84 assert capability.can? action, Note
89 class UserApiCapabilityTest < ActiveSupport::TestCase
90 test "user preferences" do
91 # A user with empty tokens
92 token = create(:oauth_access_token)
93 capability = ApiCapability.new token
95 [:index, :show, :update_all, :update, :destroy].each do |act|
96 assert capability.cannot? act, UserPreference
99 token = create(:oauth_access_token, :scopes => %w[read_prefs])
100 capability = ApiCapability.new token
102 [:update_all, :update, :destroy].each do |act|
103 assert capability.cannot? act, UserPreference
106 [:index, :show].each do |act|
107 assert capability.can? act, UserPreference
110 token = create(:oauth_access_token, :scopes => %w[write_prefs])
111 capability = ApiCapability.new token
113 [:index, :show].each do |act|
114 assert capability.cannot? act, UserPreference
117 [:update_all, :update, :destroy].each do |act|
118 assert capability.can? act, UserPreference