2015-10-11 17:41:23 +08:00
|
|
|
require 'rails_helper'
|
2014-06-26 02:35:11 +08:00
|
|
|
|
|
|
|
describe Jobs::BulkInvite do
|
|
|
|
|
|
|
|
context '.execute' do
|
|
|
|
|
|
|
|
it 'raises an error when the filename is missing' do
|
2016-12-05 00:06:35 +08:00
|
|
|
user = Fabricate(:user)
|
|
|
|
expect { Jobs::BulkInvite.new.execute(current_user_id: user.id) }.to raise_error(Discourse::InvalidParameters)
|
2014-06-26 02:35:11 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
context '.read_csv_file' do
|
2014-06-26 04:04:26 +08:00
|
|
|
let(:user) { Fabricate(:user) }
|
2014-06-26 02:35:11 +08:00
|
|
|
let(:bulk_invite) { Jobs::BulkInvite.new }
|
2018-01-09 23:03:17 +08:00
|
|
|
let(:csv_file) { "#{Rails.root}/spec/fixtures/csv/discourse.csv" }
|
2014-06-26 02:35:11 +08:00
|
|
|
|
|
|
|
it 'reads csv file' do
|
2014-06-26 04:04:26 +08:00
|
|
|
bulk_invite.current_user = user
|
|
|
|
bulk_invite.read_csv_file(csv_file)
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(Invite.where(email: "robin@outlook.com").exists?).to eq(true)
|
2018-01-09 18:19:41 +08:00
|
|
|
expect(Invite.where(email: "jeff@gmail.com").exists?).to eq(true) # handles BOM
|
2014-06-26 02:35:11 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-26 23:16:53 +08:00
|
|
|
context '.send_invite' do
|
2014-06-26 02:35:11 +08:00
|
|
|
let(:bulk_invite) { Jobs::BulkInvite.new }
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:group) { Fabricate(:group) }
|
2014-06-26 23:16:53 +08:00
|
|
|
let(:topic) { Fabricate(:topic) }
|
2014-06-26 02:35:11 +08:00
|
|
|
let(:email) { "evil@trout.com" }
|
2014-06-26 23:16:53 +08: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-12-31 22:55:03 +08:00
|
|
|
expect(Invite.where(email: email).exists?).to eq(true)
|
2014-06-26 23:16:53 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates an invite with group' do
|
|
|
|
csv_info[0] = email
|
|
|
|
csv_info[1] = group.name
|
2014-06-26 02:35:11 +08:00
|
|
|
|
2014-06-26 04:04:26 +08:00
|
|
|
bulk_invite.current_user = user
|
2014-06-26 23:16:53 +08:00
|
|
|
bulk_invite.send_invite(csv_info, 1)
|
2014-06-26 02:35:11 +08:00
|
|
|
invite = Invite.where(email: email).first
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(invite).to be_present
|
|
|
|
expect(InvitedGroup.where(invite_id: invite.id, group_id: group.id).exists?).to eq(true)
|
2014-06-26 02:35:11 +08:00
|
|
|
end
|
|
|
|
|
2014-06-26 23:16:53 +08:00
|
|
|
it 'creates an invite with topic' do
|
|
|
|
csv_info[0] = email
|
|
|
|
csv_info[2] = topic
|
2014-06-26 02:35:11 +08:00
|
|
|
|
2014-06-26 04:04:26 +08:00
|
|
|
bulk_invite.current_user = user
|
2014-06-26 23:16:53 +08:00
|
|
|
bulk_invite.send_invite(csv_info, 1)
|
|
|
|
invite = Invite.where(email: email).first
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(invite).to be_present
|
|
|
|
expect(TopicInvite.where(invite_id: invite.id, topic_id: topic.id).exists?).to eq(true)
|
2014-06-26 02:35:11 +08:00
|
|
|
end
|
2014-06-26 23:16:53 +08: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
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(invite).to be_present
|
|
|
|
expect(InvitedGroup.where(invite_id: invite.id, group_id: group.id).exists?).to eq(true)
|
|
|
|
expect(TopicInvite.where(invite_id: invite.id, topic_id: topic.id).exists?).to eq(true)
|
2014-06-26 23:16:53 +08:00
|
|
|
end
|
|
|
|
|
2014-06-26 02:35:11 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|