2014-06-25 14:35:11 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Jobs::BulkInvite do
|
|
|
|
|
|
|
|
context '.execute' do
|
|
|
|
|
|
|
|
it 'raises an error when the filename is missing' do
|
|
|
|
lambda { Jobs::BulkInvite.new.execute(identifier: '46-discoursecsv', chunks: '1') }.should raise_error(Discourse::InvalidParameters)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an error when the identifier is missing' do
|
|
|
|
lambda { Jobs::BulkInvite.new.execute(filename: 'discourse.csv', chunks: '1') }.should raise_error(Discourse::InvalidParameters)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an error when the chunks is missing' do
|
|
|
|
lambda { Jobs::BulkInvite.new.execute(filename: 'discourse.csv', identifier: '46-discoursecsv') }.should raise_error(Discourse::InvalidParameters)
|
|
|
|
end
|
|
|
|
|
|
|
|
context '.read_csv_file' do
|
2014-06-25 16:04:26 -04:00
|
|
|
let(:user) { Fabricate(:user) }
|
2014-06-25 14:35:11 -04:00
|
|
|
let(:bulk_invite) { Jobs::BulkInvite.new }
|
|
|
|
let(:csv_file) { File.new("#{Rails.root}/spec/fixtures/csv/discourse.csv") }
|
|
|
|
|
|
|
|
it 'reads csv file' do
|
2014-06-25 16:04:26 -04:00
|
|
|
bulk_invite.current_user = user
|
|
|
|
bulk_invite.read_csv_file(csv_file)
|
2014-09-25 11:44:48 -04:00
|
|
|
Invite.where(email: "robin@outlook.com").exists?.should == true
|
2014-06-25 14:35:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-26 11:16:53 -04:00
|
|
|
context '.send_invite' do
|
2014-06-25 14:35:11 -04:00
|
|
|
let(:bulk_invite) { Jobs::BulkInvite.new }
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:group) { Fabricate(:group) }
|
2014-06-26 11:16:53 -04:00
|
|
|
let(:topic) { Fabricate(:topic) }
|
2014-06-25 14:35:11 -04:00
|
|
|
let(:email) { "evil@trout.com" }
|
2014-06-26 11:16:53 -04:00
|
|
|
let(:csv_info) { [] }
|
|
|
|
|
|
|
|
it 'creates an invite' do
|
|
|
|
csv_info[0] = email
|
|
|
|
|
|
|
|
bulk_invite.current_user = user
|
|
|
|
bulk_invite.send_invite(csv_info, 1)
|
2014-09-25 11:44:48 -04:00
|
|
|
Invite.where(email: email).exists?.should == true
|
2014-06-26 11:16:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates an invite with group' do
|
|
|
|
csv_info[0] = email
|
|
|
|
csv_info[1] = group.name
|
2014-06-25 14:35:11 -04:00
|
|
|
|
2014-06-25 16:04:26 -04:00
|
|
|
bulk_invite.current_user = user
|
2014-06-26 11:16:53 -04:00
|
|
|
bulk_invite.send_invite(csv_info, 1)
|
2014-06-25 14:35:11 -04:00
|
|
|
invite = Invite.where(email: email).first
|
|
|
|
invite.should be_present
|
2014-09-25 11:44:48 -04:00
|
|
|
InvitedGroup.where(invite_id: invite.id, group_id: group.id).exists?.should == true
|
2014-06-25 14:35:11 -04:00
|
|
|
end
|
|
|
|
|
2014-06-26 11:16:53 -04:00
|
|
|
it 'creates an invite with topic' do
|
|
|
|
csv_info[0] = email
|
|
|
|
csv_info[2] = topic
|
2014-06-25 14:35:11 -04:00
|
|
|
|
2014-06-25 16:04:26 -04:00
|
|
|
bulk_invite.current_user = user
|
2014-06-26 11:16:53 -04:00
|
|
|
bulk_invite.send_invite(csv_info, 1)
|
|
|
|
invite = Invite.where(email: email).first
|
|
|
|
invite.should be_present
|
2014-09-25 11:44:48 -04:00
|
|
|
TopicInvite.where(invite_id: invite.id, topic_id: topic.id).exists?.should == true
|
2014-06-25 14:35:11 -04:00
|
|
|
end
|
2014-06-26 11:16:53 -04:00
|
|
|
|
|
|
|
it 'creates an invite with group and topic' do
|
|
|
|
csv_info[0] = email
|
|
|
|
csv_info[1] = group.name
|
|
|
|
csv_info[2] = topic
|
|
|
|
|
|
|
|
bulk_invite.current_user = user
|
|
|
|
bulk_invite.send_invite(csv_info, 1)
|
|
|
|
invite = Invite.where(email: email).first
|
|
|
|
invite.should be_present
|
2014-09-25 11:44:48 -04:00
|
|
|
InvitedGroup.where(invite_id: invite.id, group_id: group.id).exists?.should == true
|
|
|
|
TopicInvite.where(invite_id: invite.id, topic_id: topic.id).exists?.should == true
|
2014-06-26 11:16:53 -04:00
|
|
|
end
|
|
|
|
|
2014-06-25 14:35:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|