<commit_before>package spec

import com.outr.arango.ArangoSession
import org.scalatest.{AsyncWordSpec, Matchers}
import io.circe.generic.auto._

class CollectionSpec extends AsyncWordSpec with Matchers {
  "Collections" should {
    "create a new collection" in {
      ArangoSession.default.flatMap { session =>
        val dbSession = session.db("_system")
        val collection = dbSession.collection("test")
        val future = collection.create().map { response =>
          response.error should be(false)
        }
        future.onComplete { _ =>
          session.instance.dispose()
        }
        future
      }
    }
    "insert a document" in {
      ArangoSession.default.flatMap { session =>
        val dbSession = session.db("_system")
        val collection = dbSession.collection("test")
        val future = collection.document.create(User("<NAME>", 30), waitForSync = true, returnNew = true).map { response =>
          response.`new` should be(Some(User("<NAME>", 30)))
        }
        future.onComplete { _ =>
          session.instance.dispose()
        }
        future
      }
    }
    "get collection information" in {
      ArangoSession.default.flatMap { session =>
        val dbSession = session.db("_system")
        val collection = dbSession.collection("test")
        val future = collection.information().map { response =>
          response.name should be("test")
          response.`type` should be(2)
          response.status should be(3)
        }
        future.onComplete { _ =>
          session.instance.dispose()
        }
        future
      }
    }
    "get collection properties" in {
      ArangoSession.default.flatMap { session =>
        val dbSession = session.db("_system")
        val collection = dbSession.collection("test")
        val future = collection.properties().map { response =>
          response.waitForSync should be(false)
        }
        future.onComplete { _ =>
          session.instance.dispose()
        }
        future
      }
    }
    "get collection count" in {
      ArangoSession.default.flatMap { session =>
        val dbSession = session.db("_system")
        val collection = dbSession.collection("test")
        val future = collection.count().map { response =>
          response.name should be("test")
          response.`type` should be(2)
          response.status should be(3)
          response.count should be(1)
        }
        future.onComplete { _ =>
          session.instance.dispose()
        }
        future
      }
    }
    "get collection revision" in {
      ArangoSession.default.flatMap { session =>
        val dbSession = session.db("_system")
        val collection = dbSession.collection("test")
        val future = collection.revision().map { response =>
          response.name should be("test")
          response.`type` should be(2)
          response.status should be(3)
          response.revision shouldNot be("0")
        }
        future.onComplete { _ =>
          session.instance.dispose()
        }
        future
      }
    }
    "list all collections" in {
      ArangoSession.default.flatMap { session =>
        val dbSession = session.db("_system")
        val collection = dbSession.collection("test")
        val future = collection.list().map { response =>
          val collectionNames = response.result.map(_.name).toSet
          collectionNames should be(Set("test"))
        }
        future.onComplete { _ =>
          session.instance.dispose()
        }
        future
      }
    }
    "truncate the collection" in {
      ArangoSession.default.flatMap { session =>
        val dbSession = session.db("_system")
        val collection = dbSession.collection("test")
        val future = collection.truncate().map { response =>
          response.error should be(false)
        }
        future.onComplete { _ =>
          session.instance.dispose()
        }
        future
      }
    }
    "drop the new collection" in {
      ArangoSession.default.flatMap { session =>
        val dbSession = session.db("_system")
        val collection = dbSession.collection("test")
        val future = collection.drop().map { response =>
          response.error should be(false)
        }
        future.onComplete { _ =>
          session.instance.dispose()
        }
        future
      }<commit_msg>Drastically simplified the tests in CollectionSpec.<commit_after>package spec

import com.outr.arango.{ArangoCollection, ArangoDB, ArangoSession}
import org.scalatest.{AsyncWordSpec, Matchers}
import io.circe.generic.auto._

import scala.concurrent.Future

class CollectionSpec extends AsyncWordSpec with Matchers {
  private var session: ArangoSession = _
  private var db: ArangoDB = _
  private var test: ArangoCollection = _

  "Collections" should {
    "create the session" in {
      ArangoSession.default.map { s =>
        session = s
        db = session.db("_system")
        test = db.collection("test")
        s.token shouldNot be("")
      }
    }
    "create a new collection" in {
      test.create().map { response =>
        response.error should be(false)
      }
    }
    "insert a document" in {
      test.document.create(User("<NAME>", 30), waitForSync = true, returnNew = true).map { response =>
        response.`new` should be(Some(User("<NAME>", 30)))
      }
    }
    "get collection information" in {
      test.information().map { response =>
        response.name should be("test")
        response.`type` should be(2)
        response.status should be(3)
      }
    }
    "get collection properties" in {
      test.properties().map { response =>
        response.waitForSync should be(false)
      }
    }
    "get collection count" in {
      test.count().map { response =>
        response.name should be("test")
        response.`type` should be(2)
        response.status should be(3)
        response.count should be(1)
      }
    }
    "get collection revision" in {
      test.revision().map { response =>
        response.name should be("test")
        response.`type` should be(2)
        response.status should be(3)
        response.revision shouldNot be("0")
      }
    }
    "list all collections" in {
      test.list().map { response =>
        val collectionNames = response.result.map(_.name).toSet
        collectionNames should be(Set("test"))
      }
    }
    "truncate the collection" in {
      test.truncate().map { response =>
        response.error should be(false)
      }
    }
    "drop the new collection" in {
      test.drop().map { response =>
        response.error should be(false)
      }
    }
    "dispose the session" in {
      Future {
        session.instance.dispose()
        session.instance.isDisposed should be(true)
      }
{'fraction_non_alphanumeric': 0.1116533569949719, 'fraction_numerical': 0.00354924578527063, 'mean_word_length': 2.1051423324150598, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 44, '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': '4613654', 'n_tokens_mistral': 1838, 'n_tokens_neox': 1822, 'n_words': 428}