<commit_before>require "test_helper"

class OrganisationUnitGroupTest < Minitest::Test
  def test_list_organisation_unit_groups
    organisation_unit_groups = Dhis2.client.organisation_unit_groups.list(fields: :all, page_size: 1)
    assert_equal 1, organisation_unit_groups.size

    organisation_unit_group = organisation_unit_groups.first

    assert_equal 194, organisation_unit_group.organisation_units.size
    assert_equal 194, organisation_unit_group.organisation_unit_ids.size

    refute_nil organisation_unit_group.id
    assert_equal "CHC", organisation_unit_group.display_name
  end

  def test_find_by_name
    organisation_unit_group = Dhis2.client.organisation_unit_groups.find_by(name: "CHC")
    assert_equal "CHC", organisation_unit_group.display_name
  end

  def test_create_org_unit_groups
    org_unit_group_name_1 = SecureRandom.uuid
    org_unit_groups = {name: org_unit_group_name_1, short_name: org_unit_group_name_1, code:"test", id:"Ysjldlkdsflksfs"}
    status = Dhis2.client.organisation_unit_groups.create(org_unit_groups)
    assert_equal false, status.success?
    assert_equal 1, status.total_imported
    org_unit_group_1 = Dhis2.client.organisation_unit_groups.list(fields: :all, filter: "name:eq:#{org_unit_group_name_1}").first
    assert_equal org_unit_group_name_1, org_unit_group_1.short_name
    assert_equal "Ysjldlkdsflksfs", org_unit_group_1.uid
  end
end<commit_msg>generate randomly the id of the orgunitgroup when testing the create methode<commit_after>require "test_helper"

class OrganisationUnitGroupTest < Minitest::Test
  def test_list_organisation_unit_groups
    organisation_unit_groups = Dhis2.client.organisation_unit_groups.list(fields: :all, page_size: 1)
    assert_equal 1, organisation_unit_groups.size

    organisation_unit_group = organisation_unit_groups.first

    assert_equal 194, organisation_unit_group.organisation_units.size
    assert_equal 194, organisation_unit_group.organisation_unit_ids.size

    refute_nil organisation_unit_group.id
    assert_equal "CHC", organisation_unit_group.display_name
  end

  def test_find_by_name
    organisation_unit_group = Dhis2.client.organisation_unit_groups.find_by(name: "CHC")
    assert_equal "CHC", organisation_unit_group.display_name
  end

  def test_create_org_unit_groups
    org_unit_group_name_1 = SecureRandom.uuid
    # get the random string
    string =  [('a'..'z'),('A'..'Z')].map{|i| i.to_a}.flatten
    radom_id  =  (0...11).map{ string[rand(string.length)]  }.join

    org_unit_groups = {name: org_unit_group_name_1, short_name: org_unit_group_name_1, code:"test", id:radom_id}
    status = Dhis2.client.organisation_unit_groups.create(org_unit_groups)
    assert_equal true, status.success?
    assert_equal 1, status.total_imported
    org_unit_group_1 = Dhis2.client.organisation_unit_groups.list(fields: :all, filter: "name:eq:#{org_unit_group_name_1}").first
    assert_equal org_unit_group_name_1, org_unit_group_1.short_name
    assert_equal radom_id, org_unit_group_1.id
  end
end
{'fraction_non_alphanumeric': 0.07697390155269243, 'fraction_numerical': 0.014866204162537165, 'mean_word_length': 5.944954128440367, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4806976', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1022, 'n_words': 161}