cirandas.net

ref: master

plugins/stoa/test/functional/invite_controller_test.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require 'test_helper'
require_relative '../../../../app/controllers/public/invite_controller'

class InviteControllerTest < ActionController::TestCase

  def setup
    @controller = InviteController.new

    environment = Environment.default
    environment.enabled_plugins = ['StoaPlugin']
    environment.save!
  end

  should 'not enable access to invitation if the user has not an usp_id' do
    Task.create!(:code => 12345678)
    person_without_usp_id = User.create!(:login => 'user-without', :email => 'user-without@example.com', :password => 'test', :password_confirmation => 'test', :person_data => {:invitation_code => 12345678}).person

    login_as(person_without_usp_id.identifier)
    get :invite_friends, :profile => person_without_usp_id.identifier
    assert_response 403
    get :select_friends, :profile => person_without_usp_id.identifier
    assert_response 403
  end

  should 'enable access to invitation if the user has an usp_id' do
    person_with_usp_id = User.create!(:login => 'user-with', :email => 'user-with@example.com', :password => 'test', :password_confirmation => 'test', :person_data => {:usp_id => 12345678}).person

    login_as(person_with_usp_id.identifier)
    get :invite_friends, :profile => person_with_usp_id.identifier
    assert_response 200
    get :select_friends, :profile => person_with_usp_id.identifier, :contact_list => ContactList.create.id
    assert_response 200
  end

  should 'alow invitation even in organizations' do
    person_with_usp_id = User.create!(:login => 'user-with', :email => 'user-with@example.com', :password => 'test', :password_confirmation => 'test', :person_data => {:usp_id => 12345678}).person
    organization = fast_create(Organization)
    organization.add_admin(person_with_usp_id)

    login_as(person_with_usp_id.identifier)
    get :invite_friends, :profile => organization.identifier
    assert_response 200
    get :select_friends, :profile => organization.identifier, :contact_list => ContactList.create.id
    assert_response 200
  end

  should 'search friends profiles by usp_id' do
    person = User.create!(:login => 'john', :email => 'john@example.com', :password => 'test', :password_confirmation => 'test', :person_data => {:usp_id => 12345678}).person
    User.create!(:login => 'joseph', :email => 'joseph@example.com', :password => 'test', :password_confirmation => 'test', :person_data => {:usp_id => 12333333})

    admin = User.create!(:login => 'mary', :email => 'mary@example.com', :password => 'test', :password_confirmation => 'test', :person_data => {:usp_id => 11111111}).person
    organization = fast_create(Organization)
    organization.add_admin(admin)

    login_as(admin.identifier)
    get :search, :profile => organization.identifier, :q => '1234'

    assert_equal [{"id" => person.id, "name" => person.name}].to_json, @response.body
    assert_response 200
  end
end