How to use xcontext method of io.kotest.core.spec.style.scopes.FunSpecContainerScope class

Best Kotest code snippet using io.kotest.core.spec.style.scopes.FunSpecContainerScope.xcontext

TransactionMirrorerTest.kt

Source:TransactionMirrorerTest.kt Github

copy

Full Screen

...264 transactions = setOf(manuallyAddedTransaction().id)265 )266 }267 // This error shouldn't be possible, so we're going to ignore it for now268 xcontext("once a complement is created") {269 transactionMirrorer.mirrorTransactions()270 val updatedComplement = manuallyAddedTransactionComplement().copy(271 amount = 300_000,272 date = manuallyAddedTransaction().date.plusDays(1)273 )274 setUpServerDatabase {275 addTransactions(updatedComplement)276 }277 test("nothing happens") {278 val beginningServerKnowledge = serverDatabase.currentServerKnowledge279 transactionMirrorer.mirrorTransactions()280 assertSoftly {281 withClue("Server knowledge should not change") {282 serverDatabase.currentServerKnowledge shouldBe beginningServerKnowledge283 }284 localDatabase.shouldMatchServer(serverDatabase)285 localDatabase.shouldHaveAllTransactionsProcessedExcept(286 setOf(287 updatedTransaction.id,288 updatedComplement.id289 ),290 )291 }292 }293 context("once the transaction is unflagged") {294 transactionMirrorer.mirrorTransactions()295 setUpServerDatabase {296 addTransactions(updatedTransaction)297 }298 test("the conflict is resolved") {299 val beginningServerKnowledge = serverDatabase.currentServerKnowledge300 transactionMirrorer.mirrorTransactions()301 assertSoftly {302 withClue("Server knowledge should not change") {303 serverDatabase.currentServerKnowledge shouldBe beginningServerKnowledge304 }305 updatedComplement.thisOnServerShould(serverDatabase) {306 amount shouldBe updatedComplement.amount307 date shouldBe updatedComplement.date308 payeeName shouldBe updatedComplement.payeeName309 memo shouldBe updatedComplement.memo310 cleared shouldBe CLEARED311 approved.shouldBeTrue()312 deleted.shouldBeFalse()313 accountId shouldBe TO_ACCOUNT_ID.plainUuid314 }315 updatedTransaction.thisOnServerShould(serverDatabase) {316 amount shouldBe updatedTransaction.amount317 date shouldBe updatedTransaction.date318 payeeName shouldBe updatedTransaction.payeeName319 memo shouldBe updatedTransaction.memo320 cleared shouldBe CLEARED321 flagColor shouldBe null322 approved.shouldBeTrue()323 deleted.shouldBeFalse()324 accountId shouldBe updatedTransaction.accountId.plainUuid325 }326 localDatabase.shouldMatchServer(serverDatabase)327 localDatabase.shouldHaveAllTransactionsProcessed()328 }329 }330 }331 }332 }333 context("with an UP_TO_DATE complement") {334 setUpServerDatabase {335 addTransactions(manuallyAddedTransactionComplement())336 }337 setUpLocalDatabase {338 addTransactions(manuallyAddedTransactionComplement(UP_TO_DATE))339 }340 test("complement is updated") {341 transactionMirrorer.mirrorTransactions()342 updatedTransaction.complementOnServerShould(serverDatabase, TO_ACCOUNT_AND_BUDGET) {343 amount shouldBe -updatedTransaction.amount344 date shouldBe updatedTransaction.date345 flagColor shouldBe BLUE346 approved.shouldBeFalse()347 payeeName shouldBe manuallyAddedTransactionComplement().payeeName348 memo shouldBe manuallyAddedTransactionComplement().memo349 deleted.shouldBeFalse()350 accountId shouldBe TO_ACCOUNT_ID.plainUuid351 }352 localDatabase.shouldMatchServer(serverDatabase)353 localDatabase.shouldHaveAllTransactionsProcessed()354 }355 }356 context("with a CREATED complement") {357 setUpServerDatabase {358 addTransactions(manuallyAddedTransactionComplement())359 }360 test("complement is updated") {361 transactionMirrorer.mirrorTransactions()362 updatedTransaction.complementOnServerShould(serverDatabase, TO_ACCOUNT_AND_BUDGET) {363 amount shouldBe -updatedTransaction.amount364 date shouldBe updatedTransaction.date365 flagColor shouldBe BLUE366 approved.shouldBeFalse()367 payeeName shouldBe manuallyAddedTransactionComplement().payeeName368 memo shouldBe manuallyAddedTransactionComplement().memo369 deleted.shouldBeFalse()370 accountId shouldBe TO_ACCOUNT_ID.plainUuid371 }372 localDatabase.shouldMatchServer(serverDatabase)373 localDatabase.shouldHaveAllTransactionsProcessed()374 }375 }376 context("with an UPDATED complement") {377 val updatedComplement = manuallyAddedTransactionComplement(UPDATED).copy(amount = -400_000)378 setUpServerDatabase {379 addTransactions(updatedComplement)380 }381 setUpLocalDatabase {382 addTransactions(manuallyAddedTransactionComplement(UP_TO_DATE))383 }384 test("both are flagged as errors") {385 transactionMirrorer.mirrorTransactions()386 updatedTransaction.thisOnServerShould(serverDatabase) {387 flagColor shouldBe RED388 approved.shouldBeFalse()389 memo shouldBe "ERROR: Both this and its complement have been updated; update both to " +390 "the same amount and date to bring them back in sync. • " + updatedTransaction.memo391 amount shouldBe updatedTransaction.amount392 date shouldBe updatedTransaction.date393 payeeName shouldBe updatedTransaction.payeeName394 accountId shouldBe updatedTransaction.accountId.plainUuid395 deleted.shouldBeFalse()396 }397 updatedComplement.thisOnServerShould(serverDatabase) {398 flagColor shouldBe RED399 approved.shouldBeFalse()400 memo shouldBe "ERROR: Both this and its complement have been updated; update both to " +401 "the same amount and date to bring them back in sync. • " + updatedComplement.memo402 amount shouldBe updatedComplement.amount403 date shouldBe updatedComplement.date404 payeeName shouldBe updatedComplement.payeeName405 accountId shouldBe updatedComplement.accountId.plainUuid406 deleted.shouldBeFalse()407 }408 localDatabase.shouldMatchServer(serverDatabase)409 localDatabase.shouldHaveAllTransactionsProcessedExcept(410 transactions = setOf(411 manuallyAddedTransaction().id,412 manuallyAddedTransactionComplement().id413 )414 )415 }416 context("once one side updates") {417 transactionMirrorer.mirrorTransactions()418 setUpServerDatabase {419 addTransactions(manuallyAddedTransactionComplement().copy(approved = true))420 }421 test("nothing happens") {422 val beginningServerKnowledge = serverDatabase.currentServerKnowledge423 transactionMirrorer.mirrorTransactions()424 assertSoftly {425 withClue("Server knowledge should not change") {426 serverDatabase.currentServerKnowledge shouldBe beginningServerKnowledge427 }428 localDatabase.shouldMatchServer(serverDatabase)429 localDatabase.shouldHaveAllTransactionsProcessedExcept(430 setOf(431 manuallyAddedTransactionComplement().id,432 manuallyAddedTransaction().id433 ),434 )435 }436 }437 context("once the other side updates") {438 transactionMirrorer.mirrorTransactions()439 setUpServerDatabase {440 addTransactions(manuallyAddedTransaction().copy(cleared = CLEARED))441 }442 test("conflict is resolved") {443 val beginningServerKnowledge = serverDatabase.currentServerKnowledge444 transactionMirrorer.mirrorTransactions()445 withClue("Server knowledge should not change") {446 serverDatabase.currentServerKnowledge shouldBe beginningServerKnowledge447 }448 manuallyAddedTransactionComplement().thisOnServerShould(serverDatabase) {449 amount shouldBe manuallyAddedTransactionComplement().amount450 date shouldBe manuallyAddedTransactionComplement().date451 payeeName shouldBe manuallyAddedTransactionComplement().payeeName452 memo shouldBe manuallyAddedTransactionComplement().memo453 cleared shouldBe CLEARED454 approved.shouldBeTrue()455 deleted.shouldBeFalse()456 accountId shouldBe TO_ACCOUNT_ID.plainUuid457 }458 manuallyAddedTransaction().thisOnServerShould(serverDatabase) {459 amount shouldBe manuallyAddedTransaction().amount460 date shouldBe manuallyAddedTransaction().date461 payeeName shouldBe manuallyAddedTransaction().payeeName462 memo shouldBe manuallyAddedTransaction().memo463 cleared shouldBe CLEARED464 flagColor shouldBe null465 approved.shouldBeTrue()466 deleted.shouldBeFalse()467 accountId shouldBe manuallyAddedTransaction().accountId.plainUuid468 }469 localDatabase.shouldMatchServer(serverDatabase)470 localDatabase.shouldHaveAllTransactionsProcessed()471 }472 }473 }474 }475 context("with a DELETED complement") {476 val deletedComplement = manuallyAddedTransactionComplement(UP_TO_DATE).copy(477 processedState = DELETED478 )479 setUpServerDatabase {480 addTransactions(deletedComplement)481 }482 setUpLocalDatabase {483 addTransactions(manuallyAddedTransactionComplement(UP_TO_DATE))484 }485 test("this transaction is marked as deleted") {486 transactionMirrorer.mirrorTransactions()487 updatedTransaction.thisOnServerShould(serverDatabase) {488 flagColor shouldBe RED489 approved.shouldBeFalse()490 deleted.shouldBeFalse()491 amount shouldBe updatedTransaction.amount492 date shouldBe updatedTransaction.date493 payeeName shouldBe updatedTransaction.payeeName494 memo shouldBe updatedTransaction.memo495 accountId shouldBe FROM_ACCOUNT_ID.plainUuid496 }497 localDatabase.shouldMatchServer(serverDatabase)498 localDatabase.shouldHaveAllTransactionsProcessedExcept(setOf(updatedTransaction.id))499 }500 }501 }502 context("with a DELETED transaction") {503 val deletedTransaction = manuallyAddedTransaction(UP_TO_DATE).copy(processedState = DELETED)504 setUpServerDatabase {505 addTransactions(deletedTransaction)506 }507 setUpLocalDatabase {508 addTransactions(manuallyAddedTransaction(UP_TO_DATE))509 }510 context("with no complement") {511 val beginningServerKnowledge = serverDatabase.currentServerKnowledge512 test("nothing happens") {513 transactionMirrorer.mirrorTransactions()514 withClue("Server knowledge should not change") {515 serverDatabase.currentServerKnowledge shouldBe beginningServerKnowledge516 }517 localDatabase.shouldMatchServer(serverDatabase)518 }519 }520 context("with an UP_TO_DATE complement") {521 setUpServerDatabase {522 addTransactions(manuallyAddedTransactionComplement())523 }524 setUpLocalDatabase {525 addTransactions(manuallyAddedTransactionComplement(UP_TO_DATE))526 }527 test("complement is marked as deleted") {528 transactionMirrorer.mirrorTransactions()529 deletedTransaction.complementOnServerShould(serverDatabase, TO_ACCOUNT_AND_BUDGET) {530 flagColor shouldBe RED531 approved.shouldBeFalse()532 deleted.shouldBeFalse()533 amount shouldBe manuallyAddedTransactionComplement().amount534 date shouldBe manuallyAddedTransactionComplement().date535 payeeName shouldBe manuallyAddedTransactionComplement().payeeName536 memo shouldBe manuallyAddedTransactionComplement().memo537 accountId shouldBe manuallyAddedTransactionComplement().accountId.plainUuid538 }539 localDatabase.shouldMatchServer(serverDatabase)540 localDatabase.shouldHaveAllTransactionsProcessed()541 }542 context("once the complement is also deleted") {543 transactionMirrorer.mirrorTransactions()544 setUpServerDatabase {545 addOrUpdateTransactionsForAccount(546 TO_ACCOUNT_ID,547 listOf(548 serverDatabase.getTransactionsForAccount(TO_ACCOUNT_ID)549 .find { it.id == manuallyAddedTransactionComplement().id.string }!!550 .copy(deleted = true)551 )552 )553 }554 test("both transactions are fully deleted") {555 transactionMirrorer.mirrorTransactions()556 deletedTransaction.complementOnServerShould(serverDatabase, TO_ACCOUNT_AND_BUDGET) {557 deleted.shouldBeTrue()558 }559 localDatabase.shouldMatchServer(serverDatabase)560 localDatabase.shouldHaveAllTransactionsProcessed()561 }562 }563 xcontext("once the complement is un-flagged (un-deleted)") {564 /* TODO: This causes problems because you can't recreate the transaction with the same565 * importId. Let's just ignore this for now, and come back to it later.566 *567 * Some ideas for then:568 * - Store the DELETED transaction in the local database even after deletion, update it569 * rather than creating a whole new transaction. Definitely the best option, but need570 * to double-check that it works with the API.571 * - Right now, we ignore any changes that aren't amount, date, and approved. Need to add572 * a "flag" UpdateField to cover un-deletion (and eventually flag-to-split).573 */574 transactionMirrorer.mirrorTransactions()575 val unflaggedTransaction = serverDatabase.getTransactionsForAccount(TO_ACCOUNT_ID)576 .find { it.id == manuallyAddedTransactionComplement().id.string }!!577 .copy(flagColor = null, approved = true)...

