Commit 097861a1eaf086630edb02870f0d8ede1163cb2c
Exists in
staging
and in
31 other branches
Merge branch 'plugin-test-api' into 'master'
Run api tests in plugins See merge request !870
Showing
3 changed files
with
181 additions
and
179 deletions
Show diff stats
lib/tasks/plugins_tests.rake
@@ -9,7 +9,7 @@ $broken_plugins = %w[ | @@ -9,7 +9,7 @@ $broken_plugins = %w[ | ||
9 | @all_plugins = Dir.glob('plugins/*').map { |f| File.basename(f) } - ['template'] | 9 | @all_plugins = Dir.glob('plugins/*').map { |f| File.basename(f) } - ['template'] |
10 | @all_plugins.sort! | 10 | @all_plugins.sort! |
11 | 11 | ||
12 | -@all_tasks = [:units, :functionals, :integration, :cucumber, :selenium] | 12 | +@all_tasks = [:units, :api, :functionals, :integration, :cucumber, :selenium] |
13 | 13 | ||
14 | def enabled_plugins | 14 | def enabled_plugins |
15 | Dir.glob('{baseplugins,config/plugins}/*').map { |f| File.basename(f) } - ['README'] | 15 | Dir.glob('{baseplugins,config/plugins}/*').map { |f| File.basename(f) } - ['README'] |
@@ -87,6 +87,8 @@ def task2folder(task) | @@ -87,6 +87,8 @@ def task2folder(task) | ||
87 | result = case task.to_sym | 87 | result = case task.to_sym |
88 | when :units | 88 | when :units |
89 | :unit | 89 | :unit |
90 | + when :api | ||
91 | + :api | ||
90 | when :functionals | 92 | when :functionals |
91 | :functional | 93 | :functional |
92 | when :integration | 94 | when :integration |
@@ -0,0 +1,178 @@ | @@ -0,0 +1,178 @@ | ||
1 | +require_relative '../../../../test/api/test_helper' | ||
2 | + | ||
3 | +class PushNotificationApiTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + login_api | ||
7 | + environment = Environment.default | ||
8 | + environment.enable_plugin(PushNotificationPlugin) | ||
9 | + end | ||
10 | + | ||
11 | + should 'list all my device tokens' do | ||
12 | + logged_user = @user | ||
13 | + token1 = PushNotificationPlugin::DeviceToken.create!(:token => "firsttoken", device_name: "my device", :user => logged_user) | ||
14 | + token2 = PushNotificationPlugin::DeviceToken.create!(:token => "secondtoken", device_name: "my device", :user => logged_user) | ||
15 | + | ||
16 | + get "/api/v1/push_notification_plugin/device_tokens?#{params.to_query}" | ||
17 | + json = JSON.parse(last_response.body) | ||
18 | + assert_equivalent [token1.token, token2.token], json | ||
19 | + end | ||
20 | + | ||
21 | + should 'not list other people device tokens' do | ||
22 | + user = User.create!(:login => 'outro', :email => 'outro@example.com', :password => 'outro', :password_confirmation => 'outro', :environment => Environment.default) | ||
23 | + user.activate | ||
24 | + PushNotificationPlugin::DeviceToken.create!(:token => "firsttoken", device_name: "my device", :user => user) | ||
25 | + get "/api/v1/push_notification_plugin/device_tokens?#{params.merge(:target_id => user.id).to_query}" | ||
26 | + assert_equal 401, last_response.status | ||
27 | + end | ||
28 | + | ||
29 | + should 'admin see other user\'s device tokens' do | ||
30 | + logged_user = @user | ||
31 | + Environment.default.add_admin(logged_user.person) | ||
32 | + logged_user.reload | ||
33 | + | ||
34 | + user = User.create!(:login => 'outro', :email => 'outro@example.com', :password => 'outro', :password_confirmation => 'outro', :environment => Environment.default) | ||
35 | + user.activate | ||
36 | + | ||
37 | + token1 = PushNotificationPlugin::DeviceToken.create!(:token => "firsttoken", device_name: "my device", :user => user) | ||
38 | + | ||
39 | + get "/api/v1/push_notification_plugin/device_tokens?#{params.merge(:target_id => user.id).to_query}" | ||
40 | + json = JSON.parse(last_response.body) | ||
41 | + assert_equivalent [token1.token], json | ||
42 | + end | ||
43 | + | ||
44 | +#------------------------------------------------------------------------------------------------------ | ||
45 | + | ||
46 | + should 'add my device token' do | ||
47 | + params.merge!(:device_name => "my_device", :token => "token1") | ||
48 | + post "/api/v1/push_notification_plugin/device_tokens?#{params.to_query}" | ||
49 | + json = JSON.parse(last_response.body) | ||
50 | + assert_equivalent ["token1"], json["user"]["device_tokens"] | ||
51 | + end | ||
52 | + | ||
53 | + should 'not add device tokens for other people' do | ||
54 | + user = User.create!(:login => 'outro', :email => 'outro@example.com', :password => 'outro', :password_confirmation => 'outro', :environment => Environment.default) | ||
55 | + user.activate | ||
56 | + params.merge!(:device_name => "my_device", :token => "tokenX", :target_id => user.id) | ||
57 | + post "/api/v1/push_notification_plugin/device_tokens?#{params.to_query}" | ||
58 | + assert_equal 401, last_response.status | ||
59 | + end | ||
60 | + | ||
61 | + should 'admin add device tokens for other users' do | ||
62 | + logged_user = @user | ||
63 | + Environment.default.add_admin(logged_user.person) | ||
64 | + logged_user.reload | ||
65 | + | ||
66 | + user = User.create!(:login => 'outro', :email => 'outro@example.com', :password => 'outro', :password_confirmation => 'outro', :environment => Environment.default) | ||
67 | + user.activate | ||
68 | + | ||
69 | + params.merge!(:device_name => "my_device", :token=> "tokenY", :target_id => user.id) | ||
70 | + post "/api/v1/push_notification_plugin/device_tokens?#{params.to_query}" | ||
71 | + | ||
72 | + json = JSON.parse(last_response.body) | ||
73 | + assert_equivalent ["tokenY"], json["user"]["device_tokens"] | ||
74 | + end | ||
75 | + | ||
76 | +#------------------------------------------------------------------------------------------------------ | ||
77 | + | ||
78 | + should 'delete my device tokens' do | ||
79 | + logged_user = @user | ||
80 | + PushNotificationPlugin::DeviceToken.create!(:token => "firsttoken", device_name: "my device", :user => logged_user) | ||
81 | + PushNotificationPlugin::DeviceToken.create!(:token => "secondtoken", device_name: "my device", :user => logged_user) | ||
82 | + | ||
83 | + params.merge!(:token => "secondtoken") | ||
84 | + delete "/api/v1/push_notification_plugin/device_tokens?#{params.to_query}" | ||
85 | + json = JSON.parse(last_response.body) | ||
86 | + assert_equivalent ["firsttoken"], json["user"]["device_tokens"] | ||
87 | + end | ||
88 | + | ||
89 | + should 'not delete device tokens for other people' do | ||
90 | + user = User.create!(:login => 'outro', :email => 'outro@example.com', :password => 'outro', :password_confirmation => 'outro', :environment => Environment.default) | ||
91 | + user.activate | ||
92 | + | ||
93 | + PushNotificationPlugin::DeviceToken.create!(:token => "secondtoken", device_name: "my device", :user => user) | ||
94 | + user.reload | ||
95 | + | ||
96 | + params.merge!(:token => "secondtoken", :target_id => user.id) | ||
97 | + delete "/api/v1/push_notification_plugin/device_tokens?#{params.to_query}" | ||
98 | + assert_equal 401, last_response.status | ||
99 | + assert_equivalent user.device_token_list, ["secondtoken"] | ||
100 | + end | ||
101 | + | ||
102 | + should 'admin delete device tokens for other users' do | ||
103 | + logged_user = @user | ||
104 | + Environment.default.add_admin(logged_user.person) | ||
105 | + logged_user.reload | ||
106 | + | ||
107 | + user = User.create!(:login => 'outro', :email => 'outro@example.com', :password => 'outro', :password_confirmation => 'outro', :environment => Environment.default) | ||
108 | + user.activate | ||
109 | + | ||
110 | + PushNotificationPlugin::DeviceToken.create!(:token => "firsttoken", device_name: "my device", :user => user) | ||
111 | + PushNotificationPlugin::DeviceToken.create!(:token => "secondtoken", device_name: "my device", :user => user) | ||
112 | + user.reload | ||
113 | + | ||
114 | + params.merge!(:token=> "secondtoken", :target_id => user.id) | ||
115 | + delete "/api/v1/push_notification_plugin/device_tokens?#{params.to_query}" | ||
116 | + | ||
117 | + json = JSON.parse(last_response.body) | ||
118 | + assert_equivalent ["firsttoken"], json["user"]["device_tokens"] | ||
119 | + end | ||
120 | + | ||
121 | +#-------------------------------------------------------------------------------------------------------------------------------------------- | ||
122 | + | ||
123 | + should 'list all notifications disabled by default for new users' do | ||
124 | + get "/api/v1/push_notification_plugin/notification_settings?#{params.to_query}" | ||
125 | + json = JSON.parse(last_response.body) | ||
126 | + json["user"]["notification_settings"].each_pair do |notification, status| | ||
127 | + refute status | ||
128 | + end | ||
129 | + end | ||
130 | + | ||
131 | + should 'list device tokens notification options' do | ||
132 | + logged_user = @user | ||
133 | + logged_user.notification_settings.activate_notification "new_comment" | ||
134 | + logged_user.save! | ||
135 | + | ||
136 | + get "/api/v1/push_notification_plugin/notification_settings?#{params.to_query}" | ||
137 | + json = JSON.parse(last_response.body) | ||
138 | + assert_equal true, json["user"]["notification_settings"]["new_comment"] | ||
139 | + assert_equal false, json["user"]["notification_settings"]["add_friend"] | ||
140 | + end | ||
141 | + | ||
142 | + should 'get possible notifications' do | ||
143 | + get "/api/v1/push_notification_plugin/possible_notifications?#{params.to_query}" | ||
144 | + json = JSON.parse(last_response.body) | ||
145 | + assert_equivalent PushNotificationPlugin::NotificationSettings::NOTIFICATIONS.keys, json["possible_notifications"] | ||
146 | + end | ||
147 | + | ||
148 | + should 'change device tokens notification options' do | ||
149 | + logged_user = @user | ||
150 | + params.merge!("new_comment"=> "true") | ||
151 | + | ||
152 | + post "/api/v1/push_notification_plugin/notification_settings?#{params.to_query}" | ||
153 | + logged_user.reload | ||
154 | + json = JSON.parse(last_response.body) | ||
155 | + assert_equal true, json["user"]["notification_settings"]["new_comment"] | ||
156 | + assert_equal true, logged_user.notification_settings.hash_flags["new_comment"] | ||
157 | + end | ||
158 | + | ||
159 | + should 'get active notifications list' do | ||
160 | + logged_user = @user | ||
161 | + logged_user.notification_settings.activate_notification "new_comment" | ||
162 | + logged_user.save! | ||
163 | + | ||
164 | + get "/api/v1/push_notification_plugin/active_notifications?#{params.to_query}" | ||
165 | + json = JSON.parse(last_response.body) | ||
166 | + assert_equivalent ["new_comment"], json | ||
167 | + end | ||
168 | + | ||
169 | + should 'get inactive notifications list' do | ||
170 | + logged_user = @user | ||
171 | + logged_user.notification_settings.activate_notification "new_comment" | ||
172 | + logged_user.save | ||
173 | + | ||
174 | + get "/api/v1/push_notification_plugin/inactive_notifications?#{params.to_query}" | ||
175 | + json = JSON.parse(last_response.body) | ||
176 | + assert_equivalent (PushNotificationPlugin::NotificationSettings::NOTIFICATIONS.keys-["new_comment"]), json | ||
177 | + end | ||
178 | +end |
plugins/push_notification/test/unit/api_test.rb
@@ -1,178 +0,0 @@ | @@ -1,178 +0,0 @@ | ||
1 | -require_relative '../../../../test/unit/api/test_helper' | ||
2 | - | ||
3 | -class PushNotificationApiTest < ActiveSupport::TestCase | ||
4 | - | ||
5 | - def setup | ||
6 | - login_api | ||
7 | - environment = Environment.default | ||
8 | - environment.enable_plugin(PushNotificationPlugin) | ||
9 | - end | ||
10 | - | ||
11 | - should 'list all my device tokens' do | ||
12 | - logged_user = @user | ||
13 | - token1 = PushNotificationPlugin::DeviceToken.create!(:token => "firsttoken", device_name: "my device", :user => logged_user) | ||
14 | - token2 = PushNotificationPlugin::DeviceToken.create!(:token => "secondtoken", device_name: "my device", :user => logged_user) | ||
15 | - | ||
16 | - get "/api/v1/push_notification_plugin/device_tokens?#{params.to_query}" | ||
17 | - json = JSON.parse(last_response.body) | ||
18 | - assert_equivalent [token1.token, token2.token], json | ||
19 | - end | ||
20 | - | ||
21 | - should 'not list other people device tokens' do | ||
22 | - user = User.create!(:login => 'outro', :email => 'outro@example.com', :password => 'outro', :password_confirmation => 'outro', :environment => Environment.default) | ||
23 | - user.activate | ||
24 | - PushNotificationPlugin::DeviceToken.create!(:token => "firsttoken", device_name: "my device", :user => user) | ||
25 | - get "/api/v1/push_notification_plugin/device_tokens?#{params.merge(:target_id => user.id).to_query}" | ||
26 | - assert_equal 401, last_response.status | ||
27 | - end | ||
28 | - | ||
29 | - should 'admin see other user\'s device tokens' do | ||
30 | - logged_user = @user | ||
31 | - Environment.default.add_admin(logged_user.person) | ||
32 | - logged_user.reload | ||
33 | - | ||
34 | - user = User.create!(:login => 'outro', :email => 'outro@example.com', :password => 'outro', :password_confirmation => 'outro', :environment => Environment.default) | ||
35 | - user.activate | ||
36 | - | ||
37 | - token1 = PushNotificationPlugin::DeviceToken.create!(:token => "firsttoken", device_name: "my device", :user => user) | ||
38 | - | ||
39 | - get "/api/v1/push_notification_plugin/device_tokens?#{params.merge(:target_id => user.id).to_query}" | ||
40 | - json = JSON.parse(last_response.body) | ||
41 | - assert_equivalent [token1.token], json | ||
42 | - end | ||
43 | - | ||
44 | -#------------------------------------------------------------------------------------------------------ | ||
45 | - | ||
46 | - should 'add my device token' do | ||
47 | - params.merge!(:device_name => "my_device", :token => "token1") | ||
48 | - post "/api/v1/push_notification_plugin/device_tokens?#{params.to_query}" | ||
49 | - json = JSON.parse(last_response.body) | ||
50 | - assert_equivalent ["token1"], json["user"]["device_tokens"] | ||
51 | - end | ||
52 | - | ||
53 | - should 'not add device tokens for other people' do | ||
54 | - user = User.create!(:login => 'outro', :email => 'outro@example.com', :password => 'outro', :password_confirmation => 'outro', :environment => Environment.default) | ||
55 | - user.activate | ||
56 | - params.merge!(:device_name => "my_device", :token => "tokenX", :target_id => user.id) | ||
57 | - post "/api/v1/push_notification_plugin/device_tokens?#{params.to_query}" | ||
58 | - assert_equal 401, last_response.status | ||
59 | - end | ||
60 | - | ||
61 | - should 'admin add device tokens for other users' do | ||
62 | - logged_user = @user | ||
63 | - Environment.default.add_admin(logged_user.person) | ||
64 | - logged_user.reload | ||
65 | - | ||
66 | - user = User.create!(:login => 'outro', :email => 'outro@example.com', :password => 'outro', :password_confirmation => 'outro', :environment => Environment.default) | ||
67 | - user.activate | ||
68 | - | ||
69 | - params.merge!(:device_name => "my_device", :token=> "tokenY", :target_id => user.id) | ||
70 | - post "/api/v1/push_notification_plugin/device_tokens?#{params.to_query}" | ||
71 | - | ||
72 | - json = JSON.parse(last_response.body) | ||
73 | - assert_equivalent ["tokenY"], json["user"]["device_tokens"] | ||
74 | - end | ||
75 | - | ||
76 | -#------------------------------------------------------------------------------------------------------ | ||
77 | - | ||
78 | - should 'delete my device tokens' do | ||
79 | - logged_user = @user | ||
80 | - PushNotificationPlugin::DeviceToken.create!(:token => "firsttoken", device_name: "my device", :user => logged_user) | ||
81 | - PushNotificationPlugin::DeviceToken.create!(:token => "secondtoken", device_name: "my device", :user => logged_user) | ||
82 | - | ||
83 | - params.merge!(:token => "secondtoken") | ||
84 | - delete "/api/v1/push_notification_plugin/device_tokens?#{params.to_query}" | ||
85 | - json = JSON.parse(last_response.body) | ||
86 | - assert_equivalent ["firsttoken"], json["user"]["device_tokens"] | ||
87 | - end | ||
88 | - | ||
89 | - should 'not delete device tokens for other people' do | ||
90 | - user = User.create!(:login => 'outro', :email => 'outro@example.com', :password => 'outro', :password_confirmation => 'outro', :environment => Environment.default) | ||
91 | - user.activate | ||
92 | - | ||
93 | - PushNotificationPlugin::DeviceToken.create!(:token => "secondtoken", device_name: "my device", :user => user) | ||
94 | - user.reload | ||
95 | - | ||
96 | - params.merge!(:token => "secondtoken", :target_id => user.id) | ||
97 | - delete "/api/v1/push_notification_plugin/device_tokens?#{params.to_query}" | ||
98 | - assert_equal 401, last_response.status | ||
99 | - assert_equivalent user.device_token_list, ["secondtoken"] | ||
100 | - end | ||
101 | - | ||
102 | - should 'admin delete device tokens for other users' do | ||
103 | - logged_user = @user | ||
104 | - Environment.default.add_admin(logged_user.person) | ||
105 | - logged_user.reload | ||
106 | - | ||
107 | - user = User.create!(:login => 'outro', :email => 'outro@example.com', :password => 'outro', :password_confirmation => 'outro', :environment => Environment.default) | ||
108 | - user.activate | ||
109 | - | ||
110 | - PushNotificationPlugin::DeviceToken.create!(:token => "firsttoken", device_name: "my device", :user => user) | ||
111 | - PushNotificationPlugin::DeviceToken.create!(:token => "secondtoken", device_name: "my device", :user => user) | ||
112 | - user.reload | ||
113 | - | ||
114 | - params.merge!(:token=> "secondtoken", :target_id => user.id) | ||
115 | - delete "/api/v1/push_notification_plugin/device_tokens?#{params.to_query}" | ||
116 | - | ||
117 | - json = JSON.parse(last_response.body) | ||
118 | - assert_equivalent ["firsttoken"], json["user"]["device_tokens"] | ||
119 | - end | ||
120 | - | ||
121 | -#-------------------------------------------------------------------------------------------------------------------------------------------- | ||
122 | - | ||
123 | - should 'list all notifications disabled by default for new users' do | ||
124 | - get "/api/v1/push_notification_plugin/notification_settings?#{params.to_query}" | ||
125 | - json = JSON.parse(last_response.body) | ||
126 | - json["user"]["notification_settings"].each_pair do |notification, status| | ||
127 | - refute status | ||
128 | - end | ||
129 | - end | ||
130 | - | ||
131 | - should 'list device tokens notification options' do | ||
132 | - logged_user = @user | ||
133 | - logged_user.notification_settings.activate_notification "new_comment" | ||
134 | - logged_user.save! | ||
135 | - | ||
136 | - get "/api/v1/push_notification_plugin/notification_settings?#{params.to_query}" | ||
137 | - json = JSON.parse(last_response.body) | ||
138 | - assert_equal true, json["user"]["notification_settings"]["new_comment"] | ||
139 | - assert_equal false, json["user"]["notification_settings"]["add_friend"] | ||
140 | - end | ||
141 | - | ||
142 | - should 'get possible notifications' do | ||
143 | - get "/api/v1/push_notification_plugin/possible_notifications?#{params.to_query}" | ||
144 | - json = JSON.parse(last_response.body) | ||
145 | - assert_equivalent PushNotificationPlugin::NotificationSettings::NOTIFICATIONS.keys, json["possible_notifications"] | ||
146 | - end | ||
147 | - | ||
148 | - should 'change device tokens notification options' do | ||
149 | - logged_user = @user | ||
150 | - params.merge!("new_comment"=> "true") | ||
151 | - | ||
152 | - post "/api/v1/push_notification_plugin/notification_settings?#{params.to_query}" | ||
153 | - logged_user.reload | ||
154 | - json = JSON.parse(last_response.body) | ||
155 | - assert_equal true, json["user"]["notification_settings"]["new_comment"] | ||
156 | - assert_equal true, logged_user.notification_settings.hash_flags["new_comment"] | ||
157 | - end | ||
158 | - | ||
159 | - should 'get active notifications list' do | ||
160 | - logged_user = @user | ||
161 | - logged_user.notification_settings.activate_notification "new_comment" | ||
162 | - logged_user.save! | ||
163 | - | ||
164 | - get "/api/v1/push_notification_plugin/active_notifications?#{params.to_query}" | ||
165 | - json = JSON.parse(last_response.body) | ||
166 | - assert_equivalent ["new_comment"], json | ||
167 | - end | ||
168 | - | ||
169 | - should 'get inactive notifications list' do | ||
170 | - logged_user = @user | ||
171 | - logged_user.notification_settings.activate_notification "new_comment" | ||
172 | - logged_user.save | ||
173 | - | ||
174 | - get "/api/v1/push_notification_plugin/inactive_notifications?#{params.to_query}" | ||
175 | - json = JSON.parse(last_response.body) | ||
176 | - assert_equivalent (PushNotificationPlugin::NotificationSettings::NOTIFICATIONS.keys-["new_comment"]), json | ||
177 | - end | ||
178 | -end |