Skip to content

Commit

Permalink
Move account setup to beforeEach
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasberglund committed Aug 20, 2024
1 parent 2585294 commit d3f17b2
Showing 1 changed file with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,21 @@ import org.junit.jupiter.api.extension.BeforeEachCallback
import org.junit.jupiter.api.extension.ExtensionContext

class AccountTestRule : BeforeEachCallback {

private val partnerAccount: String?
private val client =
SimpleMullvadHttpClient(InstrumentationRegistry.getInstrumentation().targetContext)
private val partnerAuth: String? =
InstrumentationRegistry.getArguments().getString(PARTNER_AUTH, null)
lateinit var validAccountNumber: String
lateinit var invalidAccountNumber: String

val validAccountNumber: String
val invalidAccountNumber: String

init {
override fun beforeEach(context: ExtensionContext) {
InstrumentationRegistry.getArguments().also { bundle ->
partnerAccount = bundle.getString(PARTNER_AUTH)

if (partnerAccount != null) {
if (partnerAuth != null) {
validAccountNumber = client.createAccount()
client.addTimeToAccountUsingPartnerAuth(
accountNumber = validAccountNumber,
daysToAdd = 1,
partnerAuth = partnerAccount
partnerAuth = partnerAuth
)
} else {
validAccountNumber =
Expand All @@ -38,6 +35,4 @@ class AccountTestRule : BeforeEachCallback {
bundle.getRequiredArgument(INVALID_TEST_ACCOUNT_NUMBER_ARGUMENT_KEY)
}
}

override fun beforeEach(context: ExtensionContext) {}
}

0 comments on commit d3f17b2

Please sign in to comment.