Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangpengcheng committed Nov 13, 2020
1 parent 0eb1de9 commit e3c44da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,17 @@ abstract class SimpleHandler extends DocumentHandler {
provider: DocumentProvider)(implicit transid: TransactionId, ec: ExecutionContext): Future[Seq[JsObject]] = {
//Query result from CouchDB have below object structure with actual result in `value` key
//So transform the result to confirm to that structure
val viewResult = JsObject(
"id" -> js.fields("_id"),
"key" -> createKey(ddoc, view, startKey, js),
"value" -> computeView(ddoc, view, js))
val value = computeView(ddoc, view, js)
val viewResult = JsObject("id" -> js.fields("_id"), "key" -> createKey(ddoc, view, startKey, js), "value" -> value)

val result = if (includeDocs) JsObject(viewResult.fields + ("doc" -> js)) else viewResult
Future.successful(Seq(result))
if (includeDocs) value.fields.get("_id") match {
case Some(JsString(id)) if id != js.fields("_id") =>
provider.get(DocId(id)).map { doc =>
Seq(JsObject(viewResult.fields + ("doc" -> doc.getOrElse(js))))
}
case _ =>
Future.successful(Seq(JsObject(viewResult.fields + ("doc" -> js))))
} else Future.successful(Seq(viewResult))
}

/**
Expand Down Expand Up @@ -207,7 +211,7 @@ object WhisksHandler extends SimpleHandler {
val FULL_NAME = "fullname"
private val commonFields = Set("namespace", "name", "version", "publish", "annotations", "updated")
private val actionFields = commonFields ++ Set("limits", "exec.binary")
private val actionVersionFields = commonFields ++ Set("_id")
private val actionVersionFields = commonFields ++ Set("_id", "id")
private val packageFields = commonFields ++ Set("binding")
private val packagePublicFields = commonFields
private val ruleFields = commonFields
Expand Down Expand Up @@ -302,12 +306,9 @@ object WhisksHandler extends SimpleHandler {
}

private def computeActionVersionsView(js: JsObject): JsObject = {
val publish = annotationValue(js, "publish", { v =>
v.convertTo[Boolean]
}, true)

val base = js.fields.filterKeys(actionVersionFields).toMap
JsObject(base + ("publish" -> publish.toJson))
val defaultId = js.fields("namespace") + "/" + js.fields("name") + "/default"
JsObject(base + ("_id" -> JsString(defaultId), "id" -> js.fields("_id")))
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/src/test/scala/system/basic/WskActionTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class WskActionTests extends TestHelpers with WskTestHelpers with JsHelpers with
}

// set the default version
wsk.action.create(name, None, defaultVersion = Some("0.0.2"))
wsk.action.create(name, Some(TestUtils.getTestActionFilename("hello.js")), defaultVersion = Some("0.0.2"))

// invoke the default version
val run = wsk.action.invoke(name, Map("payload" -> "world".toJson))
Expand Down

0 comments on commit e3c44da

Please sign in to comment.