ToolJet/test/controllers/app_users_controller_test.rb

71 lines
2.7 KiB
Ruby
Raw Normal View History

2021-04-29 06:41:23 +00:00
require 'test_helper'
2021-04-27 07:06:45 +00:00
class AppUsersControllerTest < ActionDispatch::IntegrationTest
2021-04-29 06:41:23 +00:00
def setup
@org = Organization.create({ name: 'ToolJet Test' })
@org_admin = User.create({ first_name: 'Admin', email: 'admin@example.com', password: 'password',
organization: @org })
@org_developer = User.create({ first_name: 'Dev', email: 'dev@example.com', password: 'password',
organization: @org })
@org_viewer = User.create({ first_name: 'Viewer', email: 'viewer@example.com', password: 'password',
organization: @org })
2021-04-29 06:41:23 +00:00
@org_user_admin = OrganizationUser.create(organization: @org, user: @org_admin, role: 'admin')
@org_user_developer = OrganizationUser.create(organization: @org, user: @org_developer, role: 'developer')
@org_user_viewer = OrganizationUser.create(organization: @org, user: @org_viewer, role: 'viewer')
2021-04-29 06:41:23 +00:00
@another_org = Organization.create({ name: 'Another ToolJet Test' })
@another_org_admin = User.create({ first_name: 'Admin', email: 'admin@domain.com', password: 'password',
organization: @another_org })
@org_another_org_admin = OrganizationUser.create(organization: @another_org, user: @another_org_admin,
role: 'admin')
@first_app = App.create({
name: 'Test App',
organization: @org_admin.organization
})
end
2021-04-29 06:41:23 +00:00
test 'org admins can create app users' do
assert_difference 'AppUser.count', 1 do
post '/app_users/', params: {
org_user_id: @org_user_admin.id,
app_id: @first_app.id,
role: 'admin'
}, as: :json, headers: auth_header(@org_admin)
end
2021-04-29 06:41:23 +00:00
end
2021-04-29 06:41:23 +00:00
test 'non org-admins cannot create app users' do
assert_no_difference 'AppUser.count' do
post '/app_users/', params: {
org_user_id: @org_user_developer.id,
app_id: @first_app.id,
role: 'admin'
}, as: :json, headers: auth_header(@org_developer)
end
2021-04-29 06:41:23 +00:00
end
2021-04-29 06:41:23 +00:00
test 'app admins can create app users' do
AppUser.create(user: @org_viewer, app: @first_app, role: 'admin')
2021-04-29 06:41:23 +00:00
assert_difference 'AppUser.count', 1 do
post '/app_users/', params: {
org_user_id: @org_user_developer.id,
app_id: @first_app.id,
role: 'admin'
}, as: :json, headers: auth_header(@org_viewer)
end
2021-04-29 06:41:23 +00:00
end
2021-04-29 06:41:23 +00:00
test 'admin of another org cannot create app users' do
assert_no_difference 'AppUser.count' do
post '/app_users/', params: {
org_user_id: @org_user_admin.id,
app_id: @first_app.id,
role: 'admin'
}, as: :json, headers: auth_header(@another_org_admin)
end
end
2021-04-27 07:06:45 +00:00
end