Commit 24099167 authored by Tom Käsler's avatar Tom Käsler

insert motd test data before tests

add 2 tests for global motd api
parent f66273a7
Pipeline #7891 passed with stages
in 3 minutes and 17 seconds
......@@ -13,7 +13,7 @@ import org.scalatest.BeforeAndAfterEach
class BaseServiceSpec extends FunSpec with Matchers with MigrationConfig with BeforeAndAfterAll with DatabaseConfig
with BaseService with HateoasSpec with SessionApiSpec with QuestionApiSpec with FreetextAnswerApiSpec with ChoiceAnswerApiSpec with CommentApiSpec
with FeaturesApiSpec with TestData {
with FeaturesApiSpec with GlobalMotdApiSpec with TestData {
protected val log: LoggingAdapter = NoLogging
import driver.api._
......@@ -30,5 +30,7 @@ class BaseServiceSpec extends FunSpec with Matchers with MigrationConfig with Be
Await.result(choiceAnswersTable ++= testChoiceAnswers, 10.seconds)
Await.result(commentsTable ++= testComments, 10.seconds)
Await.result(featuresTable ++= testFeatures, 10.seconds)
Await.result(globalMotdsTable ++= testGlobalMotds, 10.seconds)
Await.result(sessionMotdsTable ++= testSessionMotds, 10.seconds)
}
}
package de.thm.arsnova
import de.thm.arsnova.services.BaseService
import de.thm.arsnova.models._
import de.thm.arsnova.api.GlobalMotdApi
import scala.concurrent.Await
import scala.concurrent.duration._
import akka.http.scaladsl.testkit.ScalatestRouteTest
import akka.http.scaladsl.model.{HttpEntity, MediaTypes}
import akka.http.scaladsl.model.StatusCodes._
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
import org.scalatest.{FunSpec, Matchers}
import org.scalatest.concurrent.ScalaFutures
import spray.json._
import java.util.Calendar
trait GlobalMotdApiSpec extends FunSpec with Matchers with ScalaFutures with BaseService with ScalatestRouteTest with Routes
with TestData with GlobalMotdApi {
import de.thm.arsnova.mappings.GlobalMotdJsonProtocol._
val ENDDATEDAYSFROMNOW = 7
describe("Global motd api") {
it("retrieve motd by id") {
Get("/globalmotd/1") ~> globalMotdApi ~> check {
responseAs[JsObject] should be(globalMotdAdapter.toResource(testGlobalMotds.head))
}
}
it("create motd") {
val now = Calendar.getInstance
val startdate = now.getTime.toString
now.add(Calendar.DAY_OF_MONTH, ENDDATEDAYSFROMNOW)
val enddate = now.getTime.toString
val newText = "a new global motd for all"
val newMotd = GlobalMotd(None, startdate, enddate, "newMotd", newText, "all")
val requestEntity = HttpEntity(MediaTypes.`application/json`, newMotd.toJson.toString)
Post("/globalmotd/", requestEntity) ~> globalMotdApi ~> check {
response.status should be(OK)
val newId = Await.result(Unmarshal(response.entity).to[String], 1.second).toLong
val checkMotd = newMotd.copy(id = Some(newId))
Get(s"/globalmotd/${newId}") ~> globalMotdApi ~> check {
responseAs[JsObject] should be(globalMotdAdapter.toResource(checkMotd))
}
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment