Skip to content

Commit

Permalink
chore: Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar committed Dec 28, 2023
1 parent eaffdb9 commit 37448db
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import io.tolgee.fixtures.waitForNotThrowing
import io.tolgee.service.contentDelivery.ContentDeliveryConfigService
import io.tolgee.testing.annotations.ProjectJWTAuthTestMethod
import io.tolgee.testing.assert
import io.tolgee.util.addMinutes
import io.tolgee.util.addSeconds
import net.javacrumbs.jsonunit.assertj.assertThatJson
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
Expand Down Expand Up @@ -144,7 +144,10 @@ class AutomationIntegrationTest : ProjectAuthControllerTest("/v2/projects/") {

mockWebhookResponse(HttpStatus.OK)

currentDateProvider.forcedDate = currentDateProvider.date.addMinutes(60)
verifyWebhookExecuted(testData) {
// webhooks are configured to be retried after 5 seconds
currentDateProvider.forcedDate = currentDateProvider.date.addSeconds(5)
}

verifyWebhookExecuted(testData) {
modifyTranslationData()
Expand All @@ -166,10 +169,10 @@ class AutomationIntegrationTest : ProjectAuthControllerTest("/v2/projects/") {
}

private fun verifyWebhookExecuted(testData: WebhooksTestData, webhookTriggeringCallback: () -> Unit) {
val invocations = Mockito.mockingDetails(webhookRestTemplate).invocations.count()
val invocations = getWebhookRestTemplateInvocationCount()
webhookTriggeringCallback()
waitForNotThrowing {
Mockito.mockingDetails(webhookRestTemplate).invocations.count().assert.isEqualTo(invocations + 1)
getWebhookRestTemplateInvocationCount().assert.isEqualTo(invocations + 1)
val callArguments = Mockito.mockingDetails(webhookRestTemplate).invocations.last().arguments
callArguments[0].assert
.isEqualTo(testData.webhookConfig.self.url)
Expand All @@ -189,6 +192,8 @@ class AutomationIntegrationTest : ProjectAuthControllerTest("/v2/projects/") {
}
}

private fun getWebhookRestTemplateInvocationCount() = Mockito.mockingDetails(webhookRestTemplate).invocations.count()

private fun verifyWebhookSignature(httpEntity: HttpEntity<String>, secret: String) {
val signature = httpEntity.headers["Tolgee-Signature"]
signature.assert.isNotNull
Expand Down

0 comments on commit 37448db

Please sign in to comment.