@@ -218,6 +218,51 @@ - (void)testThatUpdatePostThrowsExceptionWithoutPost
218218 failure: ^(NSError *error) {}]);
219219}
220220
221+ #pragma mark - Autosaving posts
222+
223+ - (void )testThatAutoSavePostWorks
224+ {
225+ NSNumber *dotComID = @10 ;
226+ WordPressComRestApi *api = OCMStrictClassMock ([WordPressComRestApi class ]);
227+ PostServiceRemoteREST *service = nil ;
228+
229+ RemotePost *post = OCMClassMock ([RemotePost class ]);
230+ OCMStub ([post postID ]).andReturn (@1 );
231+ OCMStub ([post title ]).andReturn (@" Title" );
232+ OCMStub ([post content ]).andReturn (@" Content" );
233+ OCMStub ([post status ]).andReturn (@" Status" );
234+ OCMStub ([post password ]).andReturn (@" Password" );
235+ OCMStub ([post type ]).andReturn (@" Type" );
236+ OCMStub ([post metadata ]).andReturn (@[]);
237+ OCMStub ([post isStickyPost ]).andReturn (@0 );
238+ OCMStub ([post parentID ]).andReturn (nil );
239+
240+ XCTAssertNoThrow (service = [[PostServiceRemoteREST alloc ] initWithWordPressComRestApi: api siteID: dotComID]);
241+
242+ NSString *endpoint = [NSString stringWithFormat: @" sites/%@ /posts/%@ /autosave" , dotComID, post.postID];
243+ NSString *url = [service pathForEndpoint: endpoint
244+ withVersion: ServiceRemoteWordPressComRESTApiVersion_1_1];
245+
246+ OCMStub ([api POST: [OCMArg isEqual: url]
247+ parameters: [OCMArg isKindOfClass: [NSDictionary class ]]
248+ success: [OCMArg isNotNil ]
249+ failure: [OCMArg isNotNil ]]);
250+
251+ [service autoSave: post
252+ success: ^(RemotePost *post, NSString *previewURL) {}
253+ failure: ^(NSError *error) {}];
254+ }
255+
256+ - (void )testThatAutoSavePostThrowsExceptionWithoutPost
257+ {
258+ PostServiceRemoteREST *service = nil ;
259+
260+ XCTAssertNoThrow (service = [self service ]);
261+ XCTAssertThrows ([service autoSave: nil
262+ success: ^(RemotePost *post, NSString *previewURL) {}
263+ failure: ^(NSError *error) {}]);
264+ }
265+
221266#pragma mark - Deleting posts
222267
223268- (void )testThatDeletePostWorks
0 commit comments