Skip to content

Commit

Permalink
chore: Create test base project with random UUID by default
Browse files Browse the repository at this point in the history
  • Loading branch information
StaNov authored and StaNov committed Nov 28, 2024
1 parent 7eebb45 commit c265376
Show file tree
Hide file tree
Showing 24 changed files with 77 additions and 91 deletions.
3 changes: 1 addition & 2 deletions backend/app/src/test/kotlin/io/tolgee/AuthTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import io.tolgee.controllers.PublicController
import io.tolgee.fixtures.andAssertThatJson
import io.tolgee.fixtures.andIsForbidden
import io.tolgee.fixtures.andIsUnauthorized
import io.tolgee.fixtures.generateUniqueString
import io.tolgee.fixtures.mapResponseTo
import io.tolgee.model.Project
import io.tolgee.security.authentication.JwtService
Expand Down Expand Up @@ -55,7 +54,7 @@ class AuthTest : AbstractControllerTest() {

@BeforeEach
fun setup() {
project = dbPopulator.createBase(generateUniqueString()).project
project = dbPopulator.createBase().project
authMvc = MockMvcBuilders.standaloneSetup(publicController).setControllerAdvice(ExceptionHandlers()).build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class StartupImportCommandLineRunnerTest : AbstractSpringTest() {
baseLanguageTag = "de"
},
)
base = dbPopulator.createBase("labaala", "admin")
base = dbPopulator.createBase("admin")
startupImportCommandLineRunner.run()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SlugControllerTest : AuthorizedControllerTest() {
Project(
name = "aaa",
slug = "hello-1",
).also { it.organizationOwner = dbPopulator.createBase("proj").organization },
).also { it.organizationOwner = dbPopulator.createBase().organization },
)
performAuthGet("/v2/slug/validate-project/hello-1").andIsOk.andAssertThatJson {
isEqualTo(false)
Expand Down Expand Up @@ -82,7 +82,7 @@ class SlugControllerTest : AuthorizedControllerTest() {
Project(
name = "aaa",
slug = "hello-world",
).also { it.organizationOwner = dbPopulator.createBase("proj").organization },
).also { it.organizationOwner = dbPopulator.createBase().organization },
)
performAuthPost("/v2/slug/generate-project", GenerateSlugDto("Hello world"))
.andIsOk.andAssertThatJson {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ class V2InvitationControllerTest : AuthorizedControllerTest() {

@Test
fun `does not return when has no project permission`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
val project = base.project
userAccount = dbPopulator.createUserIfNotExists("pavol")
performAuthGet("/v2/projects/${project.id}/invitations").andIsNotFound
}

@Test
fun `deletes translate invitation with languages`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
val project = base.project
tolgeeProperties.frontEndUrl = "https://dummyUrl.com"
val invitation = createTranslateInvitation(project)
Expand All @@ -51,7 +51,7 @@ class V2InvitationControllerTest : AuthorizedControllerTest() {

@Test
fun `deletes edit invitation`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
val project = base.project

val invitation =
Expand All @@ -68,7 +68,7 @@ class V2InvitationControllerTest : AuthorizedControllerTest() {

@Test
fun `accepts invitation`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
val project = base.project
val code =
invitationService.create(
Expand All @@ -87,7 +87,7 @@ class V2InvitationControllerTest : AuthorizedControllerTest() {

@Test
fun `accepts translate invitation with languages`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
val project = base.project
val code =
invitationService.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ class V2LanguageControllerTest : ProjectAuthControllerTest("/v2/projects/") {

@Test
fun createLanguage() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
val project = base.project
createLanguageTestValidation(project.id)
createLanguageCorrectRequest(project.id)
}

@Test
fun editLanguage() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
val project = base.project
val en = project.findLanguageOptional("en").orElseThrow { NotFoundException() }
val languageDTO =
Expand Down Expand Up @@ -75,7 +75,7 @@ class V2LanguageControllerTest : ProjectAuthControllerTest("/v2/projects/") {

@Test
fun deleteLanguage() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
val project = base.project
val deutsch = project.findLanguageOptional("de").orElseThrow { NotFoundException() }
performDelete(project.id, deutsch.id).andExpect(MockMvcResultMatchers.status().isOk)
Expand All @@ -88,7 +88,7 @@ class V2LanguageControllerTest : ProjectAuthControllerTest("/v2/projects/") {
@Test
@ProjectApiKeyAuthTestMethod(scopes = [Scope.LANGUAGES_EDIT])
fun `deletes language with API key`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
this.userAccount = base.userAccount
this.projectSupplier = { base.project }
val deutsch = project.findLanguageOptional("de").orElseThrow { NotFoundException() }
Expand All @@ -103,7 +103,7 @@ class V2LanguageControllerTest : ProjectAuthControllerTest("/v2/projects/") {
@Test
@ProjectApiKeyAuthTestMethod(scopes = [Scope.TRANSLATIONS_VIEW])
fun `does not delete language with API key (permissions)`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
this.userAccount = base.userAccount
this.projectSupplier = { base.project }
val deutsch = project.findLanguageOptional("de").orElseThrow { NotFoundException() }
Expand All @@ -114,7 +114,7 @@ class V2LanguageControllerTest : ProjectAuthControllerTest("/v2/projects/") {

@Test
fun `cannot delete base language`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
executeInNewTransaction {
val project = projectService.get(base.project.id)
val en = project.findLanguageOptional("en").orElseThrow { NotFoundException() }
Expand All @@ -129,7 +129,7 @@ class V2LanguageControllerTest : ProjectAuthControllerTest("/v2/projects/") {

@Test
fun `automatically sets base language`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()

val project =
executeInNewTransaction {
Expand All @@ -152,7 +152,7 @@ class V2LanguageControllerTest : ProjectAuthControllerTest("/v2/projects/") {

@Test
fun createLanguageTestValidationComa() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
val project = base.project
performCreate(
project.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import io.tolgee.fixtures.andAssertThatJson
import io.tolgee.fixtures.andIsBadRequest
import io.tolgee.fixtures.andIsOk
import io.tolgee.fixtures.andPrettyPrint
import io.tolgee.fixtures.generateUniqueString
import io.tolgee.fixtures.node
import io.tolgee.model.Project
import io.tolgee.model.UserAccount
Expand Down Expand Up @@ -74,7 +73,7 @@ class V2ImportControllerAddFilesTest : ProjectAuthControllerTest("/v2/projects/"
@Test
fun `it parses zip file stores it for debugging and saves issues`() {
tolgeeProperties.import.storeFilesForDebugging = true
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
commitTransaction()

val fileName = "zipOfUnknown.zip"
Expand All @@ -87,7 +86,7 @@ class V2ImportControllerAddFilesTest : ProjectAuthControllerTest("/v2/projects/"

@Test
fun `doesn't store file for when disabled`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
commitTransaction()

val fileName = "zipOfUnknown.zip"
Expand All @@ -105,7 +104,7 @@ class V2ImportControllerAddFilesTest : ProjectAuthControllerTest("/v2/projects/"

@Test
fun `it handles po file`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()

performImport(projectId = base.project.id, listOf(Pair("example.po", poFile)))
.andPrettyPrint.andAssertThatJson {
Expand All @@ -125,7 +124,7 @@ class V2ImportControllerAddFilesTest : ProjectAuthControllerTest("/v2/projects/"

@Test
fun `it handles xliff file`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()

performImport(projectId = base.project.id, listOf(Pair("example.xliff", xliffFile)))
.andPrettyPrint.andAssertThatJson {
Expand All @@ -135,7 +134,7 @@ class V2ImportControllerAddFilesTest : ProjectAuthControllerTest("/v2/projects/"

@Test
fun `it returns error when json could not be parsed`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()

performImport(projectId = base.project.id, listOf(Pair("error.json", errorJson)))
.andIsOk.andAssertThatJson {
Expand All @@ -147,7 +146,7 @@ class V2ImportControllerAddFilesTest : ProjectAuthControllerTest("/v2/projects/"

@Test
fun `it throws when more then 100 languages`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()

val data = (1..101).map { "simple$it.json" to simpleJson }

Expand Down Expand Up @@ -175,7 +174,7 @@ class V2ImportControllerAddFilesTest : ProjectAuthControllerTest("/v2/projects/"

@Test
fun `it imports nested keys with provided delimiter`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()

performImport(projectId = base.project.id, listOf("nested.json" to nested), mapOf("structureDelimiter" to ";"))
.andIsOk
Expand All @@ -189,7 +188,7 @@ class V2ImportControllerAddFilesTest : ProjectAuthControllerTest("/v2/projects/"

@Test
fun `it saves proper data and returns correct response`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
commitTransaction()

performImport(projectId = base.project.id, listOf(Pair("zipOfJsons.zip", zipOfJsons)))
Expand All @@ -201,7 +200,7 @@ class V2ImportControllerAddFilesTest : ProjectAuthControllerTest("/v2/projects/"

@Test
fun `it adds a file with long translation text and stores issues`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
commitTransaction()
tolgeeProperties.maxTranslationTextLength = 20

Expand All @@ -224,7 +223,7 @@ class V2ImportControllerAddFilesTest : ProjectAuthControllerTest("/v2/projects/"

@Test
fun `gracefully handles missing files part`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
commitTransaction()

executeInNewTransaction {
Expand All @@ -241,7 +240,7 @@ class V2ImportControllerAddFilesTest : ProjectAuthControllerTest("/v2/projects/"

@Test
fun `pre-selects namespaces and languages correctly`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
commitTransaction()
tolgeeProperties.maxTranslationTextLength = 20

Expand All @@ -265,7 +264,7 @@ class V2ImportControllerAddFilesTest : ProjectAuthControllerTest("/v2/projects/"

@Test
fun `works fine with Mac generated zip`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
commitTransaction()
tolgeeProperties.maxTranslationTextLength = 20

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ProjectsControllerCreateTest : AuthorizedControllerTest() {

@BeforeEach
fun setup() {
val base = dbPopulator.createBase("SomeProject", "user")
val base = dbPopulator.createBase("user")
userAccount = base.userAccount
createForLanguagesDto =
CreateProjectRequest(
Expand All @@ -62,7 +62,7 @@ class ProjectsControllerCreateTest : AuthorizedControllerTest() {

@Test
fun createProject() {
dbPopulator.createBase("test")
dbPopulator.createBase()
testCreateValidationSizeShort()
testCreateValidationSizeLong()
testCreateCorrectRequest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.springframework.boot.test.context.SpringBootTest
class ProjectsControllerEditTest : AuthorizedControllerTest() {
@Test
fun `edits project`() {
val base = dbPopulator.createBase("What a project")
val base = dbPopulator.createBase()
val content =
EditProjectRequest(
name = "new name",
Expand All @@ -33,7 +33,7 @@ class ProjectsControllerEditTest : AuthorizedControllerTest() {

@Test
fun `validates project on edit`() {
val base = dbPopulator.createBase("What a project")
val base = dbPopulator.createBase()
val content =
EditProjectRequest(
name = "",
Expand All @@ -46,7 +46,7 @@ class ProjectsControllerEditTest : AuthorizedControllerTest() {

@Test
fun `automatically chooses base language`() {
val base = dbPopulator.createBase("What a project")
val base = dbPopulator.createBase()
val content =
EditProjectRequest(
name = "test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import io.tolgee.fixtures.andGetContentAsString
import io.tolgee.fixtures.andHasErrorMessage
import io.tolgee.fixtures.andIsBadRequest
import io.tolgee.fixtures.andIsOk
import io.tolgee.fixtures.generateUniqueString
import io.tolgee.fixtures.node
import io.tolgee.model.Invitation
import io.tolgee.model.Permission
Expand Down Expand Up @@ -55,7 +54,7 @@ class ProjectsControllerInvitationTest : ProjectAuthControllerTest("/v2/projects

@Test
fun `returns project invitations`() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
val project = base.project
tolgeeProperties.frontEndUrl = "https://dummyUrl.com"
createTranslateInvitation(project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import io.tolgee.fixtures.andIsBadRequest
import io.tolgee.fixtures.andIsNotFound
import io.tolgee.fixtures.andIsOk
import io.tolgee.fixtures.andPrettyPrint
import io.tolgee.fixtures.generateUniqueString
import io.tolgee.fixtures.isPermissionScopes
import io.tolgee.fixtures.node
import io.tolgee.model.Permission
Expand All @@ -26,8 +25,8 @@ class ProjectsControllerTest : ProjectAuthControllerTest("/v2/projects/") {
@Test
fun getAll() {
executeInNewTransaction {
dbPopulator.createBase("one", "kim")
dbPopulator.createBase("two", "kim")
dbPopulator.createBase("kim")
dbPopulator.createBase("kim")

loginAsUser("kim")

Expand Down Expand Up @@ -126,7 +125,7 @@ class ProjectsControllerTest : ProjectAuthControllerTest("/v2/projects/") {

@Test
fun `get single returns permissions`() {
val base = dbPopulator.createBase("one")
val base = dbPopulator.createBase()
userAccount = dbPopulator.createUserIfNotExists("another-user")
permissionService.create(
Permission(
Expand All @@ -145,7 +144,7 @@ class ProjectsControllerTest : ProjectAuthControllerTest("/v2/projects/") {

@Test
fun getNotPermitted() {
val base = dbPopulator.createBase("one")
val base = dbPopulator.createBase()

val account = dbPopulator.createUserIfNotExists("peter")
loginAsUser(account.name)
Expand Down Expand Up @@ -248,7 +247,7 @@ class ProjectsControllerTest : ProjectAuthControllerTest("/v2/projects/") {

@Test
fun revokeUsersAccessOwn() {
val base = dbPopulator.createBase("base", "jirina")
val base = dbPopulator.createBase("jirina")

loginAsUser("jirina")

Expand All @@ -271,7 +270,7 @@ class ProjectsControllerTest : ProjectAuthControllerTest("/v2/projects/") {

@Test
fun deleteProject() {
val base = dbPopulator.createBase(generateUniqueString())
val base = dbPopulator.createBase()
performAuthDelete("/v2/projects/${base.project.id}", null).andIsOk
val project = projectService.find(base.project.id)
Assertions.assertThat(project).isNull()
Expand Down
Loading

0 comments on commit c265376

Please sign in to comment.