按账号与相册隔离相机下载目录,并同步更新传输管道与测试。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -8,36 +8,73 @@ import XCTest
|
||||
|
||||
/// CameraDownloadStorage 相对路径持久化测试。
|
||||
final class CameraDownloadStorageTests: XCTestCase {
|
||||
/// 测试相对路径前缀。
|
||||
func testRelativePathUsesCameraDownloadsPrefix() {
|
||||
let fileURL = CameraDownloadStorage.downloadsDirectory.appendingPathComponent("1730_test.JPG")
|
||||
XCTAssertEqual(CameraDownloadStorage.relativePath(for: fileURL), "CameraDownloads/1730_test.JPG")
|
||||
/// 测试 scoped 原图相对路径前缀。
|
||||
func testRelativePathUsesScopedOriginalsPrefix() {
|
||||
let scope = CameraDownloadStorage.Scope(accountKey: "user_101", albumID: 6603)
|
||||
defer { CameraDownloadStorage.removeScopeDirectory(for: scope) }
|
||||
|
||||
let fileURL = CameraDownloadStorage.originalsDirectory(for: scope).appendingPathComponent("1730_test.JPG")
|
||||
XCTAssertEqual(
|
||||
CameraDownloadStorage.relativePath(for: fileURL),
|
||||
"CameraDownloads/user_101/6603/originals/1730_test.JPG"
|
||||
)
|
||||
}
|
||||
|
||||
/// 测试相对路径解析。
|
||||
func testResolveLocalURLFromRelativePath() {
|
||||
let stored = "CameraDownloads/1730_test.JPG"
|
||||
let stored = "CameraDownloads/user_101/6603/originals/1730_test.JPG"
|
||||
let resolved = CameraDownloadStorage.resolveLocalURL(from: stored)
|
||||
let expected = CameraDownloadStorage.documentsDirectory.appendingPathComponent(stored)
|
||||
XCTAssertEqual(resolved, expected)
|
||||
}
|
||||
|
||||
/// 测试旧版绝对路径迁移。
|
||||
func testMigrateStoredPathFromLegacyAbsolutePath() throws {
|
||||
let fileURL = CameraDownloadStorage.uniqueLocalURL(for: "legacy.jpg")
|
||||
try Data("jpeg".utf8).write(to: fileURL)
|
||||
defer { try? FileManager.default.removeItem(at: fileURL) }
|
||||
/// 测试账号或相册不同不会生成相同目录。
|
||||
func testScopedDirectoriesDoNotCollideAcrossAccountOrAlbum() {
|
||||
let accountScope = CameraDownloadStorage.Scope(accountKey: "user_101", albumID: 6603)
|
||||
let otherAccountScope = CameraDownloadStorage.Scope(accountKey: "user_102", albumID: 6603)
|
||||
let otherAlbumScope = CameraDownloadStorage.Scope(accountKey: "user_101", albumID: 6604)
|
||||
defer {
|
||||
CameraDownloadStorage.removeScopeDirectory(for: accountScope)
|
||||
CameraDownloadStorage.removeScopeDirectory(for: otherAccountScope)
|
||||
CameraDownloadStorage.removeScopeDirectory(for: otherAlbumScope)
|
||||
}
|
||||
|
||||
let migrated = CameraDownloadStorage.migrateStoredPath(fileURL.path)
|
||||
XCTAssertEqual(migrated, "CameraDownloads/\(fileURL.lastPathComponent)")
|
||||
XCTAssertEqual(CameraDownloadStorage.resolveLocalURL(from: migrated ?? "")?.path, fileURL.path)
|
||||
XCTAssertNotEqual(
|
||||
CameraDownloadStorage.originalsDirectory(for: accountScope).path,
|
||||
CameraDownloadStorage.originalsDirectory(for: otherAccountScope).path
|
||||
)
|
||||
XCTAssertNotEqual(
|
||||
CameraDownloadStorage.originalsDirectory(for: accountScope).path,
|
||||
CameraDownloadStorage.originalsDirectory(for: otherAlbumScope).path
|
||||
)
|
||||
}
|
||||
|
||||
/// 测试 scoped 目录清理只影响目标相册。
|
||||
func testRemoveScopeDirectoryOnlyDeletesTargetScope() throws {
|
||||
let scope = CameraDownloadStorage.Scope(accountKey: "user_101", albumID: 6603)
|
||||
let otherScope = CameraDownloadStorage.Scope(accountKey: "user_101", albumID: 6604)
|
||||
defer {
|
||||
CameraDownloadStorage.removeScopeDirectory(for: scope)
|
||||
CameraDownloadStorage.removeScopeDirectory(for: otherScope)
|
||||
}
|
||||
|
||||
let fileURL = CameraDownloadStorage.uniqueLocalURL(for: "target.jpg", scope: scope)
|
||||
let otherFileURL = CameraDownloadStorage.uniqueLocalURL(for: "other.jpg", scope: otherScope)
|
||||
try Data("target".utf8).write(to: fileURL)
|
||||
try Data("other".utf8).write(to: otherFileURL)
|
||||
|
||||
CameraDownloadStorage.removeScopeDirectory(for: scope)
|
||||
|
||||
XCTAssertFalse(FileManager.default.fileExists(atPath: fileURL.path))
|
||||
XCTAssertTrue(FileManager.default.fileExists(atPath: otherFileURL.path))
|
||||
}
|
||||
|
||||
/// 测试预览 URL 字符串生成。
|
||||
func testPreviewURLStringFromRelativePath() throws {
|
||||
let fileURL = CameraDownloadStorage.uniqueLocalURL(for: "preview.jpg")
|
||||
let scope = CameraDownloadStorage.Scope(accountKey: "user_101", albumID: 6603)
|
||||
let fileURL = CameraDownloadStorage.uniqueLocalURL(for: "preview.jpg", scope: scope)
|
||||
try Data("jpeg".utf8).write(to: fileURL)
|
||||
defer { try? FileManager.default.removeItem(at: fileURL) }
|
||||
defer { CameraDownloadStorage.removeScopeDirectory(for: scope) }
|
||||
|
||||
let stored = CameraDownloadStorage.relativePath(for: fileURL)
|
||||
let preview = CameraDownloadStorage.previewURLString(from: stored)
|
||||
|
||||
@ -16,7 +16,9 @@ final class CameraTransferPipelineTests: XCTestCase {
|
||||
let camera = MockCameraService()
|
||||
let sink = MockUploadSink()
|
||||
let pipeline = CameraTransferPipeline(cameraService: camera)
|
||||
pipeline.configure(uploadSink: sink, uploadEnabled: true)
|
||||
let scope = makeScope("new_asset")
|
||||
defer { CameraDownloadStorage.removeScopeDirectory(for: scope) }
|
||||
pipeline.configure(uploadSink: sink, uploadEnabled: true, downloadScope: scope)
|
||||
|
||||
var latestTasks: [CameraTransferTask] = []
|
||||
pipeline.onTasksUpdated = { latestTasks = $0 }
|
||||
@ -30,7 +32,10 @@ final class CameraTransferPipelineTests: XCTestCase {
|
||||
|
||||
XCTAssertEqual(sink.uploadCount, 1)
|
||||
let savedTask = latestTasks.first { $0.assetID == asset.id }
|
||||
XCTAssertEqual(savedTask?.localPath?.hasPrefix("CameraDownloads/"), true)
|
||||
XCTAssertEqual(
|
||||
savedTask?.localPath?.hasPrefix("CameraDownloads/test_account/\(scope.albumID)/originals/"),
|
||||
true
|
||||
)
|
||||
XCTAssertEqual(savedTask?.localPath?.hasPrefix("/"), false)
|
||||
if let localURL = savedTask?.localURL {
|
||||
try? FileManager.default.removeItem(at: localURL)
|
||||
@ -43,9 +48,11 @@ final class CameraTransferPipelineTests: XCTestCase {
|
||||
let camera = MockCameraService()
|
||||
let sink = MockUploadSink()
|
||||
let pipeline = CameraTransferPipeline(cameraService: camera)
|
||||
pipeline.configure(uploadSink: sink, uploadEnabled: false)
|
||||
let scope = makeScope("retry")
|
||||
defer { CameraDownloadStorage.removeScopeDirectory(for: scope) }
|
||||
pipeline.configure(uploadSink: sink, uploadEnabled: false, downloadScope: scope)
|
||||
|
||||
let fileURL = CameraDownloadStorage.uniqueLocalURL(for: "retry_pipeline.JPG")
|
||||
let fileURL = CameraDownloadStorage.uniqueLocalURL(for: "retry_pipeline.JPG", scope: scope)
|
||||
try Data(repeating: 0xAB, count: 16).write(to: fileURL)
|
||||
defer { try? FileManager.default.removeItem(at: fileURL) }
|
||||
|
||||
@ -65,7 +72,9 @@ final class CameraTransferPipelineTests: XCTestCase {
|
||||
let camera = MockCameraService()
|
||||
let sink = MockSlowUploadSink()
|
||||
let pipeline = CameraTransferPipeline(cameraService: camera)
|
||||
pipeline.configure(uploadSink: sink, uploadEnabled: true)
|
||||
let scope = makeScope("manual")
|
||||
defer { CameraDownloadStorage.removeScopeDirectory(for: scope) }
|
||||
pipeline.configure(uploadSink: sink, uploadEnabled: true, downloadScope: scope)
|
||||
camera.listedAssets = (1 ... 6).map { index in
|
||||
CameraAsset(id: "manual_\(index)", filename: "MANUAL_\(index).JPG", fileSize: 1024)
|
||||
}
|
||||
@ -83,7 +92,9 @@ final class CameraTransferPipelineTests: XCTestCase {
|
||||
let camera = MockCameraService()
|
||||
let sink = MockUploadSink()
|
||||
let pipeline = CameraTransferPipeline(cameraService: camera)
|
||||
pipeline.configure(uploadSink: sink, uploadEnabled: false)
|
||||
let scope = makeScope("mode_switch")
|
||||
defer { CameraDownloadStorage.removeScopeDirectory(for: scope) }
|
||||
pipeline.configure(uploadSink: sink, uploadEnabled: false, downloadScope: scope)
|
||||
|
||||
camera.onNewAsset?(CameraAsset(id: "post_001", filename: "POST_001.JPG", fileSize: 1024))
|
||||
try await Task.sleep(nanoseconds: 400_000_000)
|
||||
@ -91,7 +102,7 @@ final class CameraTransferPipelineTests: XCTestCase {
|
||||
XCTAssertEqual(sink.uploadedFileNames, [])
|
||||
XCTAssertEqual(pipeline.task(forAssetID: "post_001")?.status, .downloaded)
|
||||
|
||||
pipeline.configure(uploadSink: sink, uploadEnabled: true)
|
||||
pipeline.configure(uploadSink: sink, uploadEnabled: true, downloadScope: scope)
|
||||
camera.onNewAsset?(CameraAsset(id: "live_001", filename: "LIVE_001.JPG", fileSize: 1024))
|
||||
try await Task.sleep(nanoseconds: 500_000_000)
|
||||
|
||||
@ -105,7 +116,9 @@ final class CameraTransferPipelineTests: XCTestCase {
|
||||
let camera = MockCameraService()
|
||||
let sink = MockUploadSink()
|
||||
let pipeline = CameraTransferPipeline(cameraService: camera)
|
||||
pipeline.configure(uploadSink: sink, uploadEnabled: true)
|
||||
let scope = makeScope("sync_existing")
|
||||
defer { CameraDownloadStorage.removeScopeDirectory(for: scope) }
|
||||
pipeline.configure(uploadSink: sink, uploadEnabled: true, downloadScope: scope)
|
||||
camera.listedAssets = [
|
||||
CameraAsset(id: "history_001", filename: "HISTORY_001.JPG", fileSize: 1024)
|
||||
]
|
||||
@ -122,7 +135,9 @@ final class CameraTransferPipelineTests: XCTestCase {
|
||||
let camera = MockBurstCameraService()
|
||||
let sink = MockSlowUploadSink()
|
||||
let pipeline = CameraTransferPipeline(cameraService: camera)
|
||||
pipeline.configure(uploadSink: sink, uploadEnabled: true)
|
||||
let scope = makeScope("burst")
|
||||
defer { CameraDownloadStorage.removeScopeDirectory(for: scope) }
|
||||
pipeline.configure(uploadSink: sink, uploadEnabled: true, downloadScope: scope)
|
||||
|
||||
for index in 1 ... 10 {
|
||||
let filename = "DSC_\(index).JPG"
|
||||
@ -149,7 +164,9 @@ final class CameraTransferPipelineTests: XCTestCase {
|
||||
let camera = MockCameraService()
|
||||
let sink = MockChattyUploadSink()
|
||||
let pipeline = CameraTransferPipeline(cameraService: camera)
|
||||
pipeline.configure(uploadSink: sink, uploadEnabled: true)
|
||||
let scope = makeScope("chatty")
|
||||
defer { CameraDownloadStorage.removeScopeDirectory(for: scope) }
|
||||
pipeline.configure(uploadSink: sink, uploadEnabled: true, downloadScope: scope)
|
||||
|
||||
var updateCount = 0
|
||||
pipeline.onTasksUpdated = { _ in updateCount += 1 }
|
||||
@ -160,6 +177,13 @@ final class CameraTransferPipelineTests: XCTestCase {
|
||||
XCTAssertEqual(pipeline.task(forAssetID: "ptp_chatty")?.status, .uploaded)
|
||||
XCTAssertLessThan(updateCount, 18)
|
||||
}
|
||||
|
||||
private func makeScope(_ albumName: String) -> CameraDownloadStorage.Scope {
|
||||
let albumID = albumName.unicodeScalars.reduce(0) { partial, scalar in
|
||||
(partial + Int(scalar.value)) % 10_000
|
||||
}
|
||||
return CameraDownloadStorage.Scope(accountKey: "test_account", albumID: albumID)
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
||||
@ -173,9 +173,10 @@ final class WiredCameraTransferViewModelTests: XCTestCase {
|
||||
),
|
||||
])
|
||||
|
||||
let fileURL = CameraDownloadStorage.uniqueLocalURL(for: "DSC_PROGRESS.JPG")
|
||||
let scope = downloadScope(account: account, albumID: context.albumId)
|
||||
let fileURL = CameraDownloadStorage.uniqueLocalURL(for: "DSC_PROGRESS.JPG", scope: scope)
|
||||
try Data(repeating: 0xAB, count: 16).write(to: fileURL)
|
||||
defer { try? FileManager.default.removeItem(at: fileURL) }
|
||||
defer { CameraDownloadStorage.removeScopeDirectory(for: scope) }
|
||||
|
||||
camera.downloadURL = fileURL
|
||||
camera.onNewAsset?(CameraAsset(id: "ptp_progress", filename: "DSC_PROGRESS.JPG", fileSize: 16))
|
||||
@ -253,9 +254,10 @@ final class WiredCameraTransferViewModelTests: XCTestCase {
|
||||
let account = AccountContext()
|
||||
account.applyLogin(profile: AccountProfile(userId: "101", displayName: "测试"))
|
||||
|
||||
let fileURL = CameraDownloadStorage.uniqueLocalURL(for: "retry_failed.JPG")
|
||||
let scope = downloadScope(account: account, albumID: context.albumId)
|
||||
let fileURL = CameraDownloadStorage.uniqueLocalURL(for: "retry_failed.JPG", scope: scope)
|
||||
try Data(repeating: 0xCD, count: 32).write(to: fileURL)
|
||||
defer { try? FileManager.default.removeItem(at: fileURL) }
|
||||
defer { CameraDownloadStorage.removeScopeDirectory(for: scope) }
|
||||
|
||||
let photoID = "persist_failed_001"
|
||||
let record = WiredTransferPhotoRecord(
|
||||
@ -304,12 +306,13 @@ final class WiredCameraTransferViewModelTests: XCTestCase {
|
||||
account.applyLogin(profile: AccountProfile(userId: userID, displayName: "测试"))
|
||||
|
||||
let fileURLs = try (1 ... 5).map { index in
|
||||
let url = CameraDownloadStorage.uniqueLocalURL(for: "batch_persist_\(index).JPG")
|
||||
let scope = downloadScope(account: account, albumID: albumID)
|
||||
let url = CameraDownloadStorage.uniqueLocalURL(for: "batch_persist_\(index).JPG", scope: scope)
|
||||
try Data(repeating: UInt8(0xA0 + index), count: 32).write(to: url)
|
||||
return url
|
||||
}
|
||||
defer {
|
||||
fileURLs.forEach { try? FileManager.default.removeItem(at: $0) }
|
||||
CameraDownloadStorage.removeScopeDirectory(for: downloadScope(account: account, albumID: albumID))
|
||||
}
|
||||
|
||||
let records = fileURLs.enumerated().map { offset, url in
|
||||
@ -410,18 +413,19 @@ final class WiredCameraTransferViewModelTests: XCTestCase {
|
||||
accountContext: account
|
||||
)
|
||||
|
||||
let imageURL = CameraDownloadStorage.uniqueLocalURL(for: "thumb_source.JPG")
|
||||
let scope = downloadScope(account: account, albumID: albumID)
|
||||
let imageURL = CameraDownloadStorage.uniqueLocalURL(for: "thumb_source.JPG", scope: scope)
|
||||
try makeJPEGData().write(to: imageURL)
|
||||
defer { try? FileManager.default.removeItem(at: imageURL) }
|
||||
defer { CameraDownloadStorage.removeScopeDirectory(for: scope) }
|
||||
|
||||
camera.downloadURL = imageURL
|
||||
camera.onNewAsset?(CameraAsset(id: "thumb_asset_001", filename: "thumb_source.JPG", fileSize: 128))
|
||||
try await Task.sleep(nanoseconds: 900_000_000)
|
||||
|
||||
let photo = try XCTUnwrap(viewModel.photos.first { $0.id == "thumb_asset_001" })
|
||||
XCTAssertTrue(photo.thumbnailURL.contains("/CameraDownloads/Thumbnails/"))
|
||||
XCTAssertTrue(photo.thumbnailURL.contains("/CameraDownloads/\(scope.accountDirectoryName)/\(albumID)/thumbnails/"))
|
||||
XCTAssertTrue(photo.previewURL.contains("/CameraDownloads/"))
|
||||
XCTAssertFalse(photo.previewURL.contains("/Thumbnails/"))
|
||||
XCTAssertFalse(photo.previewURL.contains("/thumbnails/"))
|
||||
}
|
||||
|
||||
/// 测试旧记录没有缩略图时列表先占位,但仍保留原图预览能力。
|
||||
@ -429,9 +433,10 @@ final class WiredCameraTransferViewModelTests: XCTestCase {
|
||||
let albumID = 6602
|
||||
let account = AccountContext()
|
||||
account.applyLogin(profile: AccountProfile(userId: "legacy-user", displayName: "测试"))
|
||||
let fileURL = CameraDownloadStorage.uniqueLocalURL(for: "legacy_only.JPG")
|
||||
let scope = downloadScope(account: account, albumID: albumID)
|
||||
let fileURL = CameraDownloadStorage.uniqueLocalURL(for: "legacy_only.JPG", scope: scope)
|
||||
try makeJPEGData().write(to: fileURL)
|
||||
defer { try? FileManager.default.removeItem(at: fileURL) }
|
||||
defer { CameraDownloadStorage.removeScopeDirectory(for: scope) }
|
||||
|
||||
let record = WiredTransferPhotoRecord(
|
||||
id: "legacy_photo_001",
|
||||
@ -471,6 +476,114 @@ final class WiredCameraTransferViewModelTests: XCTestCase {
|
||||
XCTAssertFalse(photo.previewURL.isEmpty)
|
||||
}
|
||||
|
||||
/// 测试清空相册时只删除当前账号当前相册的物理目录。
|
||||
func testClearAlbumRemovesOnlyCurrentAlbumScopedDirectory() throws {
|
||||
let userID = "clear-scope-user"
|
||||
let account = AccountContext()
|
||||
account.applyLogin(profile: AccountProfile(userId: userID, displayName: "测试"), accountType: "store")
|
||||
let albumID = 8801
|
||||
let otherAlbumID = 8802
|
||||
let scope = downloadScope(account: account, albumID: albumID)
|
||||
let otherScope = downloadScope(account: account, albumID: otherAlbumID)
|
||||
let scopeDirectoryPath = CameraDownloadStorage.scopeDirectory(for: scope).path
|
||||
let otherScopeDirectoryPath = CameraDownloadStorage.scopeDirectory(for: otherScope).path
|
||||
defer {
|
||||
CameraDownloadStorage.removeScopeDirectory(for: scope)
|
||||
CameraDownloadStorage.removeScopeDirectory(for: otherScope)
|
||||
}
|
||||
|
||||
let fileURL = CameraDownloadStorage.uniqueLocalURL(for: "clear_target.JPG", scope: scope)
|
||||
let otherFileURL = CameraDownloadStorage.uniqueLocalURL(for: "clear_other.JPG", scope: otherScope)
|
||||
try Data(repeating: 0x01, count: 8).write(to: fileURL)
|
||||
try Data(repeating: 0x02, count: 8).write(to: otherFileURL)
|
||||
|
||||
let store = WiredTransferPhotoStore(
|
||||
accountPrefixProvider: { account.accountCachePrefix ?? "guest_" },
|
||||
userIDProvider: { userID }
|
||||
)
|
||||
store.save(albumID: albumID, records: [
|
||||
makePhotoRecord(
|
||||
id: "clear_target",
|
||||
fileName: "clear_target.JPG",
|
||||
localPath: CameraDownloadStorage.relativePath(for: fileURL),
|
||||
albumID: albumID,
|
||||
userID: userID
|
||||
)
|
||||
])
|
||||
store.save(albumID: otherAlbumID, records: [
|
||||
makePhotoRecord(
|
||||
id: "clear_other",
|
||||
fileName: "clear_other.JPG",
|
||||
localPath: CameraDownloadStorage.relativePath(for: otherFileURL),
|
||||
albumID: otherAlbumID,
|
||||
userID: userID
|
||||
)
|
||||
])
|
||||
|
||||
let deletedIDs = store.clearAlbum(albumID: albumID)
|
||||
|
||||
XCTAssertEqual(deletedIDs, Set(["clear_target"]))
|
||||
XCTAssertFalse(FileManager.default.fileExists(atPath: fileURL.path))
|
||||
XCTAssertFalse(FileManager.default.fileExists(atPath: scopeDirectoryPath))
|
||||
XCTAssertTrue(FileManager.default.fileExists(atPath: otherFileURL.path))
|
||||
XCTAssertTrue(FileManager.default.fileExists(atPath: otherScopeDirectoryPath))
|
||||
}
|
||||
|
||||
/// 测试同一用户 ID 在不同账号类型下的有线传图记录与物理目录隔离。
|
||||
func testSameUserIDDifferentAccountTypesAreIsolated() throws {
|
||||
let userID = "multi-account-user"
|
||||
let albumID = 8803
|
||||
let storeAccount = AccountContext()
|
||||
storeAccount.applyLogin(profile: AccountProfile(userId: userID, displayName: "门店"), accountType: "store")
|
||||
let photographerAccount = AccountContext()
|
||||
photographerAccount.applyLogin(profile: AccountProfile(userId: userID, displayName: "摄影师"), accountType: "photographer")
|
||||
let storeScope = downloadScope(account: storeAccount, albumID: albumID)
|
||||
let photographerScope = downloadScope(account: photographerAccount, albumID: albumID)
|
||||
defer {
|
||||
CameraDownloadStorage.removeScopeDirectory(for: storeScope)
|
||||
CameraDownloadStorage.removeScopeDirectory(for: photographerScope)
|
||||
}
|
||||
|
||||
let storeURL = CameraDownloadStorage.uniqueLocalURL(for: "store_photo.JPG", scope: storeScope)
|
||||
let photographerURL = CameraDownloadStorage.uniqueLocalURL(for: "photographer_photo.JPG", scope: photographerScope)
|
||||
try Data(repeating: 0x03, count: 8).write(to: storeURL)
|
||||
try Data(repeating: 0x04, count: 8).write(to: photographerURL)
|
||||
|
||||
let store = WiredTransferPhotoStore(
|
||||
accountPrefixProvider: { storeAccount.accountCachePrefix ?? "guest_" },
|
||||
userIDProvider: { userID }
|
||||
)
|
||||
let photographerStore = WiredTransferPhotoStore(
|
||||
accountPrefixProvider: { photographerAccount.accountCachePrefix ?? "guest_" },
|
||||
userIDProvider: { userID }
|
||||
)
|
||||
store.save(albumID: albumID, records: [
|
||||
makePhotoRecord(
|
||||
id: "store_photo",
|
||||
fileName: "store_photo.JPG",
|
||||
localPath: CameraDownloadStorage.relativePath(for: storeURL),
|
||||
albumID: albumID,
|
||||
userID: userID
|
||||
)
|
||||
])
|
||||
photographerStore.save(albumID: albumID, records: [
|
||||
makePhotoRecord(
|
||||
id: "photographer_photo",
|
||||
fileName: "photographer_photo.JPG",
|
||||
localPath: CameraDownloadStorage.relativePath(for: photographerURL),
|
||||
albumID: albumID,
|
||||
userID: userID
|
||||
)
|
||||
])
|
||||
|
||||
XCTAssertEqual(store.load(albumID: albumID).map(\.id), ["store_photo"])
|
||||
XCTAssertEqual(photographerStore.load(albumID: albumID).map(\.id), ["photographer_photo"])
|
||||
XCTAssertNotEqual(
|
||||
CameraDownloadStorage.scopeDirectory(for: storeScope).path,
|
||||
CameraDownloadStorage.scopeDirectory(for: photographerScope).path
|
||||
)
|
||||
}
|
||||
|
||||
private func makeViewModelWithPendingPhotos() -> WiredCameraTransferViewModel {
|
||||
let viewModel = WiredCameraTransferViewModel(
|
||||
context: WiredTransferContext(albumId: 1, albumName: "相册", phone: "", orderNumber: ""),
|
||||
@ -536,6 +649,10 @@ final class WiredCameraTransferViewModelTests: XCTestCase {
|
||||
context.fill(CGRect(x: 0, y: 0, width: 8, height: 8))
|
||||
}
|
||||
}
|
||||
|
||||
private func downloadScope(account: AccountContext, albumID: Int) -> CameraDownloadStorage.Scope {
|
||||
CameraDownloadStorage.Scope(accountKey: account.accountCachePrefix ?? "guest_", albumID: albumID)
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
||||
Reference in New Issue
Block a user