Full Screen

Full Screen

FunSpecContainerScope.kt

Source:FunSpecContainerScope.kt Github

copy

Full Screen

...40 }41 /**42 * Adds a disabled container test to this context.43 */44 suspend fun xcontext(name: String, test: suspend FunSpecContainerScope.() -> Unit) {45 registerContainer(TestName(name), true, null) { FunSpecContainerScope(this).test() }46 }47 /**48 * Adds a disabled container to this context, expecting config.49 */50 @ExperimentalKotest51 fun xcontext(name: String): ContainerWithConfigBuilder<FunSpecContainerScope> {52 return ContainerWithConfigBuilder(53 TestName(name),54 this,55 true56 ) { FunSpecContainerScope(it) }57 }58 /**59 * Adds a test case to this context, expecting config.60 */61 suspend fun test(name: String): TestWithConfigBuilder {62 TestDslState.startTest(testScope.testCase.descriptor.append(name))63 return TestWithConfigBuilder(64 name = TestName(name),65 context = this,...

Full Screen

Full Screen

FunSpecRootScope.kt

Source:FunSpecRootScope.kt Github

copy

Full Screen

...17 }18 /**19 * Adds a disabled container [RootTest] that uses a [FunSpecContainerScope] as the test context.20 */21 fun xcontext(name: String, test: suspend FunSpecContainerScope.() -> Unit) =22 addContainer(TestName("context ", name, false), true, null) { FunSpecContainerScope(this).test() }23 @ExperimentalKotest24 fun context(name: String): RootContainerWithConfigBuilder<FunSpecContainerScope> =25 RootContainerWithConfigBuilder(TestName("context ", name, false), false, this) { FunSpecContainerScope(it) }26 @ExperimentalKotest27 fun xcontext(name: String): RootContainerWithConfigBuilder<FunSpecContainerScope> =28 RootContainerWithConfigBuilder(TestName("context ", name, false), true, this) { FunSpecContainerScope(it) }29 /**30 * Adds a [RootTest], with the given name and config taken from the config builder.31 */32 fun test(name: String): RootTestWithConfigBuilder =33 RootTestWithConfigBuilder(this, TestName(name), xdisabled = false)34 /**35 * Adds a [RootTest], with the given name and default config.36 */37 fun test(name: String, test: suspend TestScope.() -> Unit) = addTest(TestName(name), false, null, test)38 /**39 * Adds a disabled [RootTest], with the given name and default config.40 */41 fun xtest(name: String, test: suspend TestScope.() -> Unit) = addTest(TestName(name), true, null, test)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in FunSpecContainerScope

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful