<commit_before>require 'test_helper'

class GroupSetsApiTest < ActiveSupport::TestCase
  include Rack::Test::Methods
  include TestHelpers::AuthHelper
  include TestHelpers::JsonHelper
  include TestHelpers::TestFileHelper

  def app
    Rails.application
  end

  def test_post_add_a_new_groupset_to_a_unit_without_authorization
    # A dummy groupSet
    newGroupSet = FactoryBot.build(:group_set)

    # Create a unit
    newUnit = FactoryBot.create(:unit)
    
    # Obtain a student from unit
    studentUser = newUnit.active_projects.first.student

    # Data that we want to post
    data_to_post = {
      unit_id: newUnit.id,
      group_set: newGroupSet
    }

    # Perform the POST
    post_json with_auth_token("/api/units/#{newUnit.id}/group_sets", studentUser), data_to_post

    # Check error code
    assert_equal 403, last_response.status
  end

  def test_post_add_a_new_groupset_to_a_unit_with_authorization
    # A dummy groupSet
    newGroupSet = FactoryBot.build(:group_set)
<commit_msg>FIX: Change post test for group_sets_api<commit_after>require 'test_helper'

class GroupSetsApiTest < ActiveSupport::TestCase
  include Rack::Test::Methods
  include TestHelpers::AuthHelper
  include TestHelpers::JsonHelper
  include TestHelpers::TestFileHelper

  def app
    Rails.application
  end

  def test_post_add_a_new_groupset_to_a_unit_without_authorization
    # A dummy groupSet
    newGroupSet = FactoryBot.build(:group_set)

    # Create a unit
    newUnit = FactoryBot.create(:unit)
    
    # Obtain a student from the unit
    studentUser = newUnit.active_projects.first.student

    # Data that we want to post
    data_to_post = {
      unit_id: newUnit.id,
      group_set: newGroupSet
    }

    # Perform the POST
    post_json with_auth_token("/api/units/#{newUnit.id}/group_sets", studentUser), data_to_post

    # Check error code
    assert_equal 403, last_response.status
  end

  def test_post_add_a_new_groupset_to_a_unit_with_authorization
    # A dummy groupSet
    newGroupSet = FactoryBot.build(:group_set)

{'fraction_non_alphanumeric': 0.06679668454412482, 'fraction_numerical': 0.0029254022428083864, 'mean_word_length': 3.944578313253012, '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': '1187558', 'n_tokens_mistral': 666, 'n_tokens_neox': 651, 'n_words': 142}