From d4c2aefd99dc60101e9329372c7c5ab68b7ea483 Mon Sep 17 00:00:00 2001 From: tekay Date: Mon, 31 Oct 2016 13:47:17 +0100 Subject: [PATCH] add features api spec --- src/test/scala/BaseServiceSpec.scala | 3 +- src/test/scala/FeatureApiSpec.scala | 6 ---- src/test/scala/FeaturesApiSpec.scala | 53 ++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 7 deletions(-) delete mode 100644 src/test/scala/FeatureApiSpec.scala create mode 100644 src/test/scala/FeaturesApiSpec.scala diff --git a/src/test/scala/BaseServiceSpec.scala b/src/test/scala/BaseServiceSpec.scala index ea01f8d..19de8d5 100644 --- a/src/test/scala/BaseServiceSpec.scala +++ b/src/test/scala/BaseServiceSpec.scala @@ -13,7 +13,8 @@ import org.scalatest.BeforeAndAfterEach import utils.DatabaseConfig class BaseServiceSpec extends FunSpec with Matchers with MigrationConfig with BeforeAndAfterAll with DatabaseConfig - with BaseService with SessionApiSpec with QuestionApiSpec with FreetextAnswerApiSpec with ChoiceAnswerApiSpec with CommentApiSpec with TestData { + with BaseService with SessionApiSpec with QuestionApiSpec with FreetextAnswerApiSpec with ChoiceAnswerApiSpec with CommentApiSpec + with FeaturesApiSpec with TestData { protected val log: LoggingAdapter = NoLogging import driver.api._ diff --git a/src/test/scala/FeatureApiSpec.scala b/src/test/scala/FeatureApiSpec.scala deleted file mode 100644 index 232c90e..0000000 --- a/src/test/scala/FeatureApiSpec.scala +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Created by tekay on 31.10.16. - */ -class FeatureApiSpec { - -} diff --git a/src/test/scala/FeaturesApiSpec.scala b/src/test/scala/FeaturesApiSpec.scala new file mode 100644 index 0000000..9601ad5 --- /dev/null +++ b/src/test/scala/FeaturesApiSpec.scala @@ -0,0 +1,53 @@ +import akka.http.scaladsl.testkit.ScalatestRouteTest +import org.scalatest.{FunSpec, Matchers} +import org.scalatest.concurrent.ScalaFutures +import services.BaseService +import models._ +import services.FeaturesService +import spray.json._ +import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ +import akka.http.scaladsl.model.{HttpEntity, MediaTypes} +import akka.http.scaladsl.model.StatusCodes._ + +trait FeaturesApiSpec extends FunSpec with Matchers with ScalaFutures with BaseService with ScalatestRouteTest with Routes with TestData { + import mappings.FeatureJsonProtocol._ + describe("Features api") { + it("retrieve features by id") { + Get("/features/1") ~> featuresApi ~> check { + responseAs[JsObject] should be(testFeatures.head.toJson) + } + } + it("retrieve features for session 1") { + Get("/session/1/features") ~> featuresApi ~> check { + responseAs[JsObject] should be(testFeatures.head.toJson) + } + } + it("create features") { + val postFeature = Features(None, 4, true, true, false, false, true, true, false, false, true, true) + val requestEntity = HttpEntity(MediaTypes.`application/json`, postFeature.toJson.toString) + Post("/features/", requestEntity) ~> featuresApi ~> check { + response.status should be(OK) + } + } + it("update features") { + val feature = testFeatures.head + val putFeature = feature.copy(flashcards = false, jitt = false) + val requestEntity = HttpEntity(MediaTypes.`application/json`, putFeature.toJson.toString) + Put("/features/" + putFeature.id.get, requestEntity) ~> featuresApi ~> check { + response.status should be(OK) + Get("/features/" + putFeature.id.get) ~> featuresApi ~> check { + responseAs[Features] should be(putFeature) + } + } + } + it("delete features") { + val featureId = testFeatures.head.id.get + Delete("/features/" + featureId) ~> featuresApi ~> check { + response.status should be(OK) + Get("/features/" + featureId) ~> featuresApi ~> check { + response.status should be(NotFound) + } + } + } + } +} -- GitLab