68 lines
2 KiB
Elixir
68 lines
2 KiB
Elixir
defmodule Towerops.AgentsFixturesTest do
|
|
use Towerops.DataCase
|
|
|
|
import Towerops.AccountsFixtures
|
|
import Towerops.AgentsFixtures
|
|
|
|
describe "unique_agent_name/0" do
|
|
test "generates unique agent names" do
|
|
name1 = unique_agent_name()
|
|
name2 = unique_agent_name()
|
|
|
|
assert name1 != name2
|
|
assert name1 =~ "Test Agent"
|
|
assert name2 =~ "Test Agent"
|
|
end
|
|
end
|
|
|
|
describe "agent_token_fixture/2" do
|
|
test "creates an agent token with default name" do
|
|
user = user_fixture()
|
|
{:ok, organization} = Towerops.Organizations.create_organization(%{name: "Test Org"}, user.id)
|
|
|
|
{:ok, agent_token, token_string} = agent_token_fixture(organization.id)
|
|
|
|
assert agent_token.organization_id == organization.id
|
|
assert agent_token.name =~ "Test Agent"
|
|
assert byte_size(token_string) > 0
|
|
end
|
|
|
|
test "creates an agent token with custom name" do
|
|
user = user_fixture()
|
|
{:ok, organization} = Towerops.Organizations.create_organization(%{name: "Test Org"}, user.id)
|
|
|
|
{:ok, agent_token, _token_string} = agent_token_fixture(organization.id, "Custom Agent")
|
|
|
|
assert agent_token.name == "Custom Agent"
|
|
end
|
|
end
|
|
|
|
describe "agent_assignment_fixture/2" do
|
|
test "creates an agent assignment" do
|
|
user = user_fixture()
|
|
{:ok, organization} = Towerops.Organizations.create_organization(%{name: "Test Org"}, user.id)
|
|
|
|
{:ok, site} =
|
|
Towerops.Sites.create_site(%{
|
|
name: "Test Site",
|
|
organization_id: organization.id
|
|
})
|
|
|
|
{:ok, device} =
|
|
Towerops.Devices.create_device(%{
|
|
name: "Test Equipment",
|
|
ip_address: "192.168.1.1",
|
|
site_id: site.id,
|
|
organization_id: organization.id
|
|
})
|
|
|
|
{:ok, agent_token, _token_string} = agent_token_fixture(organization.id)
|
|
|
|
{:ok, assignment} = agent_assignment_fixture(agent_token.id, device.id)
|
|
|
|
assert assignment.agent_token_id == agent_token.id
|
|
assert assignment.device_id == device.id
|
|
assert assignment.enabled == true
|
|
end
|
|
end
|
|
end
|