2018-09-21 13:06:58 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 18:09:01 +00:00
|
|
|
RSpec.describe GroupLabelsFinder, '#execute' do
|
2018-09-21 13:06:58 +00:00
|
|
|
let!(:group) { create(:group) }
|
2018-09-27 14:19:28 +00:00
|
|
|
let!(:user) { create(:user) }
|
2018-09-21 13:06:58 +00:00
|
|
|
let!(:label1) { create(:group_label, title: 'Foo', description: 'Lorem ipsum', group: group) }
|
|
|
|
let!(:label2) { create(:group_label, title: 'Bar', description: 'Fusce consequat', group: group) }
|
|
|
|
|
|
|
|
it 'returns all group labels sorted by name if no params' do
|
2018-09-27 14:19:28 +00:00
|
|
|
result = described_class.new(user, group).execute
|
2018-09-21 13:06:58 +00:00
|
|
|
|
|
|
|
expect(result.to_a).to match_array([label2, label1])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns all group labels sorted by name desc' do
|
2018-09-27 14:19:28 +00:00
|
|
|
result = described_class.new(user, group, sort: 'name_desc').execute
|
2018-09-21 13:06:58 +00:00
|
|
|
|
|
|
|
expect(result.to_a).to match_array([label2, label1])
|
|
|
|
end
|
|
|
|
|
2018-09-27 14:19:28 +00:00
|
|
|
it 'returns group labels that match search' do
|
|
|
|
result = described_class.new(user, group, search: 'Foo').execute
|
2018-09-21 13:06:58 +00:00
|
|
|
|
|
|
|
expect(result.to_a).to match_array([label1])
|
|
|
|
end
|
|
|
|
|
2018-09-27 14:19:28 +00:00
|
|
|
it 'returns group labels user subscribed to' do
|
|
|
|
label2.subscribe(user)
|
|
|
|
|
|
|
|
result = described_class.new(user, group, subscribed: 'true').execute
|
|
|
|
|
|
|
|
expect(result.to_a).to match_array([label2])
|
|
|
|
end
|
|
|
|
|
2018-09-21 13:06:58 +00:00
|
|
|
it 'returns second page of labels' do
|
2018-09-27 14:19:28 +00:00
|
|
|
result = described_class.new(user, group, page: '2').execute
|
2018-09-21 13:06:58 +00:00
|
|
|
|
|
|
|
expect(result.to_a).to match_array([])
|
|
|
|
end
|
|
|
|
end
|