Skip to content

Commit

Permalink
Sync pagination tests (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
matelo authored Mar 10, 2020
1 parent 7017c7c commit f0e581e
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CONTENTFUL_SDK_VERSION=5.0.7
CONTENTFUL_SDK_VERSION=5.0.8
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) starting from

## Table of contents
#### 5.x Releases
- `5.0.0` Releases - [5.0.7](#507)
- `5.0.0` Releases - [5.0.7](#507) | [5.0.8](#261)
#### 4.x Releases
- `4.2.0` Releases - [4.2.0](#420) | [4.2.1](#421) | [4.2.2](#422) | [4.2.3](#423) | [4.2.4](#424)
- `4.1.0` Releases - [4.1.0](#410) | [4.1.3](#413)
Expand Down
4 changes: 4 additions & 0 deletions Cartfile.private
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
github "venmo/DVR" ~> 1.3.2
<<<<<<< HEAD
github "AliSoftware/OHHTTPStubs" ~> 7.0.0
=======
github "AliSoftware/OHHTTPStubs" ~> 8.0.0
>>>>>>> master
4 changes: 4 additions & 0 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
<<<<<<< HEAD
github "AliSoftware/OHHTTPStubs" "7.0.0"
=======
github "AliSoftware/OHHTTPStubs" "8.0.0"
>>>>>>> master
github "venmo/DVR" "v1.3.2"
2 changes: 1 addition & 1 deletion Carthage/Checkouts/OHHTTPStubs
Submodule OHHTTPStubs updated 26 files
+8 −16 .travis.yml
+0 −8 CHANGELOG.md
+2 −5 Examples/ObjC/OHHTTPStubsDemo.xcodeproj/project.pbxproj
+1 −1 Examples/ObjC/OHHTTPStubsDemo.xcodeproj/xcshareddata/xcschemes/OHHTTPStubsDemo.xcscheme
+9 −9 Examples/ObjC/Podfile.lock
+2 −2 Examples/ObjC/Pods/Local Podspecs/OHHTTPStubs.podspec.json
+9 −9 Examples/ObjC/Pods/Manifest.lock
+10 −12 Examples/ObjC/Pods/Pods.xcodeproj/project.pbxproj
+1 −1 Examples/Swift/MainViewController.swift
+5 −8 Examples/Swift/OHHTTPStubsDemo.xcodeproj/project.pbxproj
+1 −1 Examples/Swift/OHHTTPStubsDemo.xcodeproj/xcshareddata/xcschemes/OHHTTPStubsDemo.xcscheme
+10 −10 Examples/Swift/Podfile.lock
+2 −2 Examples/Swift/Pods/Local Podspecs/OHHTTPStubs.podspec.json
+10 −10 Examples/Swift/Pods/Manifest.lock
+45 −47 Examples/Swift/Pods/Pods.xcodeproj/project.pbxproj
+1 −1 Examples/Swift/Pods/Target Support Files/OHHTTPStubs/OHHTTPStubs-Info.plist
+0 −1 Examples/Swift/Pods/Target Support Files/OHHTTPStubs/OHHTTPStubs.xcconfig
+2 −1 OHHTTPStubs.podspec
+14 −13 OHHTTPStubs/OHHTTPStubs.xcodeproj/project.pbxproj
+1 −1 OHHTTPStubs/OHHTTPStubs.xcodeproj/xcshareddata/xcschemes/OHHTTPStubs Mac Framework.xcscheme
+1 −1 OHHTTPStubs/OHHTTPStubs.xcodeproj/xcshareddata/xcschemes/OHHTTPStubs iOS Framework.xcscheme
+1 −1 OHHTTPStubs/OHHTTPStubs.xcodeproj/xcshareddata/xcschemes/OHHTTPStubs iOS StaticLib.xcscheme
+1 −1 OHHTTPStubs/OHHTTPStubs.xcodeproj/xcshareddata/xcschemes/OHHTTPStubs tvOS Framework.xcscheme
+2 −5 OHHTTPStubs/Pods/Pods.xcodeproj/project.pbxproj
+1 −1 OHHTTPStubs/UnitTests/Test Suites/NSURLSessionTests.m
+5 −6 README.md
2 changes: 1 addition & 1 deletion Config.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CONTENTFUL_SDK_VERSION=5.0.7
CONTENTFUL_SDK_VERSION=5.0.8
8 changes: 8 additions & 0 deletions Contentful.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
5DD410EB21918E84003FC01E /* RichTextNodeDecodingTests.json in Resources */ = {isa = PBXBuildFile; fileRef = 5DD410E421918E62003FC01E /* RichTextNodeDecodingTests.json */; };
5DFE08DB2189D6AC00B0D68E /* EntryTests.json in Resources */ = {isa = PBXBuildFile; fileRef = 5DFE08DA2189D6AC00B0D68E /* EntryTests.json */; };
5DFE08DC2189D6AC00B0D68E /* EntryTests.json in Resources */ = {isa = PBXBuildFile; fileRef = 5DFE08DA2189D6AC00B0D68E /* EntryTests.json */; };
757C0AD32257D955008F91BD /* SyncWithPaginationTests.json in Resources */ = {isa = PBXBuildFile; fileRef = 757C0AD12257D94E008F91BD /* SyncWithPaginationTests.json */; };
757C0AD42257D955008F91BD /* SyncWithPaginationTests.json in Resources */ = {isa = PBXBuildFile; fileRef = 757C0AD12257D94E008F91BD /* SyncWithPaginationTests.json */; };
757C0AD52257D956008F91BD /* SyncWithPaginationTests.json in Resources */ = {isa = PBXBuildFile; fileRef = 757C0AD12257D94E008F91BD /* SyncWithPaginationTests.json */; };
A10FF9D21BBB2E5F001AA4E9 /* JSONDecodingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B2E3661BBAD06000814D63 /* JSONDecodingTests.swift */; };
A10FF9D31BBB32FD001AA4E9 /* Asset.swift in Sources */ = {isa = PBXBuildFile; fileRef = A15193AD1BB9236300FB83CD /* Asset.swift */; };
A10FF9D51BBB3676001AA4E9 /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = A10FF9D41BBB3676001AA4E9 /* Error.swift */; };
Expand Down Expand Up @@ -299,6 +302,7 @@
5DD410462190BC8B003FC01E /* RichText.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RichText.swift; sourceTree = "<group>"; };
5DD410E421918E62003FC01E /* RichTextNodeDecodingTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = RichTextNodeDecodingTests.json; sourceTree = "<group>"; };
5DFE08DA2189D6AC00B0D68E /* EntryTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = EntryTests.json; sourceTree = "<group>"; };
757C0AD12257D94E008F91BD /* SyncWithPaginationTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = SyncWithPaginationTests.json; sourceTree = "<group>"; };
A10FF9D41BBB3676001AA4E9 /* Error.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Error.swift; sourceTree = "<group>"; };
A10FF9DB1BBB4692001AA4E9 /* Field.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Field.swift; sourceTree = "<group>"; };
A114BBBF1C4FD3C300DE6679 /* SyncSpace.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = SyncSpace.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -608,6 +612,7 @@
ED9102671E65AE880076FDBD /* DVRRecordings */ = {
isa = PBXGroup;
children = (
757C0AD12257D94E008F91BD /* SyncWithPaginationTests.json */,
5D73EE3821B915C60091DB67 /* LinkResolverTests.json */,
5DD410E421918E62003FC01E /* RichTextNodeDecodingTests.json */,
5DFE08DA2189D6AC00B0D68E /* EntryTests.json */,
Expand Down Expand Up @@ -899,6 +904,7 @@
5D73EE3B21B915C60091DB67 /* LinkResolverTests.json in Resources */,
5D52E2802193381F00C88FC9 /* testClientCantAccessPreviewAPIWithProductionToken.json in Resources */,
5D52E2812193381F00C88FC9 /* testFetchSpace.json in Resources */,
757C0AD52257D956008F91BD /* SyncWithPaginationTests.json in Resources */,
5D52E2822193381F00C88FC9 /* Fixtures in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -930,6 +936,7 @@
5D73EE3921B915C60091DB67 /* LinkResolverTests.json in Resources */,
ED02DC9F20E12405005EC57B /* Fixtures in Resources */,
5D09C24B21870C27006B83F4 /* testFetchSpace.json in Resources */,
757C0AD32257D955008F91BD /* SyncWithPaginationTests.json in Resources */,
5D09C24521870C27006B83F4 /* ErrorTests.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -954,6 +961,7 @@
5D73EE3A21B915C60091DB67 /* LinkResolverTests.json in Resources */,
5D09C25E21870C27006B83F4 /* ContentTypeTests.json in Resources */,
5D09C24921870C27006B83F4 /* RateLimitTests.json in Resources */,
757C0AD42257D955008F91BD /* SyncWithPaginationTests.json in Resources */,
5D09C24321870C27006B83F4 /* testClientCantAccessPreviewAPIWithProductionToken.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
22 changes: 10 additions & 12 deletions Sources/Contentful/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -561,22 +561,20 @@ extension Client {
completion(Result.error(SDKError.previewAPIDoesNotSupportSync))
return nil
}

let parameters = syncableTypes.parameters + syncSpace.parameters
return fetch(url: url(endpoint: .sync, parameters: parameters)) { (result: Result<SyncSpace>) in

var mutableResult = result
if case .success(let newSyncSpace) = result {
// On each new page, update the original sync space and forward the diffs to the
// persistence integration.
switch result {
case.success(let newSyncSpace):
syncSpace.updateWithDiffs(from: newSyncSpace)
self.persistenceIntegration?.update(with: newSyncSpace)
mutableResult = .success(syncSpace)
}
if let syncSpace = result.value, syncSpace.hasMorePages == true {
self.sync(for: syncSpace, syncableTypes: syncableTypes, then: completion)
} else {
completion(mutableResult)
if newSyncSpace.hasMorePages {
self.sync(for: syncSpace, syncableTypes: syncableTypes, then: completion)
} else {
completion(.success(syncSpace))
}
case .error(let error):
completion(.error(error))
}
}
}
Expand Down
123 changes: 123 additions & 0 deletions Tests/ContentfulTests/DVRRecordings/SyncWithPaginationTests.json

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions Tests/ContentfulTests/SyncTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ class SyncTests: XCTestCase {
(client.urlSession as? DVR.Session)?.endRecording()
}

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

SyncTests.client.sync(syncableTypes: syncableTypes) { result in
client.sync(syncableTypes: syncableTypes) { result in
switch result {
case .success(let syncSpace):
action(syncSpace)
Expand Down Expand Up @@ -83,7 +85,18 @@ class SyncTests: XCTestCase {
XCTAssertEqual($0.entries.count, 3)
}
}


func testSyncWithPagination() {
let client = TestClientFactory.testClient(withCassetteNamed: "SyncWithPaginationTests")
(client.urlSession as? DVR.Session)?.beginRecording()

waitUntilSync(client: client, syncableTypes: .all) {
XCTAssertEqual($0.assets.count, 4)
XCTAssertEqual($0.entries.count, 11)
}

(client.urlSession as? DVR.Session)?.endRecording()
}
}

#if !API_COVERAGE
Expand Down

0 comments on commit f0e581e

Please sign in to comment.