This repository was archived by the owner on Sep 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Add autosave attributes to RemotePost #192
Merged
shiki
merged 15 commits into
wordpress-mobile:develop
from
guarani:issue/12141-restore-revision-dialog
Nov 6, 2019
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3c19071
Add post autosave metadata support to REST API
guarani a488bf1
Cleanly handle NSNull when fetching autosave data
guarani ae640e2
Add autosave modified date to `RemotePost`
guarani ae89a86
Remove unsupported claim about meta parameter
guarani c90227b
Remove nullable from autosave properties
guarani 96af321
Deseralize autosave modified date from string
guarani 03f9667
Add additional autosave attributes to RemotePost
guarani 85bb8a5
Make RemotePostAutosave Obj-C compatible
guarani f8aaff8
Add unit test to verify autosave mapping
guarani 6a6ef4b
Merge branch 'develop' into issue/12141-restore-revision-dialog
guarani ef538b9
Merge branch 'develop' into issue/12141-restore-revision-dialog
guarani a79aa2d
Updating pod version.
guarani 90d883a
Update documentation
guarani bfb8412
Tighten access control on RemotePostAutosave
guarani 851cc8d
Handle case when autosave is null
guarani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import Foundation | ||
|
|
||
| /// Encapsulates the autosave attributes of a post. | ||
| @objc | ||
| @objcMembers | ||
| public class RemotePostAutosave: NSObject { | ||
| public var title: String? | ||
| public var excerpt: String? | ||
| public var content: String? | ||
| public var modifiedDate: Date? | ||
| public var identifier: NSNumber? | ||
| public var authorID: String? | ||
| public var postID: NSNumber? | ||
| public var previewURL: String? | ||
| } |
38 changes: 38 additions & 0 deletions
38
WordPressKitTests/Mock Data/post-autosave-mapping-success.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| { | ||
| "found": 3, | ||
| "posts": [ | ||
| { | ||
| "modified": "2019-10-28T02:05:52+00:00", | ||
| "title": "Hola, mundo!", | ||
| "status": "publish", | ||
| "meta": { | ||
| "links": { | ||
| "self": "https://public-api.wordpress.com/rest/v1.1/sites/168297153/posts/102", | ||
| "help": "https://public-api.wordpress.com/rest/v1.1/sites/168297153/posts/102/help", | ||
| "site": "https://public-api.wordpress.com/rest/v1.1/sites/168297153", | ||
| "replies": "https://public-api.wordpress.com/rest/v1.1/sites/168297153/posts/102/replies/", | ||
| "likes": "https://public-api.wordpress.com/rest/v1.1/sites/168297153/posts/102/likes/", | ||
| "autosave": "https://public-api.wordpress.com/rest/v1.1/sites/168297153/posts/102/autosave" | ||
| }, | ||
| "data": { | ||
| "autosave": { | ||
| "ID": 100, | ||
| "author_ID": "12345678", | ||
| "post_ID": 102, | ||
| "title": "Hello, world!", | ||
| "content": "<!-- wp:paragraph -->\n<p>Uno.</p>\n<!-- /wp:paragraph -->", | ||
| "excerpt": "abc", | ||
| "preview_URL": "https://hello.wordpress.com/2019/10/28/hello-world/?preview=true&preview_nonce=07346f4e5d", | ||
| "modified": "2019-10-28T02:06:39+00:00" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ], | ||
| "meta": { | ||
| "links": { | ||
| "counts": "https://public-api.wordpress.com/rest/v1.1/sites/168297153/post-counts/post" | ||
| }, | ||
| "wpcom": true | ||
| } | ||
| } |
54 changes: 54 additions & 0 deletions
54
WordPressKitTests/PostServiceRemoteRESTAutosaveTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import Foundation | ||
| import XCTest | ||
|
|
||
| @testable import WordPressKit | ||
|
|
||
|
|
||
| class PostServiceRemoteRESTAutosaveTests: RemoteTestCase, RESTTestable { | ||
| private let performPostsAutosaveSuccessFilename = "post-autosave-mapping-success.json" | ||
| private let siteId = 0 | ||
| private var remote: PostServiceRemoteREST! | ||
| private var postsEndpoint: String { | ||
| return "sites/\(siteId)/posts" | ||
| } | ||
|
|
||
| override func setUp() { | ||
| super.setUp() | ||
| remote = PostServiceRemoteREST(wordPressComRestApi: getRestApi(), siteID: NSNumber(value: siteId)) | ||
| } | ||
|
|
||
| override func tearDown() { | ||
| super.tearDown() | ||
| remote = nil | ||
| } | ||
|
|
||
|
|
||
| // MARK: Perform tests | ||
|
|
||
| func testFetchPostsPerformsAutosaveMappingSuccessfully() { | ||
| let expect = expectation(description: "Fetch posts fetches autosaves successfully") | ||
|
|
||
| stubRemoteResponse(postsEndpoint, filename: performPostsAutosaveSuccessFilename, contentType: .ApplicationJSON) | ||
| remote.getPostsOfType("", options: [:], success: { remotePosts in | ||
|
|
||
| guard let remotePost = remotePosts?.first else { | ||
| XCTFail("Failed to retrieve mock post") | ||
| return | ||
| } | ||
|
|
||
| XCTAssertEqual(remotePost.autosave.identifier?.intValue, 100) | ||
| XCTAssertEqual(remotePost.autosave.authorID, "12345678") | ||
| XCTAssertEqual(remotePost.autosave.postID, 102) | ||
| XCTAssertEqual(remotePost.autosave.title, "Hello, world!") | ||
| XCTAssertEqual(remotePost.autosave.content, "<!-- wp:paragraph -->\n<p>Uno.</p>\n<!-- /wp:paragraph -->") | ||
| XCTAssertEqual(remotePost.autosave.excerpt, "abc") | ||
| XCTAssertEqual(remotePost.autosave.previewURL, "https://hello.wordpress.com/2019/10/28/hello-world/?preview=true&preview_nonce=07346f4e5d") | ||
| XCTAssertEqual(remotePost.autosave.modifiedDate, NSDate(wordPressComJSONString: "2019-10-28T02:06:39+00:00") as Date?) | ||
| expect.fulfill() | ||
| }, failure: { _ in | ||
| XCTFail("This callback shouldn't get called") | ||
| expect.fulfill() | ||
| }) | ||
| waitForExpectations(timeout: timeout, handler: nil) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.