Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.simprints.infra.eventsync.event.remote.models.session

import androidx.annotation.Keep
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonInclude.Include
import com.simprints.infra.events.event.domain.models.Event
import com.simprints.infra.events.event.domain.models.scope.EventScope
import com.simprints.infra.eventsync.event.remote.models.ApiEvent
Expand All @@ -22,6 +24,7 @@ internal data class ApiEventScope(
val device: ApiDevice,
val databaseInfo: ApiDatabaseInfo,
val location: ApiLocation?,
@JsonInclude(Include.NON_EMPTY)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could add a test to ensure that you have what you want, and if people remove the annotation something will fail

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Added a test.

val projectConfigurationUpdatedAt: String,
val events: List<ApiEvent>,
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.simprints.infra.eventsync.event.remote.models.session

import com.google.common.truth.Truth
import com.simprints.core.tools.json.JsonHelper
import com.simprints.infra.eventsync.event.remote.models.ApiTimestamp
import org.junit.Test

class ApiEventScopeTest {

@Test
fun `projectConfigurationUpdatedAt is not included in JSON when empty`() {
// Arrange
val apiEventScope = ApiEventScope(
id = "testId",
projectId = "testProjectId",
startTime = ApiTimestamp(0),
endTime = null,
endCause = ApiEventScopeEndCause.WORKFLOW_ENDED,
modalities = emptyList(),
sidVersion = "testSidVersion",
libSimprintsVersion = "testLibSimprintsVersion",
language = "testLanguage",
device = ApiDevice("testDeviceId", "testDeviceModel"),
databaseInfo = ApiDatabaseInfo(0, 0),
location = null,
projectConfigurationUpdatedAt = "",
events = emptyList()
)

// Act
val json = JsonHelper.toJson(apiEventScope)

// Assert
Truth.assertThat(json).doesNotContain("projectConfigurationUpdatedAt")
}

@Test
fun `projectConfigurationUpdatedAt is included in JSON when not empty`() {
// Arrange
val apiEventScope = ApiEventScope(
id = "testId",
projectId = "testProjectId",
startTime = ApiTimestamp(0),
endTime = null,
endCause = ApiEventScopeEndCause.WORKFLOW_ENDED,
modalities = emptyList(),
sidVersion = "testSidVersion",
libSimprintsVersion = "testLibSimprintsVersion",
language = "testLanguage",
device = ApiDevice("testDeviceId", "testDeviceModel"),
databaseInfo = ApiDatabaseInfo(0, 0),
location = null,
projectConfigurationUpdatedAt = "123",
events = emptyList()
)

// Act
val json = JsonHelper.toJson(apiEventScope)

// Assert
Truth.assertThat(json).contains("projectConfigurationUpdatedAt")
}
}