mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
57 lines
1.8 KiB
Ruby
57 lines
1.8 KiB
Ruby
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
|
|
let(:bulk_invite) { Jobs::BulkInvite.new }
|
|
let(:csv_file) { File.new("#{Rails.root}/spec/fixtures/csv/discourse.csv") }
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
it 'reads csv file' do
|
|
bulk_invite.read_csv_file(csv_file, user)
|
|
end
|
|
end
|
|
|
|
context '.send_invite_with_groups' do
|
|
let(:bulk_invite) { Jobs::BulkInvite.new }
|
|
let(:user) { Fabricate(:user) }
|
|
let(:group) { Fabricate(:group) }
|
|
let(:email) { "evil@trout.com" }
|
|
|
|
it 'creates an invite to the group' do
|
|
bulk_invite.send_invite_with_groups(email, group.name, user, 1)
|
|
invite = Invite.where(email: email).first
|
|
invite.should be_present
|
|
InvitedGroup.where(invite_id: invite.id, group_id: group.id).exists?.should be_true
|
|
end
|
|
end
|
|
|
|
context '.send_invite_without_group' do
|
|
let(:bulk_invite) { Jobs::BulkInvite.new }
|
|
let(:user) { Fabricate(:user) }
|
|
let(:email) { "evil@trout.com" }
|
|
|
|
it 'creates an invite' do
|
|
bulk_invite.send_invite_without_group(email, user)
|
|
Invite.where(email: email).exists?.should be_true
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
end
|