diff --git a/src/test/scala/BaseServiceSpec.scala b/src/test/scala/BaseServiceSpec.scala index ea01f8da89429be5a6dd7a44e3edacba3f231c63..19de8d5c65fdcea277473219b9e0ed79600d1fb6 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 232c90e75190708f01a8c2bf8dd2573dbd7dbcde..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..9601ad588c110c5f5eae6d5b058ee1cef908833c --- /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) + } + } + } + } +}