Skip to content

Commit 574db02

Browse files
committed
Add tests for LeaderboardListMapper
1 parent e6db16b commit 574db02

File tree

3 files changed

+453
-0
lines changed

3 files changed

+453
-0
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,8 @@
722722
DEC51AFB2769C66B009F3DF4 /* SystemStatusMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC51AFA2769C66B009F3DF4 /* SystemStatusMapperTests.swift */; };
723723
DEC51B02276AFB35009F3DF4 /* SystemStatus+DropinMustUsePlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC51B01276AFB34009F3DF4 /* SystemStatus+DropinMustUsePlugin.swift */; };
724724
DEF13C5029629EEA0024A02B /* user-complete-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DEF13C4F29629EEA0024A02B /* user-complete-without-data.json */; };
725+
DEF13C562965689F0024A02B /* LeaderboardListMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEF13C552965689F0024A02B /* LeaderboardListMapperTests.swift */; };
726+
DEF13C5829656A610024A02B /* leaderboards-products-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DEF13C5729656A600024A02B /* leaderboards-products-without-data.json */; };
725727
DEFBA74E29485A7600C35BA9 /* RESTRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEFBA74D29485A7600C35BA9 /* RESTRequest.swift */; };
726728
DEFBA7542949CE6600C35BA9 /* RequestProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEFBA7532949CE6600C35BA9 /* RequestProcessor.swift */; };
727729
DEFBA7562949D17400C35BA9 /* DefaultRequestAuthenticatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEFBA7552949D17300C35BA9 /* DefaultRequestAuthenticatorTests.swift */; };
@@ -1515,6 +1517,8 @@
15151517
DEC51AFA2769C66B009F3DF4 /* SystemStatusMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemStatusMapperTests.swift; sourceTree = "<group>"; };
15161518
DEC51B01276AFB34009F3DF4 /* SystemStatus+DropinMustUsePlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SystemStatus+DropinMustUsePlugin.swift"; sourceTree = "<group>"; };
15171519
DEF13C4F29629EEA0024A02B /* user-complete-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "user-complete-without-data.json"; sourceTree = "<group>"; };
1520+
DEF13C552965689F0024A02B /* LeaderboardListMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeaderboardListMapperTests.swift; sourceTree = "<group>"; };
1521+
DEF13C5729656A600024A02B /* leaderboards-products-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "leaderboards-products-without-data.json"; sourceTree = "<group>"; };
15181522
DEFBA74D29485A7600C35BA9 /* RESTRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RESTRequest.swift; sourceTree = "<group>"; };
15191523
DEFBA7532949CE6600C35BA9 /* RequestProcessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestProcessor.swift; sourceTree = "<group>"; };
15201524
DEFBA7552949D17300C35BA9 /* DefaultRequestAuthenticatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultRequestAuthenticatorTests.swift; sourceTree = "<group>"; };
@@ -2162,6 +2166,7 @@
21622166
B524194621AC643900D6FC0A /* device-settings.json */,
21632167
24F98C612502EFF600F49B68 /* feature-flags-load-all.json */,
21642168
268B68FA24C87384007EBF1D /* leaderboards-products.json */,
2169+
DEF13C5729656A600024A02B /* leaderboards-products-without-data.json */,
21652170
E18152C128F85E0A0011A0EC /* iap-products.json */,
21662171
E16C59B628F92782007D55BB /* iap-sample-receipt.json */,
21672172
E16C59B828F927CA007D55BB /* iap-order-create.json */,
@@ -2521,6 +2526,7 @@
25212526
isa = PBXGroup;
25222527
children = (
25232528
B505F6D220BEE3A500BB1B69 /* AccountMapperTests.swift */,
2529+
DEF13C552965689F0024A02B /* LeaderboardListMapperTests.swift */,
25242530
DE2E8EAA2954170D002E4B14 /* WordPressSiteMapperTests.swift */,
25252531
9387A6EF226E3F15001B53D7 /* AccountSettingsMapperTests.swift */,
25262532
077F39DB26A58F4800ABEADC /* SystemPluginMapperTests.swift */,
@@ -3011,6 +3017,7 @@
30113017
31054718262E2F5E00C5C02B /* wcpay-payment-intent-requires-confirmation.json in Resources */,
30123018
D8FBFF2922D52AFB006E3336 /* order-stats-v4-year.json in Resources */,
30133019
D865CE65278CA202002C8520 /* stripe-payment-intent-canceled.json in Resources */,
3020+
DEF13C5829656A610024A02B /* leaderboards-products-without-data.json in Resources */,
30143021
AED8AEBA272A97B400663FCC /* null-data.json in Resources */,
30153022
02BA23CA22EEF62C009539E7 /* order-stats-v4-wcadmin-activated.json in Resources */,
30163023
31A451D627863A2E00FE81AA /* stripe-account-unknown-status.json in Resources */,
@@ -3525,6 +3532,7 @@
35253532
isa = PBXSourcesBuildPhase;
35263533
buildActionMask = 2147483647;
35273534
files = (
3535+
DEF13C562965689F0024A02B /* LeaderboardListMapperTests.swift in Sources */,
35283536
45551F142523E7FF007EF104 /* UserAgentTests.swift in Sources */,
35293537
03EB998A2906AB0C00F06A39 /* JustInTimeMessagesRemoteTests.swift in Sources */,
35303538
DE34051D28BDF1C900CF0D97 /* JetpackConnectionURLMapperTests.swift in Sources */,
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import XCTest
2+
@testable import Networking
3+
4+
final class LeaderboardListMapperTests: XCTestCase {
5+
6+
/// Verifies that leaderboard list is parsed.
7+
///
8+
func test_mapper_parses_leaderboard_list_in_response_with_data_envelope() throws {
9+
// Given
10+
let list = try mapLeaderboardListResponse()
11+
12+
// Then
13+
XCTAssertFalse(list.isEmpty)
14+
}
15+
16+
/// Verifies that the leaderboard list is parsed when the response has no data envelope.
17+
///
18+
func test_mapper_parses_leaderboard_list_in_response_without_data_envelope() throws {
19+
// Given
20+
let list = try mapLeaderboardListResponseWithoutDataEnvelope()
21+
22+
// Then
23+
XCTAssertFalse(list.isEmpty)
24+
}
25+
}
26+
27+
// MARK: - Test Helpers
28+
///
29+
private extension LeaderboardListMapperTests {
30+
31+
/// Returns the LeaderboardListMapper output upon receiving `filename` (Data Encoded)
32+
///
33+
func mapLeaderboardList(from filename: String) throws -> [Leaderboard] {
34+
guard let response = Loader.contentsOf(filename) else {
35+
throw FileNotFoundError()
36+
}
37+
38+
return try LeaderboardListMapper().map(response: response)
39+
}
40+
41+
/// Returns the LeaderboardListMapper output from `products.json`
42+
///
43+
func mapLeaderboardListResponse() throws -> [Leaderboard] {
44+
return try mapLeaderboardList(from: "leaderboards-products")
45+
}
46+
47+
/// Returns the LeaderboardListMapper output from `leaderboards-products-without-data.json`
48+
///
49+
func mapLeaderboardListResponseWithoutDataEnvelope() throws -> [Leaderboard] {
50+
return try mapLeaderboardList(from: "leaderboards-products-without-data")
51+
}
52+
53+
struct FileNotFoundError: Error {}
54+
}

0 commit comments

Comments
 (0)