-
Notifications
You must be signed in to change notification settings - Fork 986
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MBL-1676: When a project is no longer allowed to collect, view reward…
…s menu should not filter rewards nor show the select button (#2116)
- Loading branch information
Showing
5 changed files
with
166 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
app/src/test/java/com/kickstarter/viewmodels/usecases/GetShippingRulesUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.kickstarter.viewmodels.usecases | ||
|
||
import com.kickstarter.KSRobolectricTestCase | ||
import com.kickstarter.mock.factories.ConfigFactory | ||
import com.kickstarter.mock.factories.ProjectFactory | ||
import com.kickstarter.mock.factories.RewardFactory | ||
import com.kickstarter.mock.factories.ShippingRuleFactory | ||
import com.kickstarter.mock.services.MockApolloClientV2 | ||
import com.kickstarter.models.Project | ||
import com.kickstarter.models.Reward | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.toList | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.test.UnconfinedTestDispatcher | ||
import kotlinx.coroutines.test.advanceUntilIdle | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Test | ||
|
||
class GetShippingRulesUseCaseTest : KSRobolectricTestCase() { | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
@Test | ||
fun `test useCase returns project reward list unfiltered when not collecting`() = runTest { | ||
val apolloClient = MockApolloClientV2() | ||
val config = ConfigFactory.configForCA() | ||
val project = ProjectFactory.project() | ||
.toBuilder() | ||
.state(Project.STATE_SUCCESSFUL) | ||
.isInPostCampaignPledgingPhase(false) | ||
.postCampaignPledgingEnabled(false) | ||
.build() | ||
|
||
val dispatcher = UnconfinedTestDispatcher(testScheduler) | ||
val scope = backgroundScope | ||
|
||
val useCase = GetShippingRulesUseCase(apolloClient, project, config, scope, dispatcher) | ||
|
||
val state = mutableListOf<ShippingRulesState>() | ||
scope.launch(dispatcher) { | ||
useCase.invoke() | ||
useCase.shippingRulesState.toList(state) | ||
} | ||
advanceUntilIdle() | ||
|
||
assertEquals(state.size, 2) | ||
assertEquals(state.last().filteredRw, project.rewards()) | ||
} | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
@Test | ||
fun `test useCase returns project reward list filtered when collecting late pledges`() = runTest { | ||
val apolloClient = MockApolloClientV2() | ||
val config = ConfigFactory.configForUSUser() | ||
|
||
val shippingRule1 = ShippingRuleFactory.canadaShippingRule() | ||
val shippingRule2 = ShippingRuleFactory.germanyShippingRule() | ||
val shippingRule3 = ShippingRuleFactory.usShippingRule() | ||
|
||
val reward = RewardFactory.reward().toBuilder() | ||
.shippingPreference(Reward.ShippingPreference.RESTRICTED.name) | ||
.shippingType(Reward.SHIPPING_TYPE_MULTIPLE_LOCATIONS) | ||
.isAvailable(true) | ||
.shippingRules(listOf(shippingRule1)) | ||
.build() | ||
val reward2 = reward.toBuilder() | ||
.shippingRules(listOf(shippingRule1, shippingRule2, shippingRule3)) | ||
.build() | ||
|
||
val project = ProjectFactory.project() | ||
.toBuilder() | ||
.rewards(listOf(reward, reward2)) | ||
.state(Project.STATE_SUCCESSFUL) | ||
.isInPostCampaignPledgingPhase(true) | ||
.postCampaignPledgingEnabled(true) | ||
.build() | ||
|
||
val dispatcher = UnconfinedTestDispatcher(testScheduler) | ||
val scope = backgroundScope | ||
|
||
val useCase = GetShippingRulesUseCase(apolloClient, project, config, scope, dispatcher) | ||
|
||
val state = mutableListOf<ShippingRulesState>() | ||
scope.launch(dispatcher) { | ||
useCase.invoke() | ||
useCase.shippingRulesState.toList(state) | ||
} | ||
advanceUntilIdle() | ||
|
||
assertEquals(state.size, 2) | ||
assertNotSame(state.last().filteredRw, project.rewards()) | ||
assertEquals(state.last().filteredRw.size, 1) | ||
assertEquals(state.last().filteredRw.first(), reward2) | ||
} | ||
} |