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

# 42 - Add ExtractJson method - string from json path #43

Merged

Conversation

miroslavpojer
Copy link
Collaborator

  • Introduced method 'string-from-json-path' in group: 'extractJson'.
  • Improved error message in method 'body-contains-text' in group: 'assert'

Closes #42

- Introduced method 'string-from-json-path' in group: 'extractJson'.
- Improved error message in method 'body-contains-text' in group: 'assert'
Copy link

github-actions bot commented Nov 21, 2023

JaCoCo code coverage report - ScAPI

File Coverage [85.19%] 🍏
ExtractJsonResponseActionType.scala 100% 🍏
ExtractJsonResponseAction.scala 92.43% 🍏
AssertionResponseAction.scala 83.5% 🍏
Total Project Coverage 88.37% 🍏

Comment on lines 66 to 79
case StringFromList | StringFromJsonPath =>
val cacheKey = responseAction.params("cacheKey")
val listIndex = responseAction.params("listIndex").toInt
val jsonKey = responseAction.params("jsonKey")
val cacheLevel = responseAction.params("cacheLevel")

stringFromList(response, cacheKey, listIndex, jsonKey, cacheLevel)
action match {
case StringFromList =>
val jsonKey = responseAction.params("jsonKey")
val listIndex = responseAction.params("listIndex").toInt
stringFromList(response, cacheKey, listIndex, jsonKey, cacheLevel)

case StringFromJsonPath =>
val jsonPath = responseAction.params("jsonPath")
stringFromJsonPath(response, jsonPath, cacheKey, cacheLevel)
}
Copy link
Collaborator

@dk1844 dk1844 Nov 21, 2023

Choose a reason for hiding this comment

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

Suggested change
case StringFromList | StringFromJsonPath =>
val cacheKey = responseAction.params("cacheKey")
val listIndex = responseAction.params("listIndex").toInt
val jsonKey = responseAction.params("jsonKey")
val cacheLevel = responseAction.params("cacheLevel")
stringFromList(response, cacheKey, listIndex, jsonKey, cacheLevel)
action match {
case StringFromList =>
val jsonKey = responseAction.params("jsonKey")
val listIndex = responseAction.params("listIndex").toInt
stringFromList(response, cacheKey, listIndex, jsonKey, cacheLevel)
case StringFromJsonPath =>
val jsonPath = responseAction.params("jsonPath")
stringFromJsonPath(response, jsonPath, cacheKey, cacheLevel)
}
case StringFromList =>
val (cacheKey, cacheLevel) = cachingFunctionYieldingTuple()
val jsonKey = responseAction.params("jsonKey")
val listIndex = responseAction.params("listIndex").toInt
stringFromList(response, cacheKey, listIndex, jsonKey, cacheLevel)
case StringFromJsonPath =>
val (cacheKey, cacheLevel) = cachingFunctionYieldingTuple()
val jsonPath = responseAction.params("jsonPath")
stringFromJsonPath(response, jsonPath, cacheKey, cacheLevel)
}

Instead of matching twice just like this, rather match once and repeat one method call common for specific cases.

// e.g. but with a more fitting name :)
def cachingFunctionYieldingTuple() = {
  val cacheKey = responseAction.params("cacheKey")
  val cacheLevel = responseAction.params("cacheLevel")
  (cacheKey, cacheLevel)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you for an improvement idea.
Fixed in commit 66e35c3.

Copy link
Collaborator

@dk1844 dk1844 left a comment

Choose a reason for hiding this comment

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

LGTM, just tiny suggestions

@miroslavpojer miroslavpojer merged commit 048f44b into master Nov 24, 2023
2 checks passed
@miroslavpojer miroslavpojer deleted the feature/42_Add_ExtractJson_method_-_string_from_json_path branch November 24, 2023 09:17
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.

Add ExtractJson method - string from json path
2 participants