Skip to content

Commit

Permalink
fix: More tests & ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar committed Dec 14, 2023
1 parent c9d3c3b commit afb9c99
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class PostgresRunnerConfiguration() {
class PostgresRunnerConfiguration {
@Bean
fun postgresRunner(
postgresAutostartProperties: PostgresAutostartProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,23 @@ class V2ExportControllerTest : ProjectAuthControllerTest("/v2/projects/") {
retries = 10,
exceptionMatcher = { it is ConcurrentModificationException || it is DataIntegrityViolationException }
) {
executeInNewTransaction {
initBaseData()
}
performExport()
performExport()
waitForNotThrowing(pollTime = 50, timeout = 3000) {
verify(postHog, times(1)).capture(any(), eq("EXPORT"), any())
}
setForcedDate(currentDateProvider.date.addDays(1))
performExport()
waitForNotThrowing(pollTime = 50, timeout = 3000) {
verify(postHog, times(2)).capture(any(), eq("EXPORT"), any())
initBaseData()
try {
executeInNewTransaction {
}
performExport()
performExport()
waitForNotThrowing(pollTime = 50, timeout = 3000) {
verify(postHog, times(1)).capture(any(), eq("EXPORT"), any())
}
setForcedDate(currentDateProvider.date.addDays(1))
performExport()
waitForNotThrowing(pollTime = 50, timeout = 3000) {
verify(postHog, times(2)).capture(any(), eq("EXPORT"), any())
}
} finally {
Mockito.reset(postHog)
testDataService.cleanTestData(testData.root)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import io.tolgee.dtos.response.ApiKeyDTO.ApiKeyDTO
import io.tolgee.fixtures.generateUniqueString
import io.tolgee.model.enums.Scope
import io.tolgee.testing.AbstractControllerTest
import io.tolgee.testing.assertions.UserApiAppAction
import io.tolgee.testing.assertions.PakAction
import org.springframework.test.web.servlet.MvcResult
import org.springframework.test.web.servlet.result.MockMvcResultMatchers

@Deprecated("This is too complicated")
abstract class AbstractApiKeyTest : AbstractControllerTest() {
fun performAction(action: UserApiAppAction): MvcResult {
fun performAction(action: PakAction): MvcResult {
return try {
var resultActions = mvc.perform(action.requestBuilder)
if (action.expectedStatus != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import io.tolgee.model.enums.Scope
import io.tolgee.security.authentication.JwtService
import io.tolgee.testing.assert
import io.tolgee.testing.assertions.Assertions
import io.tolgee.testing.assertions.UserApiAppAction
import io.tolgee.testing.assertions.PakAction
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
Expand All @@ -35,7 +35,7 @@ class ProjectApiKeyAuthenticationTest : AbstractApiKeyTest() {
@Test
fun accessWithApiKey_failure() {
val mvcResult = mvc.perform(MockMvcRequestBuilders.get("/v2/projects/translations"))
.andExpect(MockMvcResultMatchers.status().isForbidden).andReturn()
.andExpect(MockMvcResultMatchers.status().isUnauthorized).andReturn()
Assertions.assertThat(mvcResult).error()
}

Expand All @@ -57,14 +57,14 @@ class ProjectApiKeyAuthenticationTest : AbstractApiKeyTest() {
val base = dbPopulator.createBase(generateUniqueString())
val apiKey = apiKeyService.create(base.userAccount, setOf(*Scope.values()), base.project)
performAction(
UserApiAppAction(
PakAction(
apiKey = apiKey.key,
url = "/v2/projects",
expectedStatus = HttpStatus.FORBIDDEN
)
)
mvc.perform(MockMvcRequestBuilders.get("/v2/projects"))
.andIsForbidden
.andIsUnauthorized
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.springframework.test.web.servlet.RequestBuilder
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders

class UserApiAppAction(
class PakAction(
var method: HttpMethod? = null,
var body: Any? = null,
var apiKey: String? = null,
Expand Down

0 comments on commit afb9c99

Please sign in to comment.