Skip to content

Commit b391332

Browse files
author
sgr-ksmt
committed
added test case.
1 parent 526981e commit b391332

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

FireSnapshot.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
1694DFE92351CB2000B7807A /* QueryBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1694DFDA2351CB2000B7807A /* QueryBuilderTests.swift */; };
6464
1694DFEA2351CB2000B7807A /* ReferenceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1694DFDB2351CB2000B7807A /* ReferenceTests.swift */; };
6565
16982A08235998AA0018C74C /* StoragePath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16982A07235998AA0018C74C /* StoragePath.swift */; };
66+
16982A0A2359BF820018C74C /* StoragePathTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16982A092359BF820018C74C /* StoragePathTests.swift */; };
6667
C7AC0728461714610F570CB5 /* Pods_FireSnapshotTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BA9C3F24DAB7C0106A5A122D /* Pods_FireSnapshotTests.framework */; };
6768
CE86EA2FE75980E5237BCED1 /* Pods_FireSnapshot.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8925B294155F0A90A59C088 /* Pods_FireSnapshot.framework */; };
6869
/* End PBXBuildFile section */
@@ -137,6 +138,7 @@
137138
1694DFDA2351CB2000B7807A /* QueryBuilderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryBuilderTests.swift; sourceTree = "<group>"; };
138139
1694DFDB2351CB2000B7807A /* ReferenceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReferenceTests.swift; sourceTree = "<group>"; };
139140
16982A07235998AA0018C74C /* StoragePath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoragePath.swift; sourceTree = "<group>"; };
141+
16982A092359BF820018C74C /* StoragePathTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoragePathTests.swift; sourceTree = "<group>"; };
140142
25B42645485A6D1C6682724A /* Pods-FireSnapshot.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FireSnapshot.debug.xcconfig"; path = "Target Support Files/Pods-FireSnapshot/Pods-FireSnapshot.debug.xcconfig"; sourceTree = "<group>"; };
141143
648BB37871CC0A94356CF0DB /* Pods-FireSnapshot.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FireSnapshot.release.xcconfig"; path = "Target Support Files/Pods-FireSnapshot/Pods-FireSnapshot.release.xcconfig"; sourceTree = "<group>"; };
142144
B90A83261856C6D7C28E7346 /* Pods-FireSnapshotTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FireSnapshotTests.debug.xcconfig"; path = "Target Support Files/Pods-FireSnapshotTests/Pods-FireSnapshotTests.debug.xcconfig"; sourceTree = "<group>"; };
@@ -255,6 +257,7 @@
255257
1694DFCD2351CB2000B7807A /* ResultTests.swift */,
256258
1694DFD92351CB2000B7807A /* TransactionTests.swift */,
257259
1694DFD62351CB2000B7807A /* WriteTest.swift */,
260+
16982A092359BF820018C74C /* StoragePathTests.swift */,
258261
);
259262
path = Sources;
260263
sourceTree = "<group>";
@@ -546,6 +549,7 @@
546549
1694DFDF2351CB2000B7807A /* DocumentTimestampsTests.swift in Sources */,
547550
1694DFDE2351CB2000B7807A /* ReadTests.swift in Sources */,
548551
1694DFE32351CB2000B7807A /* PathTests.swift in Sources */,
552+
16982A0A2359BF820018C74C /* StoragePathTests.swift in Sources */,
549553
1694DFE82351CB2000B7807A /* TransactionTests.swift in Sources */,
550554
1694DFEA2351CB2000B7807A /* ReferenceTests.swift in Sources */,
551555
1694DFE72351CB2000B7807A /* IncrementableNumberTests.swift in Sources */,

FireSnapshotTests/Sources/FirebaseTestHelper.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum FirebaseTestHelper {
1818
if FirebaseApp.app() == nil {
1919
let options = FirebaseOptions(googleAppID: "1:123:ios:123abc", gcmSenderID: "sender_id")
2020
options.projectID = "test-" + dateFormatter.string(from: Date())
21+
options.storageBucket = "project-id-123.storage.firebase.com"
2122
FirebaseApp.configure(options: options)
2223
let settings = Firestore.firestore().settings
2324
settings.host = "localhost:8080"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// Copyright © Suguru Kishimoto. All rights reserved.
3+
//
4+
5+
import XCTest
6+
import FirebaseFirestore
7+
import FirebaseStorage
8+
9+
@testable import FireSnapshot
10+
11+
private extension CollectionPaths {
12+
static let mocks = CollectionPath<Mock>("mocks")
13+
}
14+
15+
private struct Mock: SnapshotData, HasTimestamps {
16+
@StoragePath(path: "path/to/image.jpg") var imageRef
17+
}
18+
19+
class StoragePathTests: XCTestCase {
20+
override func setUp() {
21+
super.setUp()
22+
FirebaseTestHelper.setupFirebaseApp()
23+
}
24+
25+
override func tearDown() {
26+
super.tearDown()
27+
FirebaseTestHelper.deleteFirebaseApp()
28+
}
29+
30+
func testCodable() {
31+
let mock = Mock()
32+
XCTAssertEqual(mock.imageRef, Storage.storage().reference().child("path/to/image.jpg"))
33+
let fields = try? Firestore.Encoder().encode(mock)
34+
XCTAssertNotNil(fields)
35+
XCTAssertEqual(fields?["imageRef"] as? String, "path/to/image.jpg")
36+
37+
let decoded = fields.flatMap { try? Firestore.Decoder().decode(Mock.self, from: $0) }
38+
XCTAssertNotNil(decoded)
39+
XCTAssertEqual(decoded?.imageRef, mock.imageRef)
40+
}
41+
42+
func testPath() {
43+
var mock = Mock()
44+
XCTAssertEqual(mock.imageRef, Storage.storage().reference().child("path/to/image.jpg"))
45+
46+
mock.$imageRef.path = "path/to/video.mp4"
47+
XCTAssertEqual(mock.imageRef, Storage.storage().reference().child("path/to/video.mp4"))
48+
}
49+
}

0 commit comments

Comments
 (0)