2021-07-01 07:24:35 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
require "test_helper"
|
2021-05-19 10:15:51 +00:00
|
|
|
|
|
|
|
|
class FolderAppsControllerTest < ActionDispatch::IntegrationTest
|
2021-05-19 15:39:10 +00:00
|
|
|
def setup
|
2021-07-01 07:24:35 +00:00
|
|
|
@org = Organization.create({ name: "ToolJet Test" })
|
|
|
|
|
@admin = User.create({ first_name: "Admin", email: "admin@example.com", password: "password",
|
2021-05-19 15:39:10 +00:00
|
|
|
organization: @org })
|
2021-07-01 07:24:35 +00:00
|
|
|
@developer = User.create({ first_name: "Dev", email: "dev@example.com", password: "password",
|
2021-05-19 15:39:10 +00:00
|
|
|
organization: @org })
|
2021-07-01 07:24:35 +00:00
|
|
|
@viewer = User.create({ first_name: "Viewer", email: "viewer@example.com", password: "password",
|
2021-05-19 15:39:10 +00:00
|
|
|
organization: @org })
|
2021-07-01 07:24:35 +00:00
|
|
|
OrganizationUser.create(organization: @org, user: @admin, role: "admin", status: "active")
|
|
|
|
|
OrganizationUser.create(organization: @org, user: @developer, role: "developer", status: "active")
|
|
|
|
|
OrganizationUser.create(organization: @org, user: @viewer, role: "viewer", status: "active")
|
2021-05-19 15:39:10 +00:00
|
|
|
|
2021-07-01 07:24:35 +00:00
|
|
|
@another_org = Organization.create({ name: "Another ToolJet Test" })
|
|
|
|
|
@another_org_admin = User.create({ first_name: "Admin", email: "admin@domain.com", password: "password",
|
2021-05-19 15:39:10 +00:00
|
|
|
organization: @another_org })
|
2021-07-01 07:24:35 +00:00
|
|
|
OrganizationUser.create(organization: @another_org, user: @another_org_admin, role: "admin")
|
2021-05-19 15:39:10 +00:00
|
|
|
|
2021-07-01 07:24:35 +00:00
|
|
|
@folder = Folder.create(name: "Test Folder", organization: @org)
|
2021-05-19 15:39:10 +00:00
|
|
|
end
|
|
|
|
|
|
2021-07-01 07:24:35 +00:00
|
|
|
test "org admins can add apps to folders" do
|
|
|
|
|
app = App.create(name: "Test App", organization: @org)
|
|
|
|
|
assert_difference "FolderApp.count", 1 do
|
|
|
|
|
get "/folder_apps", params: { app_id: app.id, folder_id: @folder.id }, as: :json, headers: auth_header(@admin)
|
2021-05-19 15:39:10 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-07-01 07:24:35 +00:00
|
|
|
test "admins of a different org cannot add apps to folders" do
|
|
|
|
|
app = App.create(name: "Test App", organization: @org)
|
|
|
|
|
assert_difference "FolderApp.count", 0 do
|
|
|
|
|
get "/folder_apps", params: { app_id: app.id, folder_id: @folder.id }, as: :json, headers: auth_header(@another_org_admin)
|
2021-05-19 15:39:10 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-07-01 07:24:35 +00:00
|
|
|
test "only admins & developers can add apps to folders" do
|
|
|
|
|
app = App.create(name: "Test App", organization: @org)
|
|
|
|
|
assert_difference "FolderApp.count", 1 do
|
|
|
|
|
get "/folder_apps", params: { app_id: app.id, folder_id: @folder.id }, as: :json, headers: auth_header(@developer)
|
2021-05-19 15:39:10 +00:00
|
|
|
end
|
|
|
|
|
|
2021-07-01 07:24:35 +00:00
|
|
|
assert_difference "FolderApp.count", 0 do
|
|
|
|
|
get "/folder_apps", params: { app_id: app.id, folder_id: @folder.id }, as: :json, headers: auth_header(@viewer)
|
2021-05-19 15:39:10 +00:00
|
|
|
end
|
|
|
|
|
end
|
2021-05-19 10:15:51 +00:00
|
|
|
end
|