forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Maintenance: Ported test/integration/object_manager_test.rb
- Loading branch information
Showing
10 changed files
with
345 additions
and
1,212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
spec/models/object_manager/attribute/object/ticket_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/ | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'ObjectManager::Attribute::Object::Ticket', aggregate_failures: true, db_strategy: :reset do | ||
shared_context 'with ticket attribute setup' do | ||
before { attribute } | ||
|
||
let(:attribute) do | ||
attribute = create(:object_manager_attribute_text) | ||
ObjectManager::Attribute.migration_execute | ||
|
||
attribute | ||
end | ||
let(:ticket) { create(:ticket) } | ||
end | ||
|
||
describe 'add ticket attribute' do | ||
include_context 'with ticket attribute setup' | ||
|
||
it 'is successful' do | ||
ticket.update(attribute.name => 'Bazinga!') | ||
expect(ticket.reload).to have_attributes(attribute.name => 'Bazinga!') | ||
end | ||
end | ||
|
||
describe 'update ticket attribute' do | ||
include_context 'with ticket attribute setup' | ||
|
||
it 'is successful' do | ||
skip 'Missing error handling on edit misconfiguration.' | ||
|
||
ticket.update!(attribute.name => 'Bazinga!') | ||
|
||
attributes = attribute.attributes | ||
attributes.delete('data_option_new') | ||
attributes['data_option'] = { | ||
maxlength: 3, | ||
type: 'text', | ||
null: false, | ||
} | ||
ObjectManager::Attribute.add(attributes.deep_symbolize_keys) | ||
ObjectManager::Attribute.migration_execute | ||
expect { ticket.reload }.not_to raise_error | ||
|
||
new_ticket = create(:ticket).tap { |t| t.update!(attribute.name => 'Bazinga!') } | ||
expect(new_ticket.attributes[attribute.name].length).to be(3) | ||
end | ||
end | ||
|
||
describe 'remove ticket attribute' do | ||
include_context 'with ticket attribute setup' | ||
|
||
it 'is successful' do | ||
ticket.update!(attribute.name => 'Bazinga!') | ||
|
||
attribute_name = attribute.name | ||
ObjectManager::Attribute.remove( | ||
object: 'Ticket', | ||
name: attribute_name | ||
) | ||
ObjectManager::Attribute.migration_execute | ||
expect(ticket.reload.attributes).not_to include(attribute_name) | ||
end | ||
end | ||
end |
32 changes: 32 additions & 0 deletions
32
spec/models/object_manager/attribute/validation/data_types_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/ | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'ObjectManager::Attribute::Validation::DataTypes', aggregate_failures: true do | ||
|
||
%w[ | ||
input | ||
user_autocompletion | ||
checkbox | ||
select | ||
multiselect | ||
tree_select | ||
multi_tree_select | ||
datetime | ||
date | ||
tag | ||
richtext | ||
textarea | ||
integer | ||
autocompletion_ajax | ||
autocompletion_ajax_customer_organization | ||
boolean | ||
user_permission | ||
active | ||
].freeze.each do |data_type| | ||
it "validates #{data_type} data type" do | ||
expect(ObjectManager::Attribute::DATA_TYPES).to include(data_type) | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/ | ||
|
||
require 'rails_helper' | ||
RSpec.describe ObjectManager, aggregate_failures: true, type: :model do | ||
|
||
describe 'class methods' do | ||
describe 'list_objects' do | ||
it 'returns an array of objects' do | ||
expect(described_class.list_objects).to be_an(Array) | ||
expect(described_class.list_objects.sort).to match_array(%w[Group Organization User Ticket TicketArticle]) | ||
end | ||
end | ||
|
||
describe 'list_frontend_objects' do | ||
it 'returns an array of objects' do | ||
expect(described_class.list_frontend_objects).to be_an(Array) | ||
expect(described_class.list_frontend_objects.sort).to match_array(%w[Group Organization User Ticket]) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/ | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'Ticket::Selector', db_strategy: :reset, searchindex: true do | ||
before do | ||
Ticket.destroy_all | ||
attribute | ||
tickets | ||
searchindex_model_reload([Ticket]) | ||
end | ||
|
||
let(:agent) { create(:agent, groups: [Group.first]) } | ||
let(:attribute) do | ||
attribute = create(:object_manager_attribute_text) | ||
ObjectManager::Attribute.migration_execute | ||
|
||
attribute | ||
end | ||
let(:tickets) do | ||
tickets = create_list(:ticket, 10, group: Group.first) | ||
tickets.each_with_index do |ticket, index| | ||
ticket[attribute.name] = index.odd? ? '1st value' : '2nd value' | ||
ticket.save! | ||
end | ||
end | ||
let(:condition) do | ||
{ | ||
"ticket.#{attribute.name}" => { | ||
operator: 'is', | ||
value: '1st value', | ||
}, | ||
} | ||
end | ||
|
||
describe 'select by condition attribute' do | ||
context 'when using the ticket selector' do | ||
it 'is successful' do | ||
ticket_count, = Ticket.selectors(condition, limit: 100) | ||
expect(ticket_count).to eq(5) | ||
end | ||
end | ||
|
||
context 'when using the search index backend' do | ||
it 'is successful' do | ||
result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent }) | ||
expect(result[:count]).to eq(5) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/ | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'Overview with custom attributes', authenticated_as: :authenticate, db_strategy: :reset, type: :system do | ||
let(:attribute) { create(:object_manager_attribute_boolean) } | ||
let(:agent) { create(:agent, groups: [Group.find_by(name: 'Users')]) } | ||
let(:overview) { nil } | ||
let(:ticket) { nil } | ||
|
||
def authenticate | ||
agent | ||
attribute | ||
ObjectManager::Attribute.migration_execute | ||
overview | ||
ticket | ||
|
||
true | ||
end | ||
|
||
before do | ||
visit "ticket/view/#{overview.link}" | ||
end | ||
|
||
context 'when the custom attribute used in a view in an overview' do | ||
let(:overview) do | ||
create(:overview, | ||
view: { s: ['title', 'number', attribute.name], | ||
view_mode_default: 's' }) | ||
end | ||
|
||
it 'shows the custom attribute display description' do | ||
within :active_content do | ||
expect(page).to have_text attribute.display.to_s.upcase | ||
end | ||
end | ||
end | ||
|
||
context 'when the custom attribute is used as condition in an overview' do | ||
let(:overview) do | ||
create(:overview, | ||
condition: { "ticket.#{attribute.name}" => { operator: 'is', value: true } }, | ||
view: { s: ['title', 'number', attribute.name], | ||
view_mode_default: 's' }) | ||
end | ||
|
||
context 'with no ticket with custom attribute value true' do | ||
it 'shows no entries' do | ||
within :active_content do | ||
expect(page).to have_text 'NO ENTRIES' | ||
end | ||
end | ||
end | ||
|
||
context 'with a ticket with custom attribute value true' do | ||
let(:ticket) { create(:ticket, group: Group.find_by(name: 'Users'), attribute.name => true) } | ||
|
||
it 'shows the ticket' do | ||
within :active_content do | ||
expect(page).to have_text attribute.display.to_s.upcase | ||
expect(page).to have_text ticket.title | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.