Skip to content

feat: Adding unit test OrderEligibility, RmaSubmitService, StatusReso…#32

Merged
SamueleMartini merged 2 commits intomage-os-lab:mainfrom
marcelmtz:feature/tests
Apr 21, 2026
Merged

feat: Adding unit test OrderEligibility, RmaSubmitService, StatusReso…#32
SamueleMartini merged 2 commits intomage-os-lab:mainfrom
marcelmtz:feature/tests

Conversation

@marcelmtz
Copy link
Copy Markdown

@marcelmtz marcelmtz commented Apr 17, 2026

Includes unit testing for RMA, I didn't cover like all cases but the ones I think have higher priority to be validated.
This should handle the issue https://github.com/mage-os-lab/module-rma/issues/

Test/Unit/Service/OrderEligibilityTest.php — 16 tests

isOrderEligible

  • Returns false when module is disabled
  • Returns false when order status is not in the allowlist
  • Returns false when order is outside the return period
  • Returns false when no eligible items remain
  • Returns true when all conditions are met
  • Returns true when return period is set to unlimited (0)

getEligibleItems

  • Skips child items (items with parentItemId)
  • Skips virtual products
  • Skips downloadable products
  • Skips items where available qty is zero (fully requested)
  • Correctly deducts already-requested qty from available qty
  • Returns the correct data structure (all 6 fields)
  • Includes configurable products
  • Filters correctly across a mixed set of item types

Test/Unit/Service/RmaSubmitServiceTest.php — 12 tests

getSelectedItems

  • Filters out unselected items (selected = '')
  • Filters out items with zero qty
  • Filters out items with negative qty
  • Returns correct structure (condition_id nullable, keys are int order item IDs)
  • Returns empty array on empty input

createRma

  • Throws LocalizedException when reasonId is missing
  • Throws LocalizedException when resolutionTypeId is missing
  • Throws LocalizedException when no matching status is found
  • Queries for new_request status when auto-approve is disabled
  • Queries for approved status when auto-approve is enabled
  • Rolls back the DB transaction on exception, never calls commit()

saveItems

  • Throws LocalizedException when item ID is not in the eligible list
  • Throws LocalizedException when requested qty exceeds available qty
  • Calls itemRepository->save() for each valid selected item

Test/Unit/Model/RMA/StatusResolverTest.php — 7 tests

getCodeById

  • Fetches from repository on cache miss
  • Returns cached value on subsequent calls (repository called once total)
  • Returns null gracefully on NoSuchEntityException

getIdByCode

  • Fetches via getList and returns the first result's ID
  • Returns cached value on subsequent calls (no second getList call)
  • Returns null when no results are found
  • Reuses cache populated by a prior getCodeById call via array_flip — getList never called

@marcelmtz marcelmtz marked this pull request as ready for review April 17, 2026 22:04
@marcelmtz marcelmtz mentioned this pull request Apr 17, 2026
…railing slash on the absolute paths for attachments
@SamueleMartini SamueleMartini merged commit aa45f4d into mage-os-lab:main Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants