FIX: Count resulting bulk invites correctly (#18461)

Skipped invites were not counted at all and some invites could generate
more than one error and resulted in a grand total that was not equal to
the count of bulk invites.
This commit is contained in:
Bianca Nenciu
2022-10-04 18:41:06 +03:00
committed by GitHub
parent 585c584fdb
commit cf646b2061
3 changed files with 47 additions and 14 deletions

View File

@@ -9,7 +9,7 @@ RSpec.describe Jobs::BulkInvite do
fab!(:topic) { Fabricate(:topic) }
let(:staged_user) { Fabricate(:user, staged: true, active: false) }
let(:email) { 'test@discourse.org' }
let(:invites) { [{ email: staged_user.email }, { email: 'test2@discourse.org' }, { email: 'test@discourse.org', groups: 'GROUP1;group2', topic_id: topic.id }] }
let(:invites) { [{ email: user.email }, { email: staged_user.email }, { email: 'test2@discourse.org' }, { email: 'test@discourse.org', groups: 'GROUP1;group2', topic_id: topic.id }, { email: 'invalid' }] }
it 'raises an error when the invites array is missing' do
expect { Jobs::BulkInvite.new.execute(current_user_id: user.id) }
@@ -34,6 +34,12 @@ RSpec.describe Jobs::BulkInvite do
expect(invite.email).to eq(email)
expect(invite.invited_groups.pluck(:group_id)).to contain_exactly(group1.id, group2.id)
expect(invite.topic_invites.pluck(:topic_id)).to contain_exactly(topic.id)
post = Post.last
expect(post.raw).to include("3 invites")
expect(post.raw).to include("1 skipped")
expect(post.raw).to include("0 warning")
expect(post.raw).to include("1 error")
end
it 'does not create invited groups for automatic groups' do
@@ -47,6 +53,9 @@ RSpec.describe Jobs::BulkInvite do
invite = Invite.last
expect(invite.email).to eq(email)
expect(invite.invited_groups.pluck(:group_id)).to contain_exactly(group1.id)
post = Post.last
expect(post.raw).to include("1 warning")
end
it 'does not create invited groups record if the user can not manage the group' do