2021-07-01 07:24:35 +00:00
|
|
|
# frozen_string_literal: true
|
2021-06-12 03:11:56 +00:00
|
|
|
|
2021-07-01 07:24:35 +00:00
|
|
|
require "test_helper"
|
2021-06-12 03:11:56 +00:00
|
|
|
|
2021-07-01 07:24:35 +00:00
|
|
|
class ApplicationControllerTest < ActionDispatch::IntegrationTest
|
2021-06-12 03:11:56 +00:00
|
|
|
def setup
|
2021-07-01 07:24:35 +00:00
|
|
|
@org = Organization.create({ name: "ToolJet Test" })
|
|
|
|
|
@org_admin = User.create({ first_name: "Admin", email: "admin@example.com", password: "password",
|
2021-06-12 03:11:56 +00:00
|
|
|
organization: @org })
|
2021-07-01 07:24:35 +00:00
|
|
|
@admin_org_user = OrganizationUser.create(organization: @org, user: @org_admin, role: "admin", status: "active")
|
2021-06-12 03:11:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "active users can access authenticated routes" do
|
2021-07-01 07:24:35 +00:00
|
|
|
app = App.create(name: "Test App", organization: @org)
|
|
|
|
|
get apps_url, headers: { "Content-Type": "application/json" }.merge(auth_header(@org_admin)), xhr: true
|
2021-06-12 03:11:56 +00:00
|
|
|
assert_response 200
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "archived users cannot access authenticated routes" do
|
|
|
|
|
|
2021-07-01 07:24:35 +00:00
|
|
|
@admin_org_user.update(status: "archived")
|
2021-06-12 03:11:56 +00:00
|
|
|
@admin_org_user.reload
|
|
|
|
|
|
2021-07-01 07:24:35 +00:00
|
|
|
app = App.create(name: "Test App", organization: @org)
|
|
|
|
|
get apps_url, headers: { "Content-Type": "application/json" }.merge(auth_header(@org_admin)), xhr: true
|
2021-06-12 03:11:56 +00:00
|
|
|
assert_response 401
|
|
|
|
|
end
|
|
|
|
|
end
|