Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation/58105 item persistence service #16884

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

apfohl
Copy link
Member

@apfohl apfohl commented Oct 2, 2024

Ticket

OP#58105

What are you trying to accomplish?

PART 1

Implement a service capable of manipulation a hierarchy of items for the custom field of type hierarchy.

  • initialize
  • generate_root
  • insert_item

What approach did you choose and why?

  • Dry::Validation contracts for input checking
  • Dry::Monads for error handling

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

Copy link

github-actions bot commented Oct 2, 2024

Caution

The provided work package version does not match the core version

Details:

Please make sure that:

  • The work package version OR your pull request target branch is correct

Copy link
Member

@Kharonus Kharonus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, we should take care of some small bobs and bits, wdyt?

it "creates a failure result" do
[
{ parent:, label: "A label", short: "" },
{ parent:, label: "A label", short: nil },
Copy link
Member

@Kharonus Kharonus Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 we might have a problem with that case. If I interpret the usage in the service correct, it will call it, when short is not passed.

Solutions:
a) adapt contract, so that passing nil is allowed, while "" still is forbidden.
b) adapt service to call contract only with non-nil shorts or no short key at all.

To make b) work we would need to create a hash from the method parameters before putting them into the call. something like:

input = {parent:, label:, short:}.compact

CustomFields::Hierarchy::InsertItemContract
  .new
  .call(**input)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

short is indeed passed, having short: nil in the hash actually creates the key in the hash. Therefor you have three cases: short: "", short: nil and no short.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed personally, there is indeed a faulty call from the service. Another test case discovered that.

end

rule(:hierarchy_root) do
key.failure("Hierarchical root already set") unless value.nil?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 change to if value.present? to battle this godless unless :D

end

rule(:field_format) do
key.failure("Custom field must have field format 'hierarchy'") unless value == "hierarchy"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 same here: can we use if value != "hierarchy"?

end
end

context "with invalid hierarchy root" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ I don't understand the test case. So, is this an item object which cannot get persisted?

Maybe renaming it to "if persistence of hierarchy root fails"? Otherwise some transitional head work is needed when reading the test - as in "an invalid hierarchy root will lead to a persistence error". But this is no hill I gonna die upon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants