<commit_before>require_relative '../test_helper'

class InvitationsControllerTest < ActionController::TestCase
  def setup
    super
    @controller = Api::V1::InvitationsController.new
    @request.env["devise.mapping"] = Devise.mappings[:api_user]
  end

  test "should accept invitation" do
    u = create_user
    t = create_team
    create_team_user team: t, user: u, role: 'owner'
    u1 = create_user email: '<EMAIL>'
    with_current_user_and_team(u, t) do
      members = {'contributor' => u1.email}
      User.send_user_invitation(members)
    end
    tu =  u1.team_users.last
    token = tu.raw_invitation_token
    get :edit, invitation_token: token, slug: t.slug
    assert_nil tu.reload.invitation_token
  end

  test "should not accept invalid invitation" do
    u = create_user
    t = create_team
    create_team_user team: t, user: u, role: 'owner'
    u1 = create_user email: '<EMAIL>'
    with_current_user_and_team(u, t) do
      members = {'contributor' => u1.email}
      User.send_user_invitation(members)
    end
    tu =  u1.team_users.last
    token = tu.raw_invitation_token
    get :edit, invitation_token: 'invalid-token', slug: t.slug
    assert_not_nil tu.reload.invitation_token
    get :edit, invitation_token: token, slug: 'invalid-slug'
    assert_not_nil tu.reload.invitation_token
  end

end
<commit_msg>Ticket #7060 - add tests for user invitation redirect<commit_after>require_relative '../test_helper'

class InvitationsControllerTest < ActionController::TestCase
  def setup
    super
    @controller = Api::V1::InvitationsController.new
    @request.env["devise.mapping"] = Devise.mappings[:api_user]
  end

  test "should accept invitation" do
    u = create_user
    t = create_team
    create_team_user team: t, user: u, role: 'owner'
    u1 = create_user email: '<EMAIL>'
    with_current_user_and_team(u, t) do
      members = {'contributor' => u1.email}
      User.send_user_invitation(members)
    end
    tu =  u1.team_users.last
    token = tu.raw_invitation_token
    get :edit, invitation_token: token, slug: t.slug
    assert_redirected_to "#{CONFIG['checkdesk_client']}/#{t.slug}"
    assert_nil tu.reload.invitation_token
  end

  test "should not accept invalid invitation" do
    u = create_user
    t = create_team
    create_team_user team: t, user: u, role: 'owner'
    u1 = create_user email: '<EMAIL>'
    with_current_user_and_team(u, t) do
      members = {'contributor' => u1.email}
      User.send_user_invitation(members)
    end
    tu =  u1.team_users.last
    token = tu.raw_invitation_token
    get :edit, invitation_token: 'invalid-token', slug: t.slug
    assert_redirected_to "#{CONFIG['checkdesk_client']}/check/user/invalid-invitation"
    assert_not_nil tu.reload.invitation_token
    get :edit, invitation_token: token, slug: 'invalid-slug'
    assert_not_nil tu.reload.invitation_token
    assert_redirected_to "#{CONFIG['checkdesk_client']}/check/user/invalid-invitation"
  end

end

{'fraction_non_alphanumeric': 0.10252951096121417, 'fraction_numerical': 0.0060708263069139965, 'mean_word_length': 3.7684887459807075, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '2394786', 'n_tokens_mistral': 998, 'n_tokens_neox': 991, 'n_words': 225}