Skip to content

Commit

Permalink
chore: added temp logging and a realistic unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanskodje committed Jun 26, 2024
1 parent 9150e3d commit 95b6cfe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,27 @@ class CpaSyncService(private val cpaRepoClient: HttpClient, private val nfsConne
lastModified: Instant,
cpaTimestamps: Map<String, String>
): Boolean {
return cpaTimestamps
.filterKeys { cpaId -> filename.contains(cpaId.replace(":", ".")) }
.filterValues { timestamp -> lastModified.toString() == timestamp }
.ifEmpty {
log.info("Could not find matching timestamp for file $filename with lastModified timestamp $lastModified")
return false
}.any()
// return cpaTimestamps
// .filterKeys { cpaId -> filename.contains(cpaId.replace(":", ".")) }
// .filterValues { timestamp -> lastModified.toString() == timestamp }
// .ifEmpty {
// log.info("Could not find matching timestamp for file $filename with lastModified timestamp $lastModified")
// return false
// }.any()

val filteredByCpaId = cpaTimestamps.filterKeys { cpaId -> filename.contains(cpaId.replace(":", ".")) }
if (filteredByCpaId.isEmpty()) {
log.info("Could not find matching filename in cpaTimestamps: $filename, will not skip")
return false
}

val hasMatchingTimestamp = filteredByCpaId.any { (_, timestamp) -> lastModified.toString() == timestamp }

if (!hasMatchingTimestamp) {
log.info("No matching timestamp found for file $filename with lastModified timestamp $lastModified. Will not skip. Available timestamps: ${filteredByCpaId.values}")
}

return hasMatchingTimestamp
}

internal suspend fun deleteStaleCpaEntries(cpaTimestamps: Map<String, String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,19 @@ class CpaSyncServiceTest {
val shouldSkip = cpaSyncService.shouldSkipFile(filename, lastModified, cpaTimestamps)

assertFalse(shouldSkip)
assertTrue(cpaTimestamps.isNotEmpty())
}

@Test
fun `shouldSkipFile should return true (skip) if the filename is found and we have a matching timestamp`() {
val filename = "nav.10086.xml"
val lastModified = Instant.parse("2022-12-30T20:14:50Z")
val cpaTimestamps = mutableMapOf("nav:10086" to "2022-12-30T20:14:50Z")
val mockedNFSConnector = mockNFSConnector(emptyList())
cpaSyncService = spyk(CpaSyncService(cpaRepoClient, mockedNFSConnector))

val shouldSkip = cpaSyncService.shouldSkipFile(filename, lastModified, cpaTimestamps)

assertTrue(shouldSkip)
}

@Test
Expand All @@ -224,7 +236,6 @@ class CpaSyncServiceTest {
val shouldSkip = cpaSyncService.shouldSkipFile(filename, lastModified, cpaTimestamps)

assertTrue(shouldSkip)
assertTrue(cpaTimestamps.isNotEmpty())
}

@Test
Expand Down

0 comments on commit 95b6cfe

Please sign in to comment.