Skip to content

Commit 18069a2

Browse files
committed
Add test for RemoteBlogSettings init with JSON
1 parent d149306 commit 18069a2

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

Sources/WordPressKit/Services/BlogServiceRemoteREST.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,7 @@ typedef void (^SettingsHandler)(RemoteBlogSettings *settings);
6666
success:(void(^)(NSDictionary *siteInfoDict))success
6767
failure:(void (^)(NSError *error))failure;
6868

69+
// FIXME: Temporary public for testing. Will remove once the logic moves to Swift
70+
- (RemoteBlogSettings *)remoteBlogSettingFromJSONDictionary:(NSDictionary *)json;
71+
6972
@end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@testable import WordPressKit
2+
import XCTest
3+
4+
final class RemoteBlogSettingsTests: XCTestCase {
5+
6+
func testInitWithJSON() throws {
7+
let jsonPath = try XCTUnwrap(
8+
Bundle(for: type(of: self))
9+
.path(forResource: "rest-site-settings", ofType: "json")
10+
)
11+
let json = try XCTUnwrap(JSONLoader().loadFile(jsonPath))
12+
// FIXME: The init logic is currently in BlogServiceRemoteREST. We'll test it from there first, then update the test with the new location.
13+
let blogService = BlogServiceRemoteREST(wordPressComRestApi: MockWordPressComRestApi(), siteID: 0)
14+
let settings = try XCTUnwrap(blogService.remoteBlogSetting(fromJSONDictionary: json))
15+
16+
// Root properties
17+
XCTAssertEqual(settings.name, "My Epic Blog")
18+
XCTAssertEqual(settings.tagline, "Definitely, the best blog out there")
19+
// Flattened settings properties
20+
XCTAssertEqual(settings.privacy, 1)
21+
XCTAssertEqual(settings.languageID, 31337)
22+
XCTAssertNil(settings.iconMediaID)
23+
XCTAssertEqual(settings.gmtOffset, 0)
24+
// And so on...
25+
26+
// defaultPostFormat has custom decoding, so let's test it explicitly.
27+
// Note that here we're obviously testing only one of the possible paths.
28+
XCTAssertEqual(settings.defaultPostFormat, "standard")
29+
}
30+
}

WordPressKit.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
3FE2E94F2BB29A1B002CA2E1 /* FilePart.m in Sources */ = {isa = PBXBuildFile; fileRef = 3FE2E94D2BB29A1B002CA2E1 /* FilePart.m */; };
7373
3FE2E9502BB29A1B002CA2E1 /* FilePart.h in Headers */ = {isa = PBXBuildFile; fileRef = 3FE2E94E2BB29A1B002CA2E1 /* FilePart.h */; settings = {ATTRIBUTES = (Public, ); }; };
7474
3FE2E9672BBEB8D2002CA2E1 /* WordPressComRESTAPIVersion.h in Headers */ = {isa = PBXBuildFile; fileRef = 3FE2E9662BBEB8D2002CA2E1 /* WordPressComRESTAPIVersion.h */; settings = {ATTRIBUTES = (Public, ); }; };
75+
3FE2E9692BBF7C10002CA2E1 /* RemoteBlogSettingsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FE2E9682BBF7C10002CA2E1 /* RemoteBlogSettingsTests.swift */; };
7576
3FFCC0412BA995290051D229 /* Date+WordPressComTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FFCC0402BA995290051D229 /* Date+WordPressComTests.swift */; };
7677
3FFCC0472BAA6EF40051D229 /* NSDate+WordPressCom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FFCC0462BAA6EF40051D229 /* NSDate+WordPressCom.swift */; };
7778
3FFCC0492BAB98130051D229 /* DateFormatter+WordPressCom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FFCC0482BAB98130051D229 /* DateFormatter+WordPressCom.swift */; };
@@ -817,6 +818,7 @@
817818
3FE2E94D2BB29A1B002CA2E1 /* FilePart.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FilePart.m; sourceTree = "<group>"; };
818819
3FE2E94E2BB29A1B002CA2E1 /* FilePart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FilePart.h; sourceTree = "<group>"; };
819820
3FE2E9662BBEB8D2002CA2E1 /* WordPressComRESTAPIVersion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WordPressComRESTAPIVersion.h; sourceTree = "<group>"; };
821+
3FE2E9682BBF7C10002CA2E1 /* RemoteBlogSettingsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteBlogSettingsTests.swift; sourceTree = "<group>"; };
820822
3FFCC0402BA995290051D229 /* Date+WordPressComTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+WordPressComTests.swift"; sourceTree = "<group>"; };
821823
3FFCC0462BAA6EF40051D229 /* NSDate+WordPressCom.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSDate+WordPressCom.swift"; sourceTree = "<group>"; };
822824
3FFCC0482BAB98130051D229 /* DateFormatter+WordPressCom.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+WordPressCom.swift"; sourceTree = "<group>"; };
@@ -1878,6 +1880,7 @@
18781880
FA1D0F8D299534FF0025D76C /* BlazeServiceRemoteTests.swift */,
18791881
465F88A6263B371D00F4C950 /* BlockEditorSettingsServiceRemoteTests.swift */,
18801882
74B5F0DD1EF82A9600B411E7 /* BlogServiceRemoteRESTTests.m */,
1883+
3FE2E9682BBF7C10002CA2E1 /* RemoteBlogSettingsTests.swift */,
18811884
FEE48EF52A4B3602008A48E0 /* BlogServiceRemote+ActiveFeaturesTests.swift */,
18821885
FEEFD8B6280EC91B00A3E261 /* BloggingPromptsServiceRemoteTests.swift */,
18831886
ABD95B7E25DD6C4B00735BEE /* CommentServiceRemoteRESTLikesTests.swift */,
@@ -3537,6 +3540,7 @@
35373540
FFA4D4AA2423B10A00BF5180 /* WordPressOrgRestApiTests.swift in Sources */,
35383541
74A44DD51F13C6D8006CD8F4 /* PushAuthenticationServiceRemoteTests.swift in Sources */,
35393542
4AE278482B2FBF1100E4D9B1 /* HTTPBodyEncodingTests.swift in Sources */,
3543+
3FE2E9692BBF7C10002CA2E1 /* RemoteBlogSettingsTests.swift in Sources */,
35403544
731BA83621DECD61000FDFCD /* SiteCreationRequestEncodingTests.swift in Sources */,
35413545
7EC60EBE22DC4F9000FB0336 /* EditorServiceRemoteTests.swift in Sources */,
35423546
931924241F1662FA0069CBCC /* JSONLoader.swift in Sources */,

0 commit comments

Comments
 (0)