Skip to content

Commit 215c914

Browse files
committed
Adds tests
1 parent 1a36bc1 commit 215c914

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@
616616
262C922126F1370000011F92 /* StorePickerError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 262C922026F1370000011F92 /* StorePickerError.swift */; };
617617
262EB5AE298C70EF009DCC36 /* SupportFormViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 262EB5AD298C70EF009DCC36 /* SupportFormViewModel.swift */; };
618618
262EB5B0298C7C3A009DCC36 /* SupportFormsDataSources.swift in Sources */ = {isa = PBXBuildFile; fileRef = 262EB5AF298C7C3A009DCC36 /* SupportFormsDataSources.swift */; };
619+
262EB5B3298D66FE009DCC36 /* SupportDataSourcesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 262EB5B2298D66FE009DCC36 /* SupportDataSourcesTests.swift */; };
619620
26309F17277D0AEA0012797F /* SafeAreaInsetsKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26309F16277D0AEA0012797F /* SafeAreaInsetsKey.swift */; };
620621
263C4CC02963784900CA7E05 /* ProductVariationGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 263C4CBF2963784900CA7E05 /* ProductVariationGenerator.swift */; };
621622
263E37E12641AD8300260D3B /* Codegen in Frameworks */ = {isa = PBXBuildFile; productRef = 263E37E02641AD8300260D3B /* Codegen */; };
@@ -2710,6 +2711,7 @@
27102711
262C922026F1370000011F92 /* StorePickerError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorePickerError.swift; sourceTree = "<group>"; };
27112712
262EB5AD298C70EF009DCC36 /* SupportFormViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupportFormViewModel.swift; sourceTree = "<group>"; };
27122713
262EB5AF298C7C3A009DCC36 /* SupportFormsDataSources.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupportFormsDataSources.swift; sourceTree = "<group>"; };
2714+
262EB5B2298D66FE009DCC36 /* SupportDataSourcesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupportDataSourcesTests.swift; sourceTree = "<group>"; };
27132715
26309F16277D0AEA0012797F /* SafeAreaInsetsKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafeAreaInsetsKey.swift; sourceTree = "<group>"; };
27142716
263C4CBF2963784900CA7E05 /* ProductVariationGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductVariationGenerator.swift; sourceTree = "<group>"; };
27152717
263EB408242C58EA00F3A15F /* ProductFormActionsFactoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductFormActionsFactoryTests.swift; sourceTree = "<group>"; };
@@ -5586,6 +5588,14 @@
55865588
path = SupportForm;
55875589
sourceTree = "<group>";
55885590
};
5591+
262EB5B1298D66E8009DCC36 /* Support */ = {
5592+
isa = PBXGroup;
5593+
children = (
5594+
262EB5B2298D66FE009DCC36 /* SupportDataSourcesTests.swift */,
5595+
);
5596+
path = Support;
5597+
sourceTree = "<group>";
5598+
};
55895599
26309F15277D0ACE0012797F /* Environment Keys */ = {
55905600
isa = PBXGroup;
55915601
children = (
@@ -7154,6 +7164,7 @@
71547164
B53A569521123D27000776C9 /* Tools */ = {
71557165
isa = PBXGroup;
71567166
children = (
7167+
262EB5B1298D66E8009DCC36 /* Support */,
71577168
E1C6535A27BD1CFC003E87D4 /* In-Person Payments */,
71587169
029700ED24FE38DE00D242F8 /* InfiniteScroll */,
71597170
028AFFB42484ED7F00693C09 /* Logging */,
@@ -11572,6 +11583,7 @@
1157211583
02EA6BFC2435EC3500FFF90A /* MockImageDownloader.swift in Sources */,
1157311584
57C9A8FC24C21BFB001E1C2F /* ReviewsCoordinatorTests.swift in Sources */,
1157411585
45B9C64523A945C0007FC4C5 /* PriceInputFormatterTests.swift in Sources */,
11586+
262EB5B3298D66FE009DCC36 /* SupportDataSourcesTests.swift in Sources */,
1157511587
AEA3F91327BEC40A00B9F555 /* ShippingLineDetailsViewModelTests.swift in Sources */,
1157611588
0286837727B25930000E5785 /* HubMenuViewModelTests.swift in Sources */,
1157711589
CC0324A3263AD9F40056C6B7 /* MockShippingLabelAccountSettings.swift in Sources */,

WooCommerce/WooCommerceTests/Testing/MockZendeskManager.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,41 @@ final class MockZendeskManager: ZendeskManagerProtocol {
7777
}
7878
}
7979

80+
extension MockZendeskManager {
81+
func createSupportRequest(formID: Int64,
82+
customFields: [Int64: String],
83+
tags: [String],
84+
subject: String,
85+
description: String,
86+
onCompletion: @escaping (Result<Void, Error>) -> Void) {
87+
// no-op
88+
}
89+
90+
func formID() -> Int64 {
91+
.zero
92+
}
93+
94+
func wcPayFormID() -> Int64 {
95+
.zero
96+
}
97+
98+
func generalTags() -> [String] {
99+
[]
100+
}
101+
102+
func wcPayTags() -> [String] {
103+
[]
104+
}
105+
106+
func generalCustomFields() -> [Int64: String] {
107+
[:]
108+
}
109+
110+
func wcPayCustomFields() -> [Int64: String] {
111+
[:]
112+
}
113+
}
114+
80115
extension MockZendeskManager: SupportManagerAdapter {
81116
/// Executed whenever the app receives a Push Notifications Token.
82117
///
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import XCTest
2+
@testable import WooCommerce
3+
4+
final class SupportDataSourcesTests: XCTestCase {
5+
6+
func test_general_formID_has_correct_value() {
7+
let dataSource = GeneralSupportDataSource()
8+
XCTAssertEqual(dataSource.formID, 360000010286)
9+
}
10+
11+
func test_general_tags_have_correct_values() {
12+
// Given
13+
let dataSource = GeneralSupportDataSource()
14+
let tagsSet = Set(dataSource.tags)
15+
let expectedSet = Set(["iOS", "woo-mobile-sdk", "jetpack"])
16+
17+
// When & Then
18+
XCTAssertTrue(expectedSet.isSubset(of: tagsSet))
19+
}
20+
21+
func test_general_custom_fields_have_correct_ids() {
22+
let dataSource = GeneralSupportDataSource()
23+
let customFieldsKeys = dataSource.customFields.keys.sorted()
24+
XCTAssertEqual(customFieldsKeys, [
25+
360008583691, // App Language
26+
360000103103, // Current Site
27+
360009311651, // Source Platform
28+
360000086966, // Network Information
29+
360000086866, // App Version
30+
22871957, // Legacy Logs
31+
25176023, // Sub Category
32+
10901699622036, // Logs
33+
360000089123 // Device Free Space
34+
].sorted())
35+
}
36+
37+
func test_wcpay_formID_has_correctValue() {
38+
let dataSource = WCPaySupportDataSource()
39+
XCTAssertEqual(dataSource.formID, 189946)
40+
}
41+
42+
func test_wcpay_tags_have_correct_values() {
43+
let dataSource = WCPaySupportDataSource()
44+
let tagsSet = Set(dataSource.tags)
45+
let expectedSet = Set(["iOS", "woo-mobile-sdk", "woocommerce_payments", "support", "payment", "product_area_woo_payment_gateway"])
46+
47+
// When & Then
48+
XCTAssertTrue(expectedSet.isSubset(of: tagsSet))
49+
}
50+
51+
func test_wcpay_custom_fields_have_correct_values() {
52+
let dataSource = WCPaySupportDataSource()
53+
let customFieldsKeys = dataSource.customFields.keys.sorted()
54+
XCTAssertEqual(customFieldsKeys, [
55+
360008583691, // App Language
56+
360000103103, // Current Site
57+
360009311651, // Source Platform
58+
360000086966, // Network Information
59+
360000086866, // App Version
60+
22871957, // Legacy Logs
61+
25176003, // Category
62+
25176023, // Sub Category
63+
10901699622036, // Logs
64+
360000089123 // Device Free Space
65+
].sorted())
66+
}
67+
}

0 commit comments

Comments
 (0)