Skip to content

Commit f0e581e

Browse files
authored
Sync pagination tests (contentful#293)
1 parent 7017c7c commit f0e581e

File tree

10 files changed

+169
-19
lines changed

10 files changed

+169
-19
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CONTENTFUL_SDK_VERSION=5.0.7
1+
CONTENTFUL_SDK_VERSION=5.0.8

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) starting from
99

1010
## Table of contents
1111
#### 5.x Releases
12-
- `5.0.0` Releases - [5.0.7](#507)
12+
- `5.0.0` Releases - [5.0.7](#507) | [5.0.8](#261)
1313
#### 4.x Releases
1414
- `4.2.0` Releases - [4.2.0](#420) | [4.2.1](#421) | [4.2.2](#422) | [4.2.3](#423) | [4.2.4](#424)
1515
- `4.1.0` Releases - [4.1.0](#410) | [4.1.3](#413)

Cartfile.private

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
github "venmo/DVR" ~> 1.3.2
2+
<<<<<<< HEAD
3+
github "AliSoftware/OHHTTPStubs" ~> 7.0.0
4+
=======
25
github "AliSoftware/OHHTTPStubs" ~> 8.0.0
6+
>>>>>>> master

Cartfile.resolved

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
<<<<<<< HEAD
2+
github "AliSoftware/OHHTTPStubs" "7.0.0"
3+
=======
14
github "AliSoftware/OHHTTPStubs" "8.0.0"
5+
>>>>>>> master
26
github "venmo/DVR" "v1.3.2"

Carthage/Checkouts/OHHTTPStubs

Submodule OHHTTPStubs updated 26 files

Config.xcconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CONTENTFUL_SDK_VERSION=5.0.7
1+
CONTENTFUL_SDK_VERSION=5.0.8

Contentful.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@
123123
5DD410EB21918E84003FC01E /* RichTextNodeDecodingTests.json in Resources */ = {isa = PBXBuildFile; fileRef = 5DD410E421918E62003FC01E /* RichTextNodeDecodingTests.json */; };
124124
5DFE08DB2189D6AC00B0D68E /* EntryTests.json in Resources */ = {isa = PBXBuildFile; fileRef = 5DFE08DA2189D6AC00B0D68E /* EntryTests.json */; };
125125
5DFE08DC2189D6AC00B0D68E /* EntryTests.json in Resources */ = {isa = PBXBuildFile; fileRef = 5DFE08DA2189D6AC00B0D68E /* EntryTests.json */; };
126+
757C0AD32257D955008F91BD /* SyncWithPaginationTests.json in Resources */ = {isa = PBXBuildFile; fileRef = 757C0AD12257D94E008F91BD /* SyncWithPaginationTests.json */; };
127+
757C0AD42257D955008F91BD /* SyncWithPaginationTests.json in Resources */ = {isa = PBXBuildFile; fileRef = 757C0AD12257D94E008F91BD /* SyncWithPaginationTests.json */; };
128+
757C0AD52257D956008F91BD /* SyncWithPaginationTests.json in Resources */ = {isa = PBXBuildFile; fileRef = 757C0AD12257D94E008F91BD /* SyncWithPaginationTests.json */; };
126129
A10FF9D21BBB2E5F001AA4E9 /* JSONDecodingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B2E3661BBAD06000814D63 /* JSONDecodingTests.swift */; };
127130
A10FF9D31BBB32FD001AA4E9 /* Asset.swift in Sources */ = {isa = PBXBuildFile; fileRef = A15193AD1BB9236300FB83CD /* Asset.swift */; };
128131
A10FF9D51BBB3676001AA4E9 /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10FF9D41BBB3676001AA4E9 /* Error.swift */; };
@@ -299,6 +302,7 @@
299302
5DD410462190BC8B003FC01E /* RichText.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RichText.swift; sourceTree = "<group>"; };
300303
5DD410E421918E62003FC01E /* RichTextNodeDecodingTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = RichTextNodeDecodingTests.json; sourceTree = "<group>"; };
301304
5DFE08DA2189D6AC00B0D68E /* EntryTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = EntryTests.json; sourceTree = "<group>"; };
305+
757C0AD12257D94E008F91BD /* SyncWithPaginationTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = SyncWithPaginationTests.json; sourceTree = "<group>"; };
302306
A10FF9D41BBB3676001AA4E9 /* Error.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Error.swift; sourceTree = "<group>"; };
303307
A10FF9DB1BBB4692001AA4E9 /* Field.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Field.swift; sourceTree = "<group>"; };
304308
A114BBBF1C4FD3C300DE6679 /* SyncSpace.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = SyncSpace.swift; sourceTree = "<group>"; };
@@ -608,6 +612,7 @@
608612
ED9102671E65AE880076FDBD /* DVRRecordings */ = {
609613
isa = PBXGroup;
610614
children = (
615+
757C0AD12257D94E008F91BD /* SyncWithPaginationTests.json */,
611616
5D73EE3821B915C60091DB67 /* LinkResolverTests.json */,
612617
5DD410E421918E62003FC01E /* RichTextNodeDecodingTests.json */,
613618
5DFE08DA2189D6AC00B0D68E /* EntryTests.json */,
@@ -899,6 +904,7 @@
899904
5D73EE3B21B915C60091DB67 /* LinkResolverTests.json in Resources */,
900905
5D52E2802193381F00C88FC9 /* testClientCantAccessPreviewAPIWithProductionToken.json in Resources */,
901906
5D52E2812193381F00C88FC9 /* testFetchSpace.json in Resources */,
907+
757C0AD52257D956008F91BD /* SyncWithPaginationTests.json in Resources */,
902908
5D52E2822193381F00C88FC9 /* Fixtures in Resources */,
903909
);
904910
runOnlyForDeploymentPostprocessing = 0;
@@ -930,6 +936,7 @@
930936
5D73EE3921B915C60091DB67 /* LinkResolverTests.json in Resources */,
931937
ED02DC9F20E12405005EC57B /* Fixtures in Resources */,
932938
5D09C24B21870C27006B83F4 /* testFetchSpace.json in Resources */,
939+
757C0AD32257D955008F91BD /* SyncWithPaginationTests.json in Resources */,
933940
5D09C24521870C27006B83F4 /* ErrorTests.json in Resources */,
934941
);
935942
runOnlyForDeploymentPostprocessing = 0;
@@ -954,6 +961,7 @@
954961
5D73EE3A21B915C60091DB67 /* LinkResolverTests.json in Resources */,
955962
5D09C25E21870C27006B83F4 /* ContentTypeTests.json in Resources */,
956963
5D09C24921870C27006B83F4 /* RateLimitTests.json in Resources */,
964+
757C0AD42257D955008F91BD /* SyncWithPaginationTests.json in Resources */,
957965
5D09C24321870C27006B83F4 /* testClientCantAccessPreviewAPIWithProductionToken.json in Resources */,
958966
);
959967
runOnlyForDeploymentPostprocessing = 0;

Sources/Contentful/Client.swift

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -561,22 +561,20 @@ extension Client {
561561
completion(Result.error(SDKError.previewAPIDoesNotSupportSync))
562562
return nil
563563
}
564-
564+
565565
let parameters = syncableTypes.parameters + syncSpace.parameters
566566
return fetch(url: url(endpoint: .sync, parameters: parameters)) { (result: Result<SyncSpace>) in
567-
568-
var mutableResult = result
569-
if case .success(let newSyncSpace) = result {
570-
// On each new page, update the original sync space and forward the diffs to the
571-
// persistence integration.
567+
switch result {
568+
case.success(let newSyncSpace):
572569
syncSpace.updateWithDiffs(from: newSyncSpace)
573570
self.persistenceIntegration?.update(with: newSyncSpace)
574-
mutableResult = .success(syncSpace)
575-
}
576-
if let syncSpace = result.value, syncSpace.hasMorePages == true {
577-
self.sync(for: syncSpace, syncableTypes: syncableTypes, then: completion)
578-
} else {
579-
completion(mutableResult)
571+
if newSyncSpace.hasMorePages {
572+
self.sync(for: syncSpace, syncableTypes: syncableTypes, then: completion)
573+
} else {
574+
completion(.success(syncSpace))
575+
}
576+
case .error(let error):
577+
completion(.error(error))
580578
}
581579
}
582580
}

Tests/ContentfulTests/DVRRecordings/SyncWithPaginationTests.json

Lines changed: 123 additions & 0 deletions
Large diffs are not rendered by default.

Tests/ContentfulTests/SyncTests.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ class SyncTests: XCTestCase {
2424
(client.urlSession as? DVR.Session)?.endRecording()
2525
}
2626

27-
func waitUntilSync(syncableTypes: SyncSpace.SyncableTypes, action: @escaping (_ space: SyncSpace) -> ()) {
27+
func waitUntilSync(client: Client = SyncTests.client,
28+
syncableTypes: SyncSpace.SyncableTypes,
29+
action: @escaping (_ space: SyncSpace) -> ()) {
2830
let expectation = self.expectation(description: "Sync test expecation")
2931

30-
SyncTests.client.sync(syncableTypes: syncableTypes) { result in
32+
client.sync(syncableTypes: syncableTypes) { result in
3133
switch result {
3234
case .success(let syncSpace):
3335
action(syncSpace)
@@ -83,7 +85,18 @@ class SyncTests: XCTestCase {
8385
XCTAssertEqual($0.entries.count, 3)
8486
}
8587
}
86-
88+
89+
func testSyncWithPagination() {
90+
let client = TestClientFactory.testClient(withCassetteNamed: "SyncWithPaginationTests")
91+
(client.urlSession as? DVR.Session)?.beginRecording()
92+
93+
waitUntilSync(client: client, syncableTypes: .all) {
94+
XCTAssertEqual($0.assets.count, 4)
95+
XCTAssertEqual($0.entries.count, 11)
96+
}
97+
98+
(client.urlSession as? DVR.Session)?.endRecording()
99+
}
87100
}
88101

89102
#if !API_COVERAGE

0 commit comments

Comments
 (0)