2023-02-22 00:55:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-27 15:07:59 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-04 03:49:53 +00:00
|
|
|
RSpec.describe Invite do
|
2017-11-27 15:07:59 +00:00
|
|
|
describe '#valid_for_use?' do
|
|
|
|
it 'returns true when there are no limitations' do
|
2019-07-26 16:55:33 +00:00
|
|
|
invite = Fabricate(:invite, max_uses: nil, expires_at: nil)
|
2017-11-27 15:07:59 +00:00
|
|
|
expect(invite.valid_for_use?).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true when not expired' do
|
2019-07-26 16:55:33 +00:00
|
|
|
invite = Fabricate(:invite, max_uses: nil, expires_at: 1.hour.from_now)
|
2017-11-27 15:07:59 +00:00
|
|
|
expect(invite.valid_for_use?).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when expired' do
|
2019-07-26 16:55:33 +00:00
|
|
|
invite = Fabricate(:invite, max_uses: nil, expires_at: 1.hour.ago)
|
2017-11-27 15:07:59 +00:00
|
|
|
expect(invite.valid_for_use?).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true when uses still available' do
|
2019-07-26 16:55:33 +00:00
|
|
|
invite = Fabricate(:invite, max_uses: 250, uses: 249, expires_at: nil)
|
2017-11-27 15:07:59 +00:00
|
|
|
expect(invite.valid_for_use?).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when maximum uses reached' do
|
2019-07-26 16:55:33 +00:00
|
|
|
invite = Fabricate(:invite, max_uses: 250, uses: 250, expires_at: nil)
|
|
|
|
expect(invite.valid_for_use?).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when invite creator has been disabled' do
|
|
|
|
invite = Fabricate(:invite, max_uses: nil, expires_at: nil)
|
2020-09-15 12:37:58 +00:00
|
|
|
invite.user.account.suspend!
|
2017-11-27 15:07:59 +00:00
|
|
|
expect(invite.valid_for_use?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|