<commit_before>require 'test_helper'

class MembershipsControllerTest < ActionDispatch::IntegrationTest
  include Devise::Test::IntegrationHelpers

  test 'get #index' do
    person = people(:two)
    group = groups(:two)
    sign_in person

    affiliate = Group.create(an_api_key: rand(1_000_000).to_s)
    affiliate_membership = Membership.create(person: Person.create)
    affiliate.memberships.push(affiliate_membership)
    Affiliation.create(affiliated: affiliate, group: group)

    get group_memberships_url(group_id: group.id), as: :json
    assert_response :success
    json = JSON.parse(response.body)

    response_members_ids = json['memberships']['data'].map { |m| m['id'].to_i }
    assert_includes response_members_ids, group.memberships.first.id
    assert_includes response_members_ids, affiliate_membership.id

    assert_equal  group.memberships.count + affiliate.memberships.count,
    json['memberships']['data'].count

  end

  test 'get #index with filter' do
    person = people(:organizer)
    sign_in person

    get group_memberships_url(group_id: groups(:test).id, filter: 'test admin'), as: :json
    assert_response :success
    json = JSON.parse(response.body)

    assert_equal 1, json['memberships']['data'].count
    assert_equal people(:admin).memberships.first.id, json['memberships']['data'].first['id'].to_i
  end

  test 'get #show' do
    person = people(:organizer)
    sign_in person

    get group_membership_url(group_id: groups(:test).id, id: person.id), as: :json
    assert_response :success
  end


  test 'get #show no group' do
    person = people(:organizer)
    sign_in person

    get membership_url( id: person.id), as: :json
    assert_response :success
  end

  test 'get #show on affiliated' do
    person = people(:organizer)
    sign_in person
    affiliate = Group.create(an_api_key: rand(1_000_000).to_s)
    affiliate_membership = Membership.create(person: person, group: affiliate)
    Affiliation.create(affiliated: affiliate, group: groups(:test))

    get group_membership_url(group_id: groups(:test).id, id: person.id), as: :json
    assert_response :success

    get group_membership_url(group_id: affiliate.id, id: person.id), as: :json
    assert_response :success
  end
 <commit_msg>removing skip<commit_after>require 'test_helper'

class MembershipsControllerTest < ActionDispatch::IntegrationTest
  include Devise::Test::IntegrationHelpers

  test 'get #index' do
    person = people(:two)
    group = groups(:two)
    sign_in person

    affiliate = Group.create(an_api_key: rand(1_000_000).to_s)
    affiliate_membership = Membership.create(person: Person.create)
    affiliate.memberships.push(affiliate_membership)
    Affiliation.create(affiliated: affiliate, group: group)

    get group_memberships_url(group_id: group.id), as: :json
    assert_response :success
    json = JSON.parse(response.body)

    response_members_ids = json['memberships']['data'].map { |m| m['id'].to_i }
    assert_includes response_members_ids, group.memberships.first.id
    assert_includes response_members_ids, affiliate_membership.id

    assert_equal  group.memberships.count + affiliate.memberships.count,
    json['memberships']['data'].count

  end

  test 'get #index with filter' do
    person = people(:organizer)
    sign_in person

    get group_memberships_url(group_id: groups(:test).id, filter: 'test admin'), as: :json
    assert_response :success
    json = JSON.parse(response.body)

    assert_equal 1, json['memberships']['data'].count
    assert_equal people(:admin).memberships.first.id, json['memberships']['data'].first['id'].to_i
  end

  test 'get #show' do
    person = people(:organizer)
    sign_in person

    get group_membership_url(group_id: groups(:test).id, id: person.id), as: :json
    assert_response :success
  end


#  skip 'get #show no group' do
#    person = people(:organizer)
#    sign_in person
#
#    get membership_url( id: person.id), as: :json
#    assert_response :success
#  end

  test 'get #show on affiliated' do
    person = people(:organizer)
    sign_in person
    affiliate = Group.create(an_api_key: rand(1_000_000).to_s)
    affiliate_membership = Membership.create(person: person, group: affiliate)
    Affiliation.create(affiliated: affiliate, group: groups(:test))

    get group_membership_url(group_id: groups(:test).id, id: person.id), as: :json
    assert_response :success

    get group_membership_url(group_id: affiliate.id, id: person.id), as: :json
    assert_response :success
  end
 
{'fraction_non_alphanumeric': 0.11219296304492145, 'fraction_numerical': 0.006638636866563399, 'mean_word_length': 4.4326923076923075, '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': '3218592', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1413, 'n_words': 319}