2018-10-10 06:09:32 +08:00
|
|
|
# frozen_string_literal: true
|
2018-03-09 21:22:00 +08:00
|
|
|
|
2019-03-13 16:06:48 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2018-03-09 21:22:00 +08:00
|
|
|
describe RepositoryDatatableService do
|
2022-06-07 00:21:57 +08:00
|
|
|
let!(:team) { create :team, created_by: user }
|
2018-03-09 21:22:00 +08:00
|
|
|
let!(:user) { create :user, email: 'user_one@asdf.com' }
|
|
|
|
let!(:repository) do
|
2018-03-09 21:43:12 +08:00
|
|
|
create :repository, name: 'my repo',
|
|
|
|
created_by: user,
|
|
|
|
team: team
|
2018-03-09 21:22:00 +08:00
|
|
|
end
|
|
|
|
let!(:repository_column) do
|
2019-03-13 16:06:48 +08:00
|
|
|
create :repository_column,
|
|
|
|
name: 'My column',
|
|
|
|
data_type: :RepositoryListValue,
|
|
|
|
repository: repository
|
2018-03-09 21:22:00 +08:00
|
|
|
end
|
|
|
|
let!(:repository_state) do
|
2018-04-20 22:31:28 +08:00
|
|
|
RepositoryTableStateService.new(user, repository).create_default_state
|
2018-03-09 21:22:00 +08:00
|
|
|
end
|
|
|
|
let!(:repository_row) do
|
|
|
|
create :repository_row, name: 'A row',
|
|
|
|
repository: repository,
|
|
|
|
created_by: user,
|
|
|
|
last_modified_by: user
|
|
|
|
end
|
|
|
|
let!(:repository_row_two) do
|
|
|
|
create :repository_row, name: 'B row',
|
|
|
|
repository: repository,
|
|
|
|
created_by: user,
|
|
|
|
last_modified_by: user
|
|
|
|
end
|
|
|
|
let!(:list_item) do
|
2018-03-09 21:43:12 +08:00
|
|
|
create :repository_list_item,
|
|
|
|
data: 'bug',
|
|
|
|
repository_column: repository_column,
|
|
|
|
created_by: user,
|
|
|
|
last_modified_by: user
|
2018-03-09 21:22:00 +08:00
|
|
|
end
|
|
|
|
let!(:repository_list_value) do
|
2018-03-09 21:43:12 +08:00
|
|
|
create :repository_list_value,
|
|
|
|
repository_list_item: list_item,
|
|
|
|
created_by: user,
|
|
|
|
last_modified_by: user,
|
|
|
|
repository_cell_attributes: {
|
|
|
|
repository_column: repository_column,
|
|
|
|
repository_row: repository_row
|
|
|
|
}
|
2018-03-09 21:22:00 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'ordering' do
|
|
|
|
it 'is ordered by row name asc' do
|
2022-01-05 02:20:02 +08:00
|
|
|
params = { order:[{ column: '3', dir: 'asc' }],
|
2018-03-09 21:22:00 +08:00
|
|
|
search: { value: '' } }
|
2018-03-09 21:43:12 +08:00
|
|
|
subject = RepositoryDatatableService.new(repository,
|
|
|
|
params,
|
|
|
|
user)
|
2018-03-09 21:22:00 +08:00
|
|
|
expect(subject.repository_rows.first.name).to eq 'A row'
|
|
|
|
expect(subject.repository_rows.last.name).to eq 'B row'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is ordered by row name desc' do
|
2022-01-05 02:20:02 +08:00
|
|
|
params = { order: [{ column: '3', dir: 'desc' }],
|
2018-03-09 21:22:00 +08:00
|
|
|
search: { value: '' } }
|
2018-03-09 21:43:12 +08:00
|
|
|
subject = RepositoryDatatableService.new(repository,
|
|
|
|
params,
|
|
|
|
user)
|
2018-03-09 21:22:00 +08:00
|
|
|
expect(subject.repository_rows.first.name).to eq 'B row'
|
|
|
|
expect(subject.repository_rows.last.name).to eq 'A row'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'search' do
|
|
|
|
before do
|
|
|
|
create :repository_row, name: 'test',
|
|
|
|
repository: repository,
|
|
|
|
created_by: user,
|
|
|
|
last_modified_by: user
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns only the searched entity' do
|
2022-01-05 02:20:02 +08:00
|
|
|
params = { order: [{ column: '4', dir: 'desc' }],
|
2018-03-09 21:22:00 +08:00
|
|
|
search: { value: 'test' } }
|
2018-03-09 21:43:12 +08:00
|
|
|
subject = RepositoryDatatableService.new(repository,
|
|
|
|
params,
|
|
|
|
user)
|
2018-03-09 21:22:00 +08:00
|
|
|
expect(subject.repository_rows.first.name).to eq 'test'
|
2020-01-14 00:17:07 +08:00
|
|
|
expect(subject.repository_rows.length).to eq 1
|
2018-03-09 21:22:00 +08:00
|
|
|
end
|
2022-01-05 02:20:02 +08:00
|
|
|
|
|
|
|
context 'when using advanced filter time presets' do
|
|
|
|
let(:base_params) do
|
|
|
|
{ order: [{ column: '4', dir: 'desc' }], search: { value: '' } }
|
|
|
|
end
|
|
|
|
it 'returns the rows matching "today"' do
|
|
|
|
repository_row.update_column(:created_at, 2.days.ago)
|
|
|
|
today_repository_row = RepositoryRow.create(
|
|
|
|
name: "Today",
|
|
|
|
repository: repository,
|
|
|
|
created_by: user,
|
|
|
|
last_modified_by: user
|
|
|
|
)
|
|
|
|
|
|
|
|
params = base_params.merge(
|
|
|
|
advanced_search: {
|
|
|
|
filter_elements: [{repository_column_id: "added_on", operator: "today"}]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
repository_rows = RepositoryDatatableService.new(repository, params, user).repository_rows
|
|
|
|
expect(repository_rows).to include(today_repository_row)
|
|
|
|
expect(repository_rows).to_not include(repository_row)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the rows matching "yesterday"' do
|
|
|
|
yesterday_repository_row = RepositoryRow.create(
|
|
|
|
name: "Yesterday",
|
|
|
|
repository: repository,
|
|
|
|
created_by: user,
|
|
|
|
last_modified_by: user
|
|
|
|
)
|
|
|
|
|
|
|
|
yesterday_repository_row.update_column(:created_at, 1.day.ago)
|
|
|
|
|
|
|
|
params = base_params.merge(
|
|
|
|
advanced_search: {
|
|
|
|
filter_elements: [{repository_column_id: "added_on", operator: "yesterday"}]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
repository_rows = RepositoryDatatableService.new(repository, params, user).repository_rows
|
|
|
|
expect(repository_rows).to include(yesterday_repository_row)
|
|
|
|
expect(repository_rows).to_not include(repository_row)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the rows matching "last_week"' do
|
|
|
|
last_week_repository_row = RepositoryRow.create(
|
|
|
|
name: "Last week",
|
|
|
|
repository: repository,
|
|
|
|
created_by: user,
|
|
|
|
last_modified_by: user
|
|
|
|
)
|
|
|
|
|
|
|
|
last_week_repository_row.update_column(:created_at, 1.week.ago)
|
|
|
|
|
|
|
|
params = base_params.merge(
|
|
|
|
advanced_search: {
|
|
|
|
filter_elements: [{repository_column_id: "added_on", operator: "last_week"}]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
repository_rows = RepositoryDatatableService.new(repository, params, user).repository_rows
|
|
|
|
expect(repository_rows).to include(last_week_repository_row)
|
|
|
|
expect(repository_rows).to_not include(repository_row)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the rows matching "this_month"' do
|
2022-03-09 21:12:16 +08:00
|
|
|
repository_row.update_column(:created_at, Time.now)
|
2022-01-05 02:20:02 +08:00
|
|
|
previous_month_repository_row = RepositoryRow.create(
|
|
|
|
name: "Last week",
|
|
|
|
repository: repository,
|
|
|
|
created_by: user,
|
|
|
|
last_modified_by: user
|
|
|
|
)
|
|
|
|
|
|
|
|
previous_month_repository_row.update_column(:created_at, 1.month.ago)
|
|
|
|
|
|
|
|
params = base_params.merge(
|
|
|
|
advanced_search: {
|
|
|
|
filter_elements: [{repository_column_id: "added_on", operator: "this_month"}]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
repository_rows = RepositoryDatatableService.new(repository, params, user).repository_rows
|
|
|
|
expect(repository_rows).to include(repository_row)
|
|
|
|
expect(repository_rows).to_not include(previous_month_repository_row)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the rows matching "last_year"' do
|
|
|
|
last_year_repository_row = RepositoryRow.create(
|
|
|
|
name: "Yesterday",
|
|
|
|
repository: repository,
|
|
|
|
created_by: user,
|
|
|
|
last_modified_by: user
|
|
|
|
)
|
|
|
|
|
|
|
|
last_year_repository_row.update_column(:created_at, 1.year.ago)
|
|
|
|
|
|
|
|
params = base_params.merge(
|
|
|
|
advanced_search: {
|
|
|
|
filter_elements: [{repository_column_id: "added_on", operator: "last_year"}]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
repository_rows = RepositoryDatatableService.new(repository, params, user).repository_rows
|
|
|
|
expect(repository_rows).to include(last_year_repository_row)
|
|
|
|
expect(repository_rows).to_not include(repository_row)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the rows matching "this_year"' do
|
|
|
|
last_year_repository_row = RepositoryRow.create(
|
|
|
|
name: "Yesterday",
|
|
|
|
repository: repository,
|
|
|
|
created_by: user,
|
|
|
|
last_modified_by: user
|
|
|
|
)
|
|
|
|
|
|
|
|
last_year_repository_row.update_column(:created_at, 1.year.ago.end_of_year)
|
|
|
|
|
|
|
|
params = base_params.merge(
|
|
|
|
advanced_search: {
|
|
|
|
filter_elements: [{repository_column_id: "added_on", operator: "this_year"}]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
repository_rows = RepositoryDatatableService.new(repository, params, user).repository_rows
|
|
|
|
expect(repository_rows).to_not include(last_year_repository_row)
|
|
|
|
expect(repository_rows).to include(repository_row)
|
|
|
|
end
|
|
|
|
end
|
2018-03-09 21:22:00 +08:00
|
|
|
end
|
|
|
|
end
|