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

Allow avoiding error returning when updating an llms post meta with the same value as stored in the db #2129

Merged
merged 10 commits into from
May 2, 2022

Conversation

eri-trabiccolo
Copy link
Collaborator

@eri-trabiccolo eri-trabiccolo commented Apr 22, 2022

Description

Fixes #909 and needed to fix gocodebox/lifterlms-rest#222
This PR, aside from some code reorganization, just adds this piece of code:
https://github.com/gocodebox/lifterlms/pull/2129/files#diff-3f0337a1db5180a72d1b5434e90b08b7b0f4b7ee5997ac4dd50efa7b6d3c21a8R1482-R1497

How has this been tested?

existing unit tests (doesn't introduce any drawback since the old behavior is the default one).
working on new unit tests.

Screenshots

Types of changes

New feature (non-breaking change which adds functionality)

Checklist:

  • My code has been tested.
  • My code passes all existing automated tests.
  • My code follows the LifterLMS Coding & Documentation Standards.

@eri-trabiccolo
Copy link
Collaborator Author

@gocodebox/engineering
while I work on unit tests, if you got time, may I have your opinion on the strategy?
Thanks

@eri-trabiccolo eri-trabiccolo changed the title Allow avoiding error returning when updaing an llms post meta with the same value as stored in the db Allow avoiding error returning when updating an llms post meta with the same value as stored in the db Apr 25, 2022
@eri-trabiccolo eri-trabiccolo requested a review from a team April 25, 2022 10:44
@eri-trabiccolo eri-trabiccolo marked this pull request as ready for review April 25, 2022 10:44
Copy link
Contributor

@thomasplevy thomasplevy left a comment

Choose a reason for hiding this comment

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

This looks pretty good to me. This is such a messy area of the codebase that this honestly seems to make it more messy to me but refactoring the code into separate methods is a good step towards making all of this a bit more testable and less fragile to maintain longterm.

I haven't physically run any tests but it looks solid given that existing unit tests are passing and the new tests you've added work. However, I'd like to see a bit more test coverage added here, specifically:

  1. Usage of the new param in set() method isn't covered at all.
  2. empty_data error condition in set_bulk() isn't covered
  3. invalid_data error condition in set_bulk() isn't covered
  4. method is_meta_value_same_as_stored_value() is only tested for scalar values (strings). Tests could be written to test this method directly, ideally with every scalar type and at least one non scalar type being passed in. Using LLMS_Unit_Test_Util::call_private_method() so you can just pass stuff in directly.
  5. You technically did not add anything related to setting post properties but there's no coverage on post properties here (I know other model tests pick it up but it wouldn't be too hard to add some post properties here while you're at it.

includes/abstracts/abstract.llms.post.model.php Outdated Show resolved Hide resolved
Co-authored-by: Thomas Patrick Levy <thomas@gocodebox.com>
@eri-trabiccolo
Copy link
Collaborator Author

eri-trabiccolo commented Apr 28, 2022

This looks pretty good to me. This is such a messy area of the codebase that this honestly seems to make it more messy to me but refactoring the code into separate methods is a good step towards making all of this a bit more testable and less fragile to maintain longterm.

Yeah

I haven't physically run any tests but it looks solid given that existing unit tests are passing and the new tests you've added work. However, I'd like to see a bit more test coverage added here, specifically:

  1. Usage of the new param in set() method isn't covered at all.

True.

  1. empty_data error condition in set_bulk() isn't covered
  2. invalid_data error condition in set_bulk() isn't covered

Yeah, I haven't added unit tests for old code.
Tests added in 58b0165

  1. method is_meta_value_same_as_stored_value() is only tested for scalar values (strings). Tests could be written to test this method directly, ideally with every scalar type and at least one non scalar type being passed in. Using LLMS_Unit_Test_Util::call_private_method() so you can just pass stuff in directly.

You're right.
Tested it un-directly with non scalar types in 184a13c
and improved in 3abbdd9

  1. You technically did not add anything related to setting post properties but there's no coverage on post properties here (I know other model tests pick it up but it wouldn't be too hard to add some post properties here while you're at it.

Because this PR didn't change the behavior on post properties: old code.

I can add more tests coverage though <3

@thomasplevy
Copy link
Contributor

@eri-trabiccolo I realize that you didn't add tests for old code but since you're moving that old code and writing code all around it it's a good opportunity to add some tests to that old code.

@eri-trabiccolo
Copy link
Collaborator Author

Yeah sorry, what I meant was that despite what it looks like the PR introduces very little changes, and those are tested.
But yeah improving the code coverage is always good you're right.

@eri-trabiccolo
Copy link
Collaborator Author

@thomasplevy added various tests.

@thomasplevy thomasplevy merged commit 3597f83 into gocodebox:dev May 2, 2022
@thomasplevy thomasplevy mentioned this pull request May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants