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 AuthenticationControllerTest < 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 "can login if org user is active" do
|
2021-07-01 07:24:35 +00:00
|
|
|
post "/authenticate/", params: {
|
|
|
|
|
email: "admin@example.com",
|
|
|
|
|
password: "password",
|
2021-06-12 03:11:56 +00:00
|
|
|
}, as: :json
|
|
|
|
|
|
|
|
|
|
assert_equal "200", response.code
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "cannot login if org user is not active" 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
|
|
|
post "/authenticate/", params: {
|
|
|
|
|
email: "admin@example.com",
|
|
|
|
|
password: "password",
|
2021-06-12 03:11:56 +00:00
|
|
|
}, as: :json
|
|
|
|
|
|
|
|
|
|
assert_equal "401", response.code
|
|
|
|
|
end
|
|
|
|
|
end
|