<commit_before>defmodule HELM.Entity.Controller.EntityServerTest do
  use ExUnit.Case

  alias HELL.IPv6
  alias HELL.TestHelper.Random, as: HRand
  alias HELM.Entity.Controller.Entity, as: CtrlEntity
  alias HELM.Entity.Controller.EntityType, as: CtrlEntityType
  alias HELM.Entity.Controller.EntityServer, as: CtrlEntityServer

  setup do
    type = HRand.string()
    ref_id = IPv6.generate([])
    id = IPv6.generate([])
    payload = %{entity_type: type, reference_id: ref_id}
    {:ok, type: type, id: id, payload: payload}
  end

  test "create/1", %{type: type, payload: payload, id: id} do
    {:ok, _} = CtrlEntityType.create(type)
    {:ok, entity} = CtrlEntity.create(payload)
    assert {:ok, _} = CtrlEntityServer.create(entity.entity_id, id)
  end

  describe "find/2" do
    test "success", %{type: type, payload: payload, id: id} do
      {:ok, _} = CtrlEntityType.create(type)
      {:ok, entity} = CtrlEntity.create(payload)
      {:ok, entity_server} = CtrlEntityServer.create(entity.entity_id, id)
      assert {:ok, ^entity_server} = CtrlEntityServer.find(entity.entity_id, id)
    end

    test "failure" do
      assert {:error, :notfound} = CtrlEntityServer.find(IPv6.generate([]), IPv6.generate([]))
    end
  end

  test "delete/1 idempotency", %{type: type, payload: payload, id: id} do
    {:ok, _} = CtrlEntityType.create(type)
    {:ok, entity} = CtrlEntity.create(payload)
    {:ok, entity_server} = CtrlEntityServer.create(entity.entity_id, id)
    assert :ok = CtrlEntityServer.delete(entity.entity_id, id)
    assert :ok = CtrlEntityServer.delete(entity.entity_id, id)
  end
end<commit_msg>Fix EntityServer.find/1 test contracts.<commit_after>defmodule HELM.Entity.Controller.EntityServerTest do
  use ExUnit.Case

  alias HELL.IPv6
  alias HELL.TestHelper.Random, as: HRand
  alias HELM.Entity.Controller.Entity, as: CtrlEntity
  alias HELM.Entity.Controller.EntityType, as: CtrlEntityType
  alias HELM.Entity.Controller.EntityServer, as: CtrlEntityServer

  setup do
    type = HRand.string()
    ref_id = IPv6.generate([])
    id = IPv6.generate([])
    payload = %{entity_type: type, reference_id: ref_id}
    {:ok, type: type, id: id, payload: payload}
  end

  test "create/1", %{type: type, payload: payload, id: id} do
    {:ok, _} = CtrlEntityType.create(type)
    {:ok, entity} = CtrlEntity.create(payload)
    assert {:ok, _} = CtrlEntityServer.create(entity.entity_id, id)
  end

  describe "find/1" do
    test "found servers", %{type: type, payload: payload, id: id} do
      {:ok, _} = CtrlEntityType.create(type)
      {:ok, entity} = CtrlEntity.create(payload)
      {:ok, entity_server_a} = CtrlEntityServer.create(entity.entity_id, id)
      {:ok, entity_server_b} = CtrlEntityServer.create(entity.entity_id, IPv6.generate([]))
      assert [^entity_server_a | [^entity_server_b | _]] = CtrlEntityServer.find(entity.entity_id)
    end

    test "no servers found" do
      assert [] = CtrlEntityServer.find(IPv6.generate([]))
    end
  end

  test "delete/1 idempotency", %{type: type, payload: payload, id: id} do
    {:ok, _} = CtrlEntityType.create(type)
    {:ok, entity} = CtrlEntity.create(payload)
    {:ok, _} = CtrlEntityServer.create(entity.entity_id, id)
    assert :ok = CtrlEntityServer.delete(entity.entity_id, id)
    assert :ok = CtrlEntityServer.delete(entity.entity_id, id)
  end
end
{'fraction_non_alphanumeric': 0.13561847988077497, 'fraction_numerical': 0.005067064083457526, 'mean_word_length': 4.001490312965723, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1882275', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1132, 'n_words': 262}