Skip to content

Commit 26913bf

Browse files
committed
Release: 0.42.4
- `revUp` override to accept vararg Kicks - Rename TestsJs to PostResJs everywhere Signed-off-by: Gopal S Akshintala <[email protected]>
1 parent cb601a5 commit 26913bf

File tree

9 files changed

+58
-35
lines changed

9 files changed

+58
-35
lines changed

README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ endif::[]
1818
:pmtemplates: src/integrationTest/resources/pm-templates
1919
:imagesdir: docs/images
2020
:prewrap!:
21-
:revoman-version: 0.42.3.1
21+
:revoman-version: 0.42.4
2222

2323
'''
2424

buildSrc/src/main/kotlin/Config.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
* ************************************************************************************************
77
*/
88
const val GROUP_ID = "com.salesforce.revoman"
9-
const val VERSION = "0.42.3.1"
9+
const val VERSION = "0.42.4"
1010
const val ARTIFACT_ID = "revoman"
1111
const val STAGING_PROFILE_ID = "1ea0a23e61ba7d"

src/main/kotlin/com/salesforce/revoman/ReVoman.kt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import arrow.core.merge
1414
import com.salesforce.revoman.input.bufferFileInResources
1515
import com.salesforce.revoman.input.config.Kick
1616
import com.salesforce.revoman.internal.exe.deepFlattenItems
17+
import com.salesforce.revoman.internal.exe.executePostResJS
1718
import com.salesforce.revoman.internal.exe.executePreReqJS
18-
import com.salesforce.revoman.internal.exe.executeTestsJS
1919
import com.salesforce.revoman.internal.exe.fireHttpRequest
2020
import com.salesforce.revoman.internal.exe.postHookExe
2121
import com.salesforce.revoman.internal.exe.preHookExe
@@ -43,6 +43,23 @@ import org.http4k.core.Request
4343
import org.http4k.format.ConfigurableMoshi
4444

4545
object ReVoman {
46+
@JvmStatic
47+
@OptIn(ExperimentalStdlibApi::class)
48+
fun revUp(vararg kicks: Kick): List<Rundown> =
49+
kicks
50+
.fold(mapOf<String, String>() to listOf<Rundown>()) { (accumulatedMutableEnv, rundowns), kick
51+
->
52+
val rundown =
53+
revUp(
54+
kick.overrideDynamicEnvironments(
55+
kick.dynamicEnvironmentsFlattened(),
56+
accumulatedMutableEnv
57+
)
58+
)
59+
rundown.mutableEnv.mutableEnvCopyWithValuesOfType<String>() to (rundowns + rundown)
60+
}
61+
.second
62+
4663
@JvmStatic
4764
@OptIn(ExperimentalStdlibApi::class)
4865
fun revUp(kick: Kick): Rundown {
@@ -101,7 +118,7 @@ object ReVoman {
101118
pm.rundown =
102119
Rundown(stepReports + preStepReport, kick.haltOnFailureOfTypeExcept(), pm.environment)
103120
pm.environment.putAll(regexReplacer.replaceVariablesInEnv(pm))
104-
val currentStepReport: StepReport = // --------### PRE-REQUEST-JS ###--------
121+
val currentStepReport: StepReport = // --------### PRE-REQ-JS ###--------
105122
executePreReqJS(step, itemWithRegex, pm)
106123
.mapLeft { preStepReport.copy(requestInfo = left(it)) }
107124
.flatMap { // --------### UNMARSHALL-REQUEST ###--------
@@ -133,10 +150,10 @@ object ReVoman {
133150
)
134151
}
135152
}
136-
.flatMap { sr: StepReport -> // --------### TESTS-JS ###--------
153+
.flatMap { sr: StepReport -> // --------### PRE-RES-JS ###--------
137154
pm.currentStepReport = sr
138155
pm.rundown = pm.rundown.copy(stepReports = pm.rundown.stepReports + sr)
139-
executeTestsJS(step, itemWithRegex, pm)
156+
executePostResJS(step, itemWithRegex, pm)
140157
.mapLeft { sr.copy(responseInfo = left(it)) }
141158
.map { sr }
142159
}

src/main/kotlin/com/salesforce/revoman/internal/exe/PMJSEval.kt

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,22 @@ import arrow.core.Either.Right
1212
import com.salesforce.revoman.internal.postman.PostmanSDK
1313
import com.salesforce.revoman.internal.postman.template.Item
1414
import com.salesforce.revoman.internal.postman.template.Request
15-
import com.salesforce.revoman.output.ExeType.PRE_REQUEST_JS
16-
import com.salesforce.revoman.output.ExeType.TESTS_JS
15+
import com.salesforce.revoman.output.ExeType.POST_RES_JS
16+
import com.salesforce.revoman.output.ExeType.PRE_REQ_JS
1717
import com.salesforce.revoman.output.report.Step
1818
import com.salesforce.revoman.output.report.StepReport
19-
import com.salesforce.revoman.output.report.failure.RequestFailure.PreRequestJSFailure
20-
import com.salesforce.revoman.output.report.failure.ResponseFailure.TestsJSFailure
19+
import com.salesforce.revoman.output.report.failure.RequestFailure.PreReqJSFailure
20+
import com.salesforce.revoman.output.report.failure.ResponseFailure.PostResJSFailure
2121

2222
internal fun executePreReqJS(
2323
currentStep: Step,
2424
item: Item,
2525
pm: PostmanSDK
26-
): Either<PreRequestJSFailure, Unit> {
26+
): Either<PreReqJSFailure, Unit> {
2727
val preReqJS = item.event?.find { it.listen == "prerequest" }?.script?.exec?.joinToString("\n")
2828
return if (!preReqJS.isNullOrBlank()) {
29-
runChecked(currentStep, PRE_REQUEST_JS) {
30-
executePreReqJSWithPolyglot(preReqJS, item.request, pm)
31-
}
32-
.mapLeft { PreRequestJSFailure(it, pm.currentStepReport.requestInfo!!.get()) }
29+
runChecked(currentStep, PRE_REQ_JS) { executePreReqJSWithPolyglot(preReqJS, item.request, pm) }
30+
.mapLeft { PreReqJSFailure(it, pm.currentStepReport.requestInfo!!.get()) }
3331
} else {
3432
Right(Unit)
3533
}
@@ -40,18 +38,18 @@ private fun executePreReqJSWithPolyglot(preReqJS: String, pmRequest: Request, pm
4038
pm.evaluateJS(preReqJS)
4139
}
4240

43-
internal fun executeTestsJS(
41+
internal fun executePostResJS(
4442
currentStep: Step,
4543
item: Item,
4644
pm: PostmanSDK
47-
): Either<TestsJSFailure, Unit> {
48-
val testsJS = item.event?.find { it.listen == "test" }?.script?.exec?.joinToString("\n")
49-
return if (!testsJS.isNullOrBlank()) {
50-
runChecked(currentStep, TESTS_JS) {
51-
executeTestsJSWithPolyglot(testsJS, item.request, pm.currentStepReport, pm)
45+
): Either<PostResJSFailure, Unit> {
46+
val postResJs = item.event?.find { it.listen == "test" }?.script?.exec?.joinToString("\n")
47+
return if (!postResJs.isNullOrBlank()) {
48+
runChecked(currentStep, POST_RES_JS) {
49+
executePostResJSWithPolyglot(postResJs, item.request, pm.currentStepReport, pm)
5250
}
5351
.mapLeft {
54-
TestsJSFailure(
52+
PostResJSFailure(
5553
it,
5654
pm.currentStepReport.requestInfo!!.get(),
5755
pm.currentStepReport.responseInfo!!.get()
@@ -62,13 +60,13 @@ internal fun executeTestsJS(
6260
}
6361
}
6462

65-
private fun executeTestsJSWithPolyglot(
66-
testsJs: String,
63+
private fun executePostResJSWithPolyglot(
64+
postResJS: String,
6765
pmRequest: Request,
6866
stepReport: StepReport,
6967
pm: PostmanSDK
7068
) {
7169
val httpResponse = stepReport.responseInfo!!.get().httpMsg
7270
pm.setRequestAndResponse(pm.from(pmRequest), httpResponse)
73-
pm.evaluateJS(testsJs, mapOf("responseBody" to httpResponse.bodyString()))
71+
pm.evaluateJS(postResJS, mapOf("responseBody" to httpResponse.bodyString()))
7472
}

src/main/kotlin/com/salesforce/revoman/internal/postman/PostmanSDK.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import org.graalvm.polyglot.Value
2222
import org.http4k.format.ConfigurableMoshi
2323

2424
/**
25-
* SDK to use in TestsJs, to be compatible with the Postman API reference:
25+
* SDK to execute pre-req and post-res js scripts, to be compatible with the Postman API reference:
2626
* https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/
2727
*/
2828
class PostmanSDK(
@@ -66,7 +66,8 @@ class PostmanSDK(
6666
Context.newBuilder("js")
6767
.allowExperimentalOptions(true)
6868
// ! TODO 07 Dec 2024 gopala.akshintala: Using this for core compatability
69-
.allowIO(true)
69+
.allowIO(true)
70+
.allowExperimentalOptions(true)
7071
.options(options)
7172
.allowHostAccess(HostAccess.ALL)
7273
.allowHostClassLookup { true }

src/main/kotlin/com/salesforce/revoman/output/ExeType.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ package com.salesforce.revoman.output
1010
enum class ExeType(private val exeName: String) {
1111
UNMARSHALL_REQUEST("unmarshall-request"),
1212
PRE_HOOK("pre-hook"),
13-
PRE_REQUEST_JS("pre-request-js"),
13+
PRE_REQ_JS("pre-req-js"),
1414
HTTP_REQUEST("http-request"),
1515
HTTP_STATUS("http-status"),
16-
TESTS_JS("tests-js"),
16+
POST_RES_JS("post-res-js"),
1717
UNMARSHALL_RESPONSE("unmarshall-response"),
1818
POST_HOOK("post-hook");
1919

src/main/kotlin/com/salesforce/revoman/output/postman/PostmanEnvironment.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ data class PostmanEnvironment<ValueT : Any?>(
4444
.toMutableMap()
4545
)
4646

47+
inline fun <reified T> mutableEnvCopyWithValuesOfType(): PostmanEnvironment<T> =
48+
mutableEnvCopyWithValuesOfType(T::class.java)
49+
4750
fun <T> mutableEnvCopyWithKeysStartingWith(
4851
type: Class<T>,
4952
vararg prefixes: String
@@ -57,6 +60,10 @@ data class PostmanEnvironment<ValueT : Any?>(
5760
.toMutableMap()
5861
)
5962

63+
inline fun <reified T> mutableEnvCopyWithKeysStartingWith(
64+
vararg prefixes: String
65+
): PostmanEnvironment<T> = mutableEnvCopyWithKeysStartingWith(T::class.java, *prefixes)
66+
6067
fun <T> mutableEnvCopyExcludingKeys(
6168
type: Class<T>,
6269
whiteListKeys: Set<String>

src/main/kotlin/com/salesforce/revoman/output/report/failure/RequestFailure.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
package com.salesforce.revoman.output.report.failure
99

1010
import com.salesforce.revoman.output.ExeType.HTTP_REQUEST
11-
import com.salesforce.revoman.output.ExeType.PRE_REQUEST_JS
11+
import com.salesforce.revoman.output.ExeType.PRE_REQ_JS
1212
import com.salesforce.revoman.output.ExeType.UNMARSHALL_REQUEST
1313
import com.salesforce.revoman.output.report.TxnInfo
1414
import org.http4k.core.Request
1515

1616
sealed class RequestFailure : ExeFailure() {
1717
abstract val requestInfo: TxnInfo<Request>
1818

19-
data class PreRequestJSFailure(
19+
data class PreReqJSFailure(
2020
override val failure: Throwable,
2121
override val requestInfo: TxnInfo<Request>,
2222
) : RequestFailure() {
23-
override val exeType = PRE_REQUEST_JS
23+
override val exeType = PRE_REQ_JS
2424
}
2525

2626
data class UnmarshallRequestFailure(

src/main/kotlin/com/salesforce/revoman/output/report/failure/ResponseFailure.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
package com.salesforce.revoman.output.report.failure
99

10-
import com.salesforce.revoman.output.ExeType.TESTS_JS
10+
import com.salesforce.revoman.output.ExeType.POST_RES_JS
1111
import com.salesforce.revoman.output.ExeType.UNMARSHALL_RESPONSE
1212
import com.salesforce.revoman.output.report.TxnInfo
1313
import org.http4k.core.Request
@@ -17,12 +17,12 @@ sealed class ResponseFailure : ExeFailure() {
1717
abstract val requestInfo: TxnInfo<Request>
1818
abstract val responseInfo: TxnInfo<Response>
1919

20-
data class TestsJSFailure(
20+
data class PostResJSFailure(
2121
override val failure: Throwable,
2222
override val requestInfo: TxnInfo<Request>,
2323
override val responseInfo: TxnInfo<Response>,
2424
) : ResponseFailure() {
25-
override val exeType = TESTS_JS
25+
override val exeType = POST_RES_JS
2626
}
2727

2828
data class UnmarshallResponseFailure(

0 commit comments

Comments
 (0)