Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5025 from corona-warn-app/fix/10452-Recycle-Bin--…
Browse files Browse the repository at this point in the history
…-Missing-Test-certificate-connection-if-test-was-deleted-before-certificate-arrived

Fix/10452: Recycle Bin - Missing Test-certificate connection if test was deleted before certificate arrived
  • Loading branch information
naveeddotio committed Feb 7, 2023
2 parents 442b5dc + 002a077 commit 8b99f2b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,48 @@ class CoronaTestService: CoronaTestServiceProviding {
self.antigenTest.value?.uniqueCertificateIdentifier = uniqueCertificateIdentifier
}
}

setUniqueCertificateIdentifierForRecycleBinItemsIfNeeded(uniqueCertificateIdentifier, from: testCertificateRequest)
}

// For Edge Cases, if a Test Certificate was received, after the Test Result was moved to recycle bin.
// The method sets the Unique Certificate Identifier (UCI) in the corresponding item.
private func setUniqueCertificateIdentifierForRecycleBinItemsIfNeeded(_ uniqueCertificateIdentifier: String, from testCertificateRequest: TestCertificateRequest) {
switch testCertificateRequest.coronaTestType {
case .pcr:
recycleBin.recycledItems.forEach { recycleBinItem in
if case let .userCoronaTest(userCoronaTest) = recycleBinItem.item,
userCoronaTest.registrationToken == testCertificateRequest.registrationToken {

if case let .pcr(userPCRTest) = userCoronaTest {
var userPCRTestValueCopy = userPCRTest
userPCRTestValueCopy.set(uniqueCertificateIdentifier: uniqueCertificateIdentifier)

// Write the item with the UCI
recycleBin.moveToBin(.userCoronaTest(.pcr(userPCRTestValueCopy)))
// Remove the item without the UCI
recycleBin.remove(recycleBinItem)
}
}
}

case .antigen:
recycleBin.recycledItems.forEach { recycleBinItem in
if case let .userCoronaTest(userCoronaTest) = recycleBinItem.item,
userCoronaTest.registrationToken == testCertificateRequest.registrationToken {

if case let .antigen(userAntigenTest) = userCoronaTest {
var userAntigenTestValueCopy = userAntigenTest
userAntigenTestValueCopy.set(uniqueCertificateIdentifier: uniqueCertificateIdentifier)

// Write the item with the UCI
recycleBin.moveToBin(.userCoronaTest(.antigen(userAntigenTestValueCopy)))
// Remove the item without the UCI
recycleBin.remove(recycleBinItem)
}
}
}
}
}

@objc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,7 @@ struct UserAntigenTest: Equatable, Hashable, Codable {
return sampleCollectionDate ?? pointOfCareConsentDate
}

mutating func set(uniqueCertificateIdentifier: String) {
self.uniqueCertificateIdentifier = uniqueCertificateIdentifier
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,8 @@ struct UserPCRTest: Equatable, Hashable, Codable {

var uniqueCertificateIdentifier: String?

mutating func set(uniqueCertificateIdentifier: String) {
self.uniqueCertificateIdentifier = uniqueCertificateIdentifier
}

}

0 comments on commit 8b99f2b

Please sign in to comment.