@@ -136,4 +136,155 @@ final class ReceiptEligibilityUseCaseTests: XCTestCase {
136136 // Then
137137 XCTAssertTrue ( isEligible)
138138 }
139+
140+ // MARK: - Send Receipt After Payment
141+
142+ func test_isEligibleSendingReceiptAfterPayment_when_feature_flag_is_disabled_then_returns_false( ) {
143+ // Given
144+ let featureFlag = MockFeatureFlagService ( isSendReceiptAfterPaymentEnabled: false )
145+ let stores = MockStoresManager ( sessionManager: . makeForTesting( ) )
146+ let sut = ReceiptEligibilityUseCase ( stores: stores, featureFlagService: featureFlag)
147+
148+ // When
149+ let isEligible : Bool = waitFor { promise in
150+ sut. isEligibleSendingReceiptAfterPayment ( onCompletion: { result in
151+ promise ( result)
152+ } )
153+ }
154+
155+ // Then
156+ XCTAssertFalse ( isEligible)
157+ }
158+
159+ func test_isEligibleSendingReceiptAfterPayment_when_plugins_are_inactive_then_returns_false( ) {
160+ // Given
161+ let featureFlag = MockFeatureFlagService ( isSendReceiptAfterPaymentEnabled: true )
162+ let stores = MockStoresManager ( sessionManager: . makeForTesting( ) )
163+ let wooCommercePlugin = SystemPlugin . fake ( ) . copy ( name: " WooCommerce " , version: " 9.6.0 " , active: false )
164+ let wooPaymentsPlugin = SystemPlugin . fake ( ) . copy ( name: " WooPayments " , version: " 8.9.0 " , active: false )
165+
166+ stores. whenReceivingAction ( ofType: SystemStatusAction . self) { action in
167+ switch action {
168+ case let . fetchSystemPlugin( _, systemPluginName, onCompletion) :
169+ if systemPluginName == " WooCommerce " {
170+ onCompletion ( wooCommercePlugin)
171+ } else if systemPluginName == " WooPayments " {
172+ onCompletion ( wooPaymentsPlugin)
173+ }
174+ default :
175+ XCTFail ( " Unexpected action " )
176+ }
177+ }
178+
179+ let sut = ReceiptEligibilityUseCase ( stores: stores, featureFlagService: featureFlag)
180+
181+ // When
182+ let isEligible : Bool = waitFor { promise in
183+ sut. isEligibleSendingReceiptAfterPayment ( onCompletion: { result in
184+ promise ( result)
185+ } )
186+ }
187+
188+ // Then
189+ XCTAssertFalse ( isEligible)
190+ }
191+
192+ func test_isEligibleSendingReceiptAfterPayment_when_plugins_are_supported_then_returns_true( ) {
193+ // Given
194+ let featureFlag = MockFeatureFlagService ( isSendReceiptAfterPaymentEnabled: true )
195+ let stores = MockStoresManager ( sessionManager: . makeForTesting( ) )
196+ let wooCommercePlugin = SystemPlugin . fake ( ) . copy ( name: " WooCommerce " , version: " 9.5.0 " , active: true )
197+ let wooPaymentsPlugin = SystemPlugin . fake ( ) . copy ( name: " WooPayments " , version: " 8.6.0 " , active: true )
198+
199+ stores. whenReceivingAction ( ofType: SystemStatusAction . self) { action in
200+ switch action {
201+ case let . fetchSystemPlugin( _, systemPluginName, onCompletion) :
202+ if systemPluginName == " WooCommerce " {
203+ onCompletion ( wooCommercePlugin)
204+ } else if systemPluginName == " WooPayments " {
205+ onCompletion ( wooPaymentsPlugin)
206+ }
207+ default :
208+ XCTFail ( " Unexpected action " )
209+ }
210+ }
211+
212+ let sut = ReceiptEligibilityUseCase ( stores: stores, featureFlagService: featureFlag)
213+
214+ // When
215+ let isEligible : Bool = waitFor { promise in
216+ sut. isEligibleSendingReceiptAfterPayment ( onCompletion: { result in
217+ promise ( result)
218+ } )
219+ }
220+
221+ // Then
222+ XCTAssertTrue ( isEligible)
223+ }
224+
225+ func test_isEligibleSendingReceiptAfterPayment_when_plugins_are_supported_dev_then_returns_true( ) {
226+ // Given
227+ let featureFlag = MockFeatureFlagService ( isSendReceiptAfterPaymentEnabled: true )
228+ let stores = MockStoresManager ( sessionManager: . makeForTesting( ) )
229+ let wooCommercePlugin = SystemPlugin . fake ( ) . copy ( name: " WooCommerce " , version: " 9.6.0-dev-1181231238 " , active: true )
230+ let wooPaymentsPlugin = SystemPlugin . fake ( ) . copy ( name: " WooPayments " , version: " 8.6.0-test-1 " , active: true )
231+
232+ stores. whenReceivingAction ( ofType: SystemStatusAction . self) { action in
233+ switch action {
234+ case let . fetchSystemPlugin( _, systemPluginName, onCompletion) :
235+ if systemPluginName == " WooCommerce " {
236+ onCompletion ( wooCommercePlugin)
237+ } else if systemPluginName == " WooPayments " {
238+ onCompletion ( wooPaymentsPlugin)
239+ }
240+ default :
241+ XCTFail ( " Unexpected action " )
242+ }
243+ }
244+
245+ let sut = ReceiptEligibilityUseCase ( stores: stores, featureFlagService: featureFlag)
246+
247+ // When
248+ let isEligible : Bool = waitFor { promise in
249+ sut. isEligibleSendingReceiptAfterPayment ( onCompletion: { result in
250+ promise ( result)
251+ } )
252+ }
253+
254+ // Then
255+ XCTAssertTrue ( isEligible)
256+ }
257+
258+ func test_isEligibleSendingReceiptAfterPayment_when_woopayments_version_is_incorrect_then_returns_false( ) {
259+ // Given
260+ let featureFlag = MockFeatureFlagService ( isSendReceiptAfterPaymentEnabled: true )
261+ let stores = MockStoresManager ( sessionManager: . makeForTesting( ) )
262+ let wooCommercePlugin = SystemPlugin . fake ( ) . copy ( name: " WooCommerce " , version: " 9.5.0 " , active: true )
263+ let wooPaymentsPlugin = SystemPlugin . fake ( ) . copy ( name: " WooPayments " , version: " 5.0.0-dev " , active: true )
264+
265+ stores. whenReceivingAction ( ofType: SystemStatusAction . self) { action in
266+ switch action {
267+ case let . fetchSystemPlugin( _, systemPluginName, onCompletion) :
268+ if systemPluginName == " WooCommerce " {
269+ onCompletion ( wooCommercePlugin)
270+ } else if systemPluginName == " WooPayments " {
271+ onCompletion ( wooPaymentsPlugin)
272+ }
273+ default :
274+ XCTFail ( " Unexpected action " )
275+ }
276+ }
277+
278+ let sut = ReceiptEligibilityUseCase ( stores: stores, featureFlagService: featureFlag)
279+
280+ // When
281+ let isEligible : Bool = waitFor { promise in
282+ sut. isEligibleSendingReceiptAfterPayment ( onCompletion: { result in
283+ promise ( result)
284+ } )
285+ }
286+
287+ // Then
288+ XCTAssertFalse ( isEligible)
289+ }
139290}
0 commit comments