Skip to content

Commit

Permalink
chore: fix bad language controller tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar committed Dec 18, 2023
1 parent 166bbc0 commit a1011de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,38 @@ class V2LanguageControllerTest : ProjectAuthControllerTest("/v2/projects/") {

@Test
fun deleteLanguage() {
val base = dbPopulator.createBase(generateUniqueString())
val project = base.project
val deutsch = project.findLanguageOptional("de").orElseThrow { NotFoundException() }
performDelete(project.id, deutsch.id).andExpect(MockMvcResultMatchers.status().isOk)
executeInNewTransaction {
val base = dbPopulator.createBase(generateUniqueString())
val project = base.project
val deutsch = project.findLanguageOptional("de").orElseThrow { NotFoundException() }
performDelete(project.id, deutsch.id).andExpect(MockMvcResultMatchers.status().isOk)
Assertions.assertThat(languageService.findById(deutsch.id)).isEmpty
}
}

@Test
@ProjectApiKeyAuthTestMethod(scopes = [Scope.LANGUAGES_EDIT])
fun `deletes language with API key`() {
val base = dbPopulator.createBase(generateUniqueString())
this.userAccount = base.userAccount
this.projectSupplier = { base.project }
val deutsch = project.findLanguageOptional("de").orElseThrow { NotFoundException() }

performProjectAuthDelete("languages/${deutsch.id}", null)
.andExpect(MockMvcResultMatchers.status().isOk)
executeInNewTransaction {
val base = dbPopulator.createBase(generateUniqueString())
this.userAccount = base.userAccount
this.projectSupplier = { base.project }
val deutsch = project.findLanguageOptional("de").orElseThrow { NotFoundException() }
performProjectAuthDelete("languages/${deutsch.id}", null)
.andExpect(MockMvcResultMatchers.status().isOk)
Assertions.assertThat(languageService.findById(deutsch.id)).isEmpty
}
}

@Test
@ProjectApiKeyAuthTestMethod(scopes = [Scope.TRANSLATIONS_VIEW])
fun `does not delete language with API key (permissions)`() {
val base = dbPopulator.createBase(generateUniqueString())
this.userAccount = base.userAccount
this.projectSupplier = { base.project }
val deutsch = project.findLanguageOptional("de").orElseThrow { NotFoundException() }
executeInNewTransaction {
val base = dbPopulator.createBase(generateUniqueString())
this.userAccount = base.userAccount
this.projectSupplier = { base.project }
val deutsch = project.findLanguageOptional("de").orElseThrow { NotFoundException() }
performProjectAuthDelete("languages/${deutsch.id}", null).andIsForbidden
}
}
Expand Down
4 changes: 2 additions & 2 deletions backend/data/src/main/kotlin/io/tolgee/model/Project.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class Project(

constructor(name: String, description: String? = null, slug: String?, organizationOwner: Organization) :
this(id = 0L, name, description, slug) {
this.organizationOwner = organizationOwner
}
this.organizationOwner = organizationOwner
}

fun findLanguageOptional(tag: String): Optional<Language> {
return languages.stream().filter { l: Language -> (l.tag == tag) }.findFirst()
Expand Down

0 comments on commit a1011de

Please sign in to comment.