Skip to content

Commit

Permalink
Additional not working test
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Fałdrowicz committed Sep 6, 2024
1 parent 8fd58c7 commit d6f853e
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
openapi: "3.0.0"
info:
title: Simple API overview
version: 2.0.0
paths:
/customer:
post:
summary: Returns ComponentsBykeys.
requestBody:
description:
Keys of the Customers.
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/MultiKeys'
responses:
'201':
description:
OK
content:
application/json:
schema:
$ref: '#/components/schemas/Customer'

components:
schemas:
MultiKeys:
type: array
minItems: 1
items:
type: object
properties:
primaryKey:
type: string
additionalKey:
type: string
validFor:
type: integer
format: int64
minimum: 1
maximum: 2592000
required:
- primaryKey
- additionalKey
Customer:
type: object
properties:
name:
type: string
category:
type: string
id:
type: integer
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import pl.touk.nussknacker.engine.api.typed.TypedMap
import pl.touk.nussknacker.engine.build.ScenarioBuilder
import pl.touk.nussknacker.engine.flink.test.FlinkSpec
import pl.touk.nussknacker.engine.graph.expression.Expression
import pl.touk.nussknacker.engine.spel
import pl.touk.nussknacker.engine.util.test.{ClassBasedTestScenarioRunner, RunResult, TestScenarioRunner}
import pl.touk.nussknacker.openapi.enrichers.SwaggerEnricher
import pl.touk.nussknacker.openapi.parser.SwaggerParser
Expand Down Expand Up @@ -53,6 +54,11 @@ class OpenApiScenarioIntegrationTest
test(prepareScenarioRunner(port, sttpBackend, _.copy(allowedMethods = List("POST"))))
}

def withRequestBody(sttpBackend: SttpBackend[Future, Any])(test: ClassBasedTestScenarioRunner => Any) =
new StubService("/enrichers-with-optional-fields.yaml").withCustomerService { port =>
test(prepareScenarioRunner(port, sttpBackend, _.copy(allowedMethods = List("POST"))))
}

val stubbedBackend: SttpBackendStub[Future, Any] = SttpBackendStub.asynchronousFuture.whenRequestMatchesPartial {
case request =>
request.headers match {
Expand Down Expand Up @@ -93,6 +99,21 @@ class OpenApiScenarioIntegrationTest
)
}

it should "call enricher with request body" in withRequestBody(stubbedBackend) { testScenarioRunner =>
// given
val data = List("10")
val scenario =
scenarioWithEnricher((SingleBodyParameter.name, """{{additionalKey:"sss", primaryKey:"dfgdf"}}""".spel))

// when
val result = testScenarioRunner.runWithData(scenario, data)

// then
result.validValue shouldBe RunResult.success(
TypedMap(Map("name" -> "Robert Wright", "id" -> 10L, "category" -> "GOLD"))
)
}

it should "call enricher returning string" in withPrimitiveReturnType(
SttpBackendStub.asynchronousFuture.whenRequestMatchesPartial { case _ =>
Response.ok((s""""justAString""""))
Expand Down

0 comments on commit d6f853e

Please sign in to comment.