Skip to content

Commit

Permalink
#1264 WIP improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rriclet committed Feb 25, 2021
1 parent deaefba commit f9b7829
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
59 changes: 29 additions & 30 deletions thehive/app/org/thp/thehive/services/CaseSrv.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package org.thp.thehive.services

import java.util.{Map => JMap}
import java.lang.{Long => JLong}
import akka.actor.ActorRef

import javax.inject.{Inject, Named, Singleton}
import org.apache.tinkerpop.gremlin.process.traversal.{Order, P}
import org.apache.tinkerpop.gremlin.structure.{Graph, Vertex}
import org.thp.scalligraph.auth.{AuthContext, Permission}
Expand All @@ -27,6 +23,9 @@ import org.thp.thehive.services.ShareOps._
import org.thp.thehive.services.TaskOps._
import play.api.libs.json.{JsNull, JsObject, Json}

import java.lang.{Long => JLong}
import java.util.{Map => JMap}
import javax.inject.{Inject, Named, Singleton}
import scala.util.{Failure, Success, Try}

@Singleton
Expand Down Expand Up @@ -317,32 +316,32 @@ class CaseSrv @Inject() (
user <- userSrv.get(EntityIdOrName(authContext.userId)).getOrFail("User")
orga <- organisationSrv.get(authContext.organisation).getOrFail("Organisation")
richCase <- create(mergedCase, Some(user), orga, tags.toSet, Seq(), None, Seq())
_ <- cases.toTry(
get(_)
.tasks
.richTask
.toList
.toTry(shareSrv.shareTask(_, richCase.`case`, orga))
)
_ <- cases.toTry(
get(_)
.observables
.richObservable
.toList
.toTry(shareSrv.shareObservable(_, richCase.`case`, orga))
)
_ <- cases.toTry(
get(_)
.procedure
.toList
.toTry(caseProcedureSrv.create(CaseProcedure(), richCase.`case`, _))
)
_ <- cases.toTry(
get(_)
.richCustomFields
.toList
.toTry(c => createCustomField(richCase.`case`, EntityIdOrName(c.customField.name), c.value, c.order))
)
_ <- cases.toTry { c =>
for {
_ <-
get(c)
.tasks
.richTask
.toList
.toTry(shareSrv.shareTask(_, richCase.`case`, orga))
_ <-
get(c)
.observables
.richObservable
.toList
.toTry(shareSrv.shareObservable(_, richCase.`case`, orga))
_ <-
get(c)
.procedure
.toList
.toTry(caseProcedureSrv.create(CaseProcedure(), richCase.`case`, _))
_ <-
get(c)
.richCustomFields
.toList
.toTry(c => createCustomField(richCase.`case`, EntityIdOrName(c.customField.name), c.value, c.order))
} yield Success(())
}
_ = cases.map(remove(_))
} yield richCase
}
Expand Down
4 changes: 4 additions & 0 deletions thehive/test/org/thp/thehive/services/CaseSrvTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ class CaseSrvTest extends PlaySpecification with TestAppBuilder {
mergedCase.customFields.toSeq.size mustEqual 2
mergedCase.tasks.toSeq.size mustEqual 3
mergedCase.observables.toSeq.size mustEqual 3

app[CaseSrv].get(EntityName("21")).getOrFail("Case") must beAFailedTry
app[CaseSrv].get(EntityName("22")).getOrFail("Case") must beAFailedTry
app[CaseSrv].get(EntityName("23")).getOrFail("Case") must beAFailedTry
}
}
}
Expand Down

0 comments on commit f9b7829

Please sign in to comment.