Skip to content

Commit

Permalink
add tests to sync classes (#1505)
Browse files Browse the repository at this point in the history
sync/download/ResourceParamsBasedDownloadWorkManagerTest.kt, sync/upload/BundleUploaderTest.kt, /sync/upload/TransactionBundleGeneratorTest.kt

Co-authored-by: Benjamin Mwalimu <dubdabasoduba@gmail.com>
  • Loading branch information
roywanyaga and dubdabasoduba authored Sep 13, 2023
1 parent 87c3437 commit 8c97ba6
Show file tree
Hide file tree
Showing 5 changed files with 420 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,30 +102,30 @@ class ResourceParamsBasedDownloadWorkManager(
throw FHIRException(response.issueFirstRep.diagnostics)
}

return if (response is Bundle && response.type == Bundle.BundleType.SEARCHSET) {
response.link
.firstOrNull { component -> component.relation == "next" }
?.url?.let { next -> urlOfTheNextPagesToDownloadForAResource.add(next) }

response.entry
.map { it.resource }
.also { resources ->
resources
.groupBy { it.resourceType }
.entries.map { map ->
map.value
.filter { it.meta.lastUpdated != null }
.let {
context.saveLastUpdatedTimestamp(
map.key,
it.maxOfOrNull { it.meta.lastUpdated }?.toTimeZoneString()
)
}
}
}
} else {
emptyList()
if ((response !is Bundle || response.type != Bundle.BundleType.SEARCHSET)) {
return emptyList()
}

response.link
.firstOrNull { component -> component.relation == "next" }
?.url?.let { next -> urlOfTheNextPagesToDownloadForAResource.add(next) }

return response.entry
.map { it.resource }
.also { resources ->
resources
.groupBy { it.resourceType }
.entries.map { map ->
map.value
.filter { it.meta.lastUpdated != null }
.let {
context.saveLastUpdatedTimestamp(
map.key,
it.maxOfOrNull { it.meta.lastUpdated }?.toTimeZoneString()
)
}
}
}
}

interface TimestampContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class TransactionBundleGenerator(
httpVerbToUseForCreate: Bundle.HTTPVerb,
httpVerbToUseForUpdate: Bundle.HTTPVerb,
generatedBundleSize: Int,
useETagForUpload: Boolean
useETagForUpload: Boolean,
): TransactionBundleGenerator {

val createFunction =
Expand Down
Loading

0 comments on commit 8c97ba6

Please sign in to comment.