<commit_before>require 'test_helper'
require 'user'

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

  def app
    Rails.application
  end

  def test_get_students_with_authentication
    # Create admin
    #adminUser = FactoryBot.create(:user, :admin)

    # Create unit
    newUnit = FactoryBot.create(:unit)

    #Create campus
    #newCampus = FactoryBot.create(:campus)

  #  expectedStudents = newUnit.projects.all
 #   expectedStudents each do | data |
 #     puts(data)
  #  end
    # Create student
   # studentUser = FactoryBot.create(:user, :student)

    # Assign student to the unit
    #newUnit.enrol_student(studentUser, newCampus)

    # The get that we will be testing.
    get with_auth_token "/api/students/?unit_id=#{newUnit.id}", newUnit.main_convenor_user
    #assert_equal expectedStudents.count, last_response_body.count
    response_keys = %w(first_name last_name student_id project_id)
    last_response_body.each do | data |
      #pro = Project.find(data['project_id'])
      #assert_json_matches_model(data, pro, response_keys)
    end
    assert_equal 200, last_response.status
  end

  def test_get_students_without_authentication
    # Create student user<commit_msg>FIX: Change get tests for student_api<commit_after>require 'test_helper'
require 'user'

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

  def app
    Rails.application
  end

  def test_get_students_with_authentication
    # Create admin
    #adminUser = FactoryBot.create(:user, :admin)

    # Create unit
    newUnit = FactoryBot.create(:unit)

    #Create campus
    #newCampus = FactoryBot.create(:campus)

  #  expectedStudents = newUnit.projects.all
 #   expectedStudents each do | data |
 #     puts(data)
  #  end
    # Create student
   # studentUser = FactoryBot.create(:user, :student)

    # Assign student to the unit
    #newUnit.enrol_student(studentUser, newCampus)

    # The get that we will be testing.
    get with_auth_token "/api/students/?unit_id=#{newUnit.id}", newUnit.main_convenor_user
    #assert_equal expectedStudents.count, last_response_body.count
    #response_keys = %w(first_name last_name student_id project_id)
    #last_response_body.each do | data |
      #pro = Project.find(data['project_id'])
      #assert_json_matches_model(data, pro, response_keys)
    #end
    assert_equal 200, last_response.status
  end

  def test_get_students_without_authentication
    # Create student user
{'fraction_non_alphanumeric': 0.08539839878002288, 'fraction_numerical': 0.002287457110179184, 'mean_word_length': 4.065637065637065, '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': '5083420', 'n_tokens_mistral': 828, 'n_tokens_neox': 803, 'n_words': 182}