@@ -262,4 +262,60 @@ final class RewardsCollectionViewModelTests: TestCase {
262262 )
263263 }
264264 }
265+
266+ func test_selectLocation_outputsNilShippingRule_forProjectWithNoShippableRewards( ) {
267+ let noReward = Reward . noReward
268+ let digitalReward = Reward . template
269+ |> Reward . lens. isAvailable .~ true
270+ |> Reward . lens. shippingRulesExpanded .~ [ ]
271+ |> Reward . lens. shipping .~ Reward . Shipping (
272+ enabled: true ,
273+ location: nil ,
274+ preference: Reward . Shipping. Preference. none,
275+ summary: " Digital reward " ,
276+ type: . noShipping
277+ )
278+
279+ let localShippingReward = Reward . template
280+ |> Reward . lens. isAvailable .~ true
281+ |> Reward . lens. shippingRulesExpanded .~ [ ]
282+ |> Reward . lens. shipping .~ Reward . Shipping (
283+ enabled: true ,
284+ location: Reward . Shipping. Location (
285+ id: 1 ,
286+ localizedName: " Pickup your stuff "
287+ ) ,
288+ preference: Reward . Shipping. Preference. local,
289+ summary: " Digital reward " ,
290+ type: . noShipping
291+ )
292+
293+ let rewards = [
294+ noReward,
295+ digitalReward,
296+ localShippingReward
297+ ]
298+
299+ let testProject = Project . template
300+ |> Project . lens. rewardData. rewards .~ rewards
301+
302+ self . vm. configure ( with: testProject, refTag: nil , context: . createPledge, secretRewardToken: nil )
303+ // Because the shipping location is powered by the available shipping rules,
304+ // if there are no shippable rewards, the location element may be hidden and output `nil` once.
305+ self . vm. inputs. shippingLocationSelected ( nil )
306+ self . vm. viewDidLoad ( )
307+ self . vm. viewDidLayoutSubviews ( )
308+
309+ self . vm. inputs. rewardSelected ( with: digitalReward. id)
310+
311+ self . goToCustomizeYourReward. assertDidEmitValue ( )
312+
313+ if let pledgeData = self . goToCustomizeYourReward. lastValue {
314+ XCTAssertEqual (
315+ pledgeData. selectedShippingRule,
316+ nil ,
317+ " Pledge data should have no shipping rule, because the reward is digital "
318+ )
319+ }
320+ }
265321}
0 commit comments