mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-18 07:52:23 +01:00
(test) backend test for notification types and notification preferences
This commit is contained in:
parent
35f2a69048
commit
ae67a371f5
@ -1112,7 +1112,7 @@ ActiveRecord::Schema.define(version: 2023_01_31_104958) do
|
||||
t.text "description"
|
||||
t.boolean "public_page", default: true
|
||||
t.boolean "disabled"
|
||||
t.boolean "auto_cancel", default: false
|
||||
t.boolean "auto_cancel"
|
||||
t.integer "auto_cancel_threshold"
|
||||
t.integer "auto_cancel_deadline"
|
||||
t.boolean "authorization"
|
||||
|
26
test/fixtures/notification_preferences.yml
vendored
Normal file
26
test/fixtures/notification_preferences.yml
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
notification_preference_1:
|
||||
id: 1
|
||||
user_id: 1
|
||||
notification_type_id: 1
|
||||
in_system: true
|
||||
email: true
|
||||
created_at: 2023-02-02 15:25:13.744539000 Z
|
||||
updated_at: 2023-02-02 15:25:13.744539000 Z
|
||||
|
||||
notification_preference_2:
|
||||
id: 2
|
||||
user_id: 1
|
||||
notification_type_id: 2
|
||||
in_system: true
|
||||
email: true
|
||||
created_at: 2023-02-02 15:25:13.744539000 Z
|
||||
updated_at: 2023-02-02 15:25:13.744539000 Z
|
||||
|
||||
notification_preference_3:
|
||||
id: 3
|
||||
user_id: 2
|
||||
notification_type_id: 2
|
||||
in_system: false
|
||||
email: false
|
||||
created_at: 2023-02-02 15:25:13.744539000 Z
|
||||
updated_at: 2023-02-02 15:25:13.744539000 Z
|
31
test/fixtures/notification_types.yml
vendored
Normal file
31
test/fixtures/notification_types.yml
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
notification_type_1:
|
||||
id: 1
|
||||
name: 'notify_dev_when_sun_shines'
|
||||
category: 'meteo'
|
||||
is_configurable: true
|
||||
created_at: 2023-02-02 15:25:13.744539000 Z
|
||||
updated_at: 2023-02-02 15:25:13.744539000 Z
|
||||
|
||||
notification_type_2:
|
||||
id: 2
|
||||
name: 'notify_dev_when_raining'
|
||||
category: 'meteo'
|
||||
is_configurable: true
|
||||
created_at: 2023-02-02 15:25:30.321953000 Z
|
||||
updated_at: 2023-02-02 15:25:30.321953000 Z
|
||||
|
||||
notification_type_3:
|
||||
id: 3
|
||||
name: 'notify_dev_when_storming'
|
||||
category: 'meteo'
|
||||
is_configurable: true
|
||||
created_at: 2023-02-02 15:25:13.744539000 Z
|
||||
updated_at: 2023-02-02 15:25:13.744539000 Z
|
||||
|
||||
notification_type_4:
|
||||
id: 4
|
||||
name: 'notify_dev_when_tsunami'
|
||||
category: 'meteo'
|
||||
is_configurable: false
|
||||
created_at: 2023-02-02 15:25:30.321953000 Z
|
||||
updated_at: 2023-02-02 15:25:30.321953000 Z
|
@ -0,0 +1,83 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class NotificationPreferencesTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@admin = User.find_by(username: 'admin')
|
||||
login_as(@admin, scope: :user)
|
||||
end
|
||||
|
||||
test 'Index lists all notification preferences for a user' do
|
||||
get '/api/notification_preferences'
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 200, response.status, response.body
|
||||
assert_equal Mime[:json], response.content_type
|
||||
|
||||
# Check the list items are ok and don't include other users' notification preferences
|
||||
notification_preferences = json_response(response.body)
|
||||
assert_not_equal notification_preferences.count, 0
|
||||
assert_equal NotificationPreference.where(user: @admin).count, notification_preferences.count
|
||||
end
|
||||
|
||||
test 'update a notification preference' do
|
||||
patch '/api/notification_preferences/1',
|
||||
params: {
|
||||
notification_preference: {
|
||||
id: 1,
|
||||
user_id: 1,
|
||||
notification_type: 'notify_dev_when_sun_shines',
|
||||
in_system: false,
|
||||
email: false
|
||||
}
|
||||
}.to_json,
|
||||
headers: default_headers
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 200, response.status, response.body
|
||||
assert_equal Mime[:json], response.content_type
|
||||
|
||||
# Check the status was updated
|
||||
res = json_response(response.body)
|
||||
assert_equal 1, res[:id]
|
||||
assert_equal 'notify_dev_when_sun_shines', res[:notification_type]
|
||||
end
|
||||
|
||||
test 'bulk update notification preference' do
|
||||
patch '/api/notification_preferences/bulk_update',
|
||||
params: {
|
||||
notification_preferences: [
|
||||
{
|
||||
id: 1,
|
||||
user_id: 1,
|
||||
notification_type: 'notify_dev_when_sun_shines',
|
||||
in_system: false,
|
||||
email: false
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
user_id: 1,
|
||||
notification_type: 'notify_dev_when_raining',
|
||||
in_system: false,
|
||||
email: false
|
||||
}
|
||||
]
|
||||
}.to_json,
|
||||
headers: default_headers
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 204, response.status, response.body
|
||||
|
||||
# Check records
|
||||
first_notification_preference = NotificationPreference.find(1)
|
||||
assert_not_nil first_notification_preference, 'notification preference was not found in database'
|
||||
assert_equal first_notification_preference.email, false
|
||||
assert_equal first_notification_preference.in_system, false
|
||||
|
||||
second_notification_preference = NotificationPreference.find(2)
|
||||
assert_not_nil second_notification_preference, 'notification preference was not found in database'
|
||||
assert_equal second_notification_preference.email, false
|
||||
assert_equal second_notification_preference.in_system, false
|
||||
end
|
||||
end
|
36
test/integration/notifications/notification_types_test.rb
Normal file
36
test/integration/notifications/notification_types_test.rb
Normal file
@ -0,0 +1,36 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class NotificationTypesTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@admin = User.find_by(username: 'admin')
|
||||
login_as(@admin, scope: :user)
|
||||
end
|
||||
|
||||
test 'Index lists all notification types' do
|
||||
get '/api/notification_types'
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 200, response.status, response.body
|
||||
assert_equal Mime[:json], response.content_type
|
||||
|
||||
# Check the list items are ok
|
||||
notification_types = json_response(response.body)
|
||||
assert_not_equal notification_types.count, 0
|
||||
assert_equal NotificationType.count, notification_types.count
|
||||
end
|
||||
|
||||
test 'Index with params[:is_configurable] lists only configurable notification types' do
|
||||
get '/api/notification_types?is_configurable=true'
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 200, response.status, response.body
|
||||
assert_equal Mime[:json], response.content_type
|
||||
|
||||
# Check the list items are ok
|
||||
notification_types = json_response(response.body)
|
||||
assert_not_equal notification_types.count, 0
|
||||
assert_equal NotificationType.where(is_configurable: true).count, notification_types.count
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user