velody/packages/apple/VelodyPersistence/Tests/VelodyPersistenceTests/RemoteTrackDownloadStateStoreTests.swift

39 lines
1.3 KiB
Swift

import Foundation
import XCTest
import VelodyDomain
@testable import VelodyPersistence
final class RemoteTrackDownloadStateStoreTests: XCTestCase {
func testFileDownloadStateStorePersistsAcrossInstances() async throws {
let fileManager = FileManager.default
let tempDirectory = fileManager.temporaryDirectory.appendingPathComponent(
UUID().uuidString,
isDirectory: true
)
let fileURL = tempDirectory.appendingPathComponent("remote-download-states.json")
defer {
try? fileManager.removeItem(at: tempDirectory)
}
let firstStore = try FileRemoteTrackDownloadStateStore(fileURL: fileURL)
let states = [
RemoteTrackDownloadState(
remoteTrackId: "track-123",
assetId: "asset-456",
localFilePath: "/tmp/asset-456.mp3",
downloadedAt: Date(timeIntervalSince1970: 1_000),
downloadStatus: .downloaded,
lastDownloadError: nil
),
]
try await firstStore.saveDownloadStates(states)
let secondStore = try FileRemoteTrackDownloadStateStore(fileURL: fileURL)
let restoredStates = try await secondStore.loadDownloadStates()
XCTAssertEqual(restoredStates, states)
}
}