<commit_before>package com.azavea.rf.api.thumbnail

import java.sql.Timestamp
import java.util.UUID

import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.model.{HttpEntity, ContentTypes}
import akka.http.scaladsl.testkit.{RouteTestTimeout, ScalatestRouteTest}
import akka.http.scaladsl.server.Route
import akka.actor.ActorSystem
import org.scalatest.{Matchers, WordSpec}

import concurrent.duration._

import com.azavea.rf.api.AuthUtils
import com.azavea.rf.database.tables._
import com.azavea.rf.datamodel._
import com.azavea.rf.api.scene._
import com.azavea.rf.api.utils.Config
import com.azavea.rf.api.{DBSpec, Router}

import io.circe._
import io.circe.generic.auto._
import io.circe.syntax._
import de.heikoseeberger.akkahttpcirce.CirceSupport._

import scala.util.{Success, Failure, Try}

class ThumbnailSpec extends WordSpec
    with ThumbnailSpecHelper
    with Matchers
    with ScalatestRouteTest
    with Config
    with Router
    with DBSpec {

  implicit val ec = system.dispatcher
  implicit def database = db
  implicit def default(implicit system: ActorSystem) = RouteTestTimeout(DurationInt(5).second)

  val uuid = new UUID(123456789, 123456789)
  val baseThumbnailRow = Thumbnail(
    uuid,
    new Timestamp(1234687268),
    new Timestamp(1234687268),
    uuid,
    128,
    128,
    uuid,
    "https://website.com",
    ThumbnailSize.Large
  )
  val authHeader = AuthUtils.generateAuthHeader("Default")

  // Alias to baseRoutes to be explicit
  val baseRoutes = routes

  "Creating a row" should {
    "add a row to the table" ignore {
      val result = Thumbnails.insertThumbnail(baseThumbnailRow)
      assert(result === Success)
    }
  }

  "Getting a row" should {
    "return the expected row" ignore {
      assert(Thumbnails.getThumbnail(uuid) === baseThumbnailRow)
    }
  }

  "Updating a row" should {
    "change the expected values" ignore {
      val newThumbnailsRow = Thumbnail(
        uuid,
        new Timestamp(1234687268),
        new Timestamp(1234687268),
        uuid,
        256,
        128,
        uuid,
        "https://website.com",
        ThumbnailSize.Large
      )
      val result = Thumbnails.updateThumbnail(newThumbnailsRow, uuid)
      assert(result === 1)
      Thumbnails.getThumbnail(uuid) map {
        case Some(resp) => assert(resp.widthPx === 256)
        case _ => Failure(new Exception("Field not updated successfully"))
      }
    }
  }

  "Deleting a row" should {
    "remove a row from the table" ignore {
      val result = Thumbnails.deleteThumbnail(uuid)
      assert(result === 1)
    }
  }


  "/api/thumbnails/{uuid}" should {
    "return a 404 for non-existent thumbnail" ignore {
      Get(s"${baseThumbnail}${publicOrgId}") ~> Route.seal(baseRoutes) ~> check {<commit_msg>Remove database method tests from ThumbnailSpec<commit_after>package com.azavea.rf.api.thumbnail

import java.sql.Timestamp
import java.util.UUID

import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.model.{HttpEntity, ContentTypes}
import akka.http.scaladsl.testkit.{RouteTestTimeout, ScalatestRouteTest}
import akka.http.scaladsl.server.Route
import akka.actor.ActorSystem
import org.scalatest.{Matchers, WordSpec}

import concurrent.duration._

import com.azavea.rf.api.AuthUtils
import com.azavea.rf.database.tables._
import com.azavea.rf.datamodel._
import com.azavea.rf.api.scene._
import com.azavea.rf.api.utils.Config
import com.azavea.rf.api.{DBSpec, Router}

import io.circe._
import io.circe.generic.auto._
import io.circe.syntax._
import de.heikoseeberger.akkahttpcirce.CirceSupport._

import scala.util.{Success, Failure, Try}

class ThumbnailSpec extends WordSpec
    with ThumbnailSpecHelper
    with Matchers
    with ScalatestRouteTest
    with Config
    with Router
    with DBSpec {

  implicit val ec = system.dispatcher
  implicit def database = db
  implicit def default(implicit system: ActorSystem) = RouteTestTimeout(DurationInt(5).second)

  val uuid = new UUID(123456789, 123456789)
  val baseThumbnailRow = Thumbnail(
    uuid,
    new Timestamp(1234687268),
    new Timestamp(1234687268),
    uuid,
    128,
    128,
    uuid,
    "https://website.com",
    ThumbnailSize.Large
  )
  val authHeader = AuthUtils.generateAuthHeader("Default")

  // Alias to baseRoutes to be explicit
  val baseRoutes = routes

  "/api/thumbnails/{uuid}" should {
    "return a 404 for non-existent thumbnail" ignore {
      Get(s"${baseThumbnail}${publicOrgId}") ~> Route.seal(baseRoutes) ~> check {
{'fraction_non_alphanumeric': 0.10013321492007105, 'fraction_numerical': 0.02819715808170515, 'mean_word_length': 3.5875763747454177, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3137831', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1505, 'n_words': 331}