@@ -4,11 +4,7 @@ import XCTest
44final class RemoteBlogSettingsTests : XCTestCase {
55
66 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) )
7+ let json = try loadJSONSettings ( )
128 // FIXME: The init logic is currently in BlogServiceRemoteREST. We'll test it from there first, then update the test with the new location.
139 let blogService = BlogServiceRemoteREST ( wordPressComRestApi: MockWordPressComRestApi ( ) , siteID: 0 )
1410 let settings = try XCTUnwrap ( blogService. remoteBlogSetting ( fromJSONDictionary: json) )
@@ -27,4 +23,38 @@ final class RemoteBlogSettingsTests: XCTestCase {
2723 // Note that here we're obviously testing only one of the possible paths.
2824 XCTAssertEqual ( settings. defaultPostFormat, " standard " )
2925 }
26+
27+ func testToDictionary( ) throws {
28+ // Rather than creating an object and checking the resulting NSDictionary,
29+ // let's load one, convert it, then compare the source and converted dictionaries
30+ let json = try loadJSONSettings ( )
31+ // FIXME: The init logic is currently in BlogServiceRemoteREST. We'll test it from there first, then update the test with the new location.
32+ let blogService = BlogServiceRemoteREST ( wordPressComRestApi: MockWordPressComRestApi ( ) , siteID: 0 )
33+ let settings = try XCTUnwrap ( blogService. remoteBlogSetting ( fromJSONDictionary: json) )
34+
35+ let dictionary = try XCTUnwrap ( blogService. remoteSettings ( toDictionary: settings) )
36+
37+ // name and tagline have different keys when encoded...
38+ XCTAssertEqual ( dictionary [ " blogname " ] as? String , settings. name) // from JSON this is "name"
39+ XCTAssertEqual ( dictionary [ " blogdescription " ] as? String , settings. tagline) // from JSON this is "description"
40+ // Flattened settings properties
41+ XCTAssertEqual ( dictionary [ " blog_public " ] as? NSNumber , settings. privacy)
42+ XCTAssertEqual ( dictionary [ " lang_id " ] as? NSNumber , settings. languageID)
43+ XCTAssertEqual ( dictionary [ " site_icon " ] as? NSNumber , settings. iconMediaID)
44+ XCTAssertEqual ( dictionary [ " gmt_offset " ] as? NSNumber , settings. gmtOffset)
45+ // And so on...
46+
47+ // defaultPostFormat has custom encoding, so let's test it explicitly.
48+ // Note that here we're obviously testing only one of the possible paths.
49+ XCTAssertEqual ( dictionary [ " default_post_format " ] as? String , settings. defaultPostFormat)
50+ }
51+
52+ func loadJSONSettings( ) throws -> [ String : Any ] {
53+ let jsonPath = try XCTUnwrap (
54+ Bundle ( for: type ( of: self ) )
55+ . path ( forResource: " rest-site-settings " , ofType: " json " )
56+ )
57+ let json = try XCTUnwrap ( JSONLoader ( ) . loadFile ( jsonPath) )
58+ return json
59+ }
3060}
0 commit comments