/
edit_spec.rb
54 lines (46 loc) · 2.31 KB
/
edit_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
require 'rails_helper'
require 'models/form_updater/concerns/checks_core_workflow_examples'
RSpec.describe(FormUpdater::Updater::User::Edit) do
subject(:resolved_result) do
described_class.new(
context: context,
relation_fields: relation_fields,
meta: meta,
data: data,
id: Gql::ZammadSchema.id_from_object(edit_user)
)
end
let(:user) { create(:agent) }
let(:context) { { current_user: user } }
let(:meta) { { initial: true, form_id: SecureRandom.uuid } }
let(:data) { {} }
let(:organization) { create(:organization) }
let(:secondary_organizations) { create_list(:organization, 5) }
let(:edit_user) { create(:user, organization_id: organization.id, organization_ids: secondary_organizations.map(&:id)) }
let(:relation_fields) { [] }
context 'when resolving' do
it 'has permission on the object' do
expect(resolved_result.authorized?).to be true
end
it 'returns secondary organization options for current object in initial request' do
# Triggers the object initialization from the id.
resolved_result.authorized?
expect(resolved_result.resolve).to include(
'organization_ids' => include({
initialValue: secondary_organizations.map(&:id),
options: secondary_organizations.each_with_object([]) do |organization, options|
options << {
value: organization.id,
label: organization.name,
organization: {
active: organization.active,
}
}
end
}),
)
end
end
include_examples 'FormUpdater::ChecksCoreWorkflow', object_name: 'User'
end