<commit_before>package code.service

import code.model.Project
import code.test.utils.DbSpec
import net.liftweb.mapper.By
import org.scalatest.{BeforeAndAfter, FunSuite}

class ProjectServiceTest extends FunSuite with DbSpec with BeforeAndAfter {

  before {
    givenSomeProjectData()
  }

  test("Display name of the top level project") {
    assert(ProjectService.getDisplayName(project("top")) == "top")
  }

  test("Display name of the middle level project") {
    assert(ProjectService.getDisplayName(project("middle")) == "top-middle")
  }

  test("Display name of the bottom level project") {
    assert(ProjectService.getDisplayName(project("bottom")) == "top-middle-bottom")
  }

  test("Move bottom project to any parent project") {
    ProjectService.move(project("bottom"), project("any project"))

    assert(ProjectService.getDisplayName(project("bottom")) == "top-any project-bottom")
  }

  test("Move bottom project to root") {
    ProjectService.moveToRoot(project("bottom"))

    assert(ProjectService.getDisplayName(project("bottom")) == "bottom")
  }

  test("The top level project is not empty") {
    assert(!ProjectService.isEmpty(project("top")))
  }

  test("The bottom level project is empty") {
    assert(ProjectService.isEmpty(project("bottom")))
  }

  test("Delete a bottom level project") {
    assert(ProjectService.delete(project("bottom")))
  }

  test("Try to delete a top level project") {
    intercept[IllegalArgumentException] {
      ProjectService.delete(project("top"))
    }
  }

  def givenSomeProjectData(): Unit = {
    Project.create.name("top").save()
    lazy val top = Project.find(By(Project.name, "top"))
    Project.create.name("any project").parent(top).save()
    Project.create.name("middle").parent(top).save()
    lazy val middle = Project.find(By(Project.name, "middle"))
    Project.create.name("bottom").parent(middle).save()
  }
<commit_msg>Fix project service tests.<commit_after>package code.service

import code.model.Project
import code.test.utils.BaseContext
import net.liftweb.mapper.By

class ProjectServiceTest extends BaseContext {

  it("Display name of the top level project") {
    assert(ProjectService.getDisplayName(project("top")) == "top")
  }

  it("Display name of the middle level project") {
    assert(ProjectService.getDisplayName(project("middle")) == "top-middle")
  }

  it("Display name of the bottom level project") {
    assert(ProjectService.getDisplayName(project("bottom")) == "top-middle-bottom")
  }

  it("Move bottom project to any parent project") {
    ProjectService.move(project("bottom"), project("any project"))

    assert(ProjectService.getDisplayName(project("bottom")) == "top-any project-bottom")
  }

  it("Move bottom project to root") {
    ProjectService.moveToRoot(project("bottom"))

    assert(ProjectService.getDisplayName(project("bottom")) == "bottom")
  }

  it("The top level project is not empty") {
    assert(!ProjectService.isEmpty(project("top")))
  }

  it("The bottom level project is empty") {
    assert(ProjectService.isEmpty(project("bottom")))
  }

  it("Delete a bottom level project") {
    assert(ProjectService.delete(project("bottom")))
  }

  it("Try to delete a top level project") {
    intercept[IllegalArgumentException] {
      ProjectService.delete(project("top"))
    }
  }

  given {
    Project.create.name("top").save()
    lazy val top = Project.find(By(Project.name, "top"))
    Project.create.name("any project").parent(top).save()
    Project.create.name("middle").parent(top).save()
    lazy val middle = Project.find(By(Project.name, "middle"))
    Project.create.name("bottom").parent(middle).save()
  }

{'fraction_non_alphanumeric': 0.14687414687414688, 'fraction_numerical': 0.0, 'mean_word_length': 4.602446483180428, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1455338', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1047, 'n_words': 226}