I want to make testable network calls using Swift.
For example, I want to download the latest from AWS if and only if it's version is newer than the downloaded file.
In order to do this I've created a function:
func requestDownloadLinkForAWS() {
DispatchQueue.global(qos: .background).async { [weak self] in
guard let self = self else {return}
// Hard coded download for testing - where will this compatibility file be hosted??
do {
let decoder = JSONDecoder()
if let dataResponse = content.data?[0]
{
if (dataResponse.appMinimumVersion >= appVersionString) && (dataResponse.appTargetVersion >= appVersionString) {
if let version = self.stagingBundle.getVersion()
{
if (version < dataResponse.version) {
self.downloadLatestFileAWS(dataResponse.bucketName, dataResponse.folderName, dataResponse.version)
}
}
}
}
}
} catch let error as NSError {
print ("\(error) 2 error")
}
}
}
Now my self.downloadLatestFileAWS is an async function that I can easily test.
My problem is to test the function above. There is no output here, but I need to test this function. What refactoring could I do to make this testable?