<commit_before>package db

import com.gilt.apidoc.v0.models.{ApplicationForm, Version, Visibility}
import com.gilt.apidoc.spec.v0.models.{Application, Organization, Service}
import com.gilt.apidoc.spec.v0.models.json._
import org.scalatest.FlatSpec
import org.junit.Assert._
import java.util.UUID
import play.api.libs.json.{Json, JsObject}

class VersionsDaoSpec extends FlatSpec {

  new play.core.StaticApplication(new java.io.File("."))

  val key = UUID.randomUUID.toString

  private lazy val application = {
    val applicationForm = ApplicationForm(
      name = key,
      key = Some(key),
      description = None,
      visibility = Visibility.Organization
    )
    ApplicationsDao.create(Util.createdBy, Util.testOrg, applicationForm)
  }

  private val OriginalJson = Json.obj("name" -> UUID.randomUUID.toString)

  private lazy val service = Service(
    name = key,
    organization = Organization(key = "test"),
    application = Application(key = key),
    namespace = "test." + key,
    version = "0.0.1-dev",
    headers = Nil,
    imports = Nil,
    enums = Nil,
    models = Nil,
    unions = Nil,
    resources = Nil
  )

  it should "create" in {
    val version = VersionsDao.create(Util.createdBy, application, "1.0.0", OriginalJson, service)
    assertEquals("1.0.0", version.version)
  }

  it should "findByApplicationAndVersion" in {
    VersionsDao.create(Util.createdBy, application, "1.0.1", OriginalJson, service)
    assertEquals(
      Some(service),
      VersionsDao.findByApplicationAndVersion(Authorization.All, application, "1.0.1").map(_.service)
    )
  }

  it should "soft delete" in {
    val version1 = VersionsDao.create(Util.createdBy, application, "1.0.2", OriginalJson, service)
    VersionsDao.softDelete(Util.createdBy, version1)

    val version2 = VersionsDao.create(Util.createdBy, application, "1.0.2", OriginalJson, service)
    assertEquals(version1, version2.copy(guid = version1.guid))
    assertNotEquals(version1.guid, version2.guid)
  }

}<commit_msg>Convert to flat spec api<commit_after>package db

import com.gilt.apidoc.v0.models.{ApplicationForm, Version, Visibility}
import com.gilt.apidoc.spec.v0.models.{Application, Organization, Service}
import com.gilt.apidoc.spec.v0.models.json._
import org.scalatest.{FunSpec, Matchers}
import java.util.UUID
import play.api.libs.json.{Json, JsObject}

class VersionsDaoSpec extends FunSpec with Matchers {

  new play.core.StaticApplication(new java.io.File("."))

  val applicationKey = "test-" + UUID.randomUUID.toString

  private lazy val application = {
    val applicationForm = ApplicationForm(
      name = applicationKey,
      key = Some(applicationKey),
      description = None,
      visibility = Visibility.Organization
    )
    ApplicationsDao.create(Util.createdBy, Util.testOrg, applicationForm)
  }

  private val OriginalJson = Json.obj("name" -> UUID.randomUUID.toString)

  private lazy val service = Service(
    name = applicationKey,
    organization = Organization(key = "test"),
    application = Application(key = applicationKey),
    namespace = "test." + key,
    version = "0.0.1-dev",
    headers = Nil,
    imports = Nil,
    enums = Nil,
    models = Nil,
    unions = Nil,
    resources = Nil
  )

  it("create") {
    val version = VersionsDao.create(Util.createdBy, application, "1.0.0", OriginalJson, service)
    version.version should be("1.0.0")
  }

  it("findByApplicationAndVersion") {
    VersionsDao.create(Util.createdBy, application, "1.0.1", OriginalJson, service)
    VersionsDao.findByApplicationAndVersion(Authorization.All, application, "1.0.1").map(_.service) should be(Some(service))
  }

  it("soft delete") {
    val version1 = VersionsDao.create(Util.createdBy, application, "1.0.2", OriginalJson, service)
    VersionsDao.softDelete(Util.createdBy, version1)

    val version2 = VersionsDao.create(Util.createdBy, application, "1.0.2", OriginalJson, service)
    version2.copy(guid = version1.guid) should be(version1)
    version2.guid shouldNot be(version1.guid)
  }

}
{'fraction_non_alphanumeric': 0.12076218757733234, 'fraction_numerical': 0.015837663944568176, 'mean_word_length': 3.8407185628742515, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '3496906', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1281, 'n_words': 274}