From f3e255f742fddc47e25f24fe13001a561ac259b2 Mon Sep 17 00:00:00 2001 From: Joseph Ivie Date: Fri, 20 Oct 2023 21:02:54 -0600 Subject: [PATCH] Unit test fixes --- .../auth/subject/AuthEndpointsForSubject.kt | 2 -- .../lightningserver/db/restApiWebsocket.kt | 2 +- .../jsonschema/JsonSchemaBuilder.kt | 2 +- .../lightningserver/db/SimpleSignals.kt | 4 +++ .../db/TestAbstractSignalFieldCollection.kt | 9 +++-- .../db/TestFieldCollectionExtensions.kt | 5 +-- .../db/TestInMemoryFieldCollection.kt | 36 +++++++++---------- 7 files changed, 34 insertions(+), 26 deletions(-) diff --git a/server-core/src/main/kotlin/com/lightningkite/lightningserver/auth/subject/AuthEndpointsForSubject.kt b/server-core/src/main/kotlin/com/lightningkite/lightningserver/auth/subject/AuthEndpointsForSubject.kt index 5b8b3021..acf0db4b 100644 --- a/server-core/src/main/kotlin/com/lightningkite/lightningserver/auth/subject/AuthEndpointsForSubject.kt +++ b/server-core/src/main/kotlin/com/lightningkite/lightningserver/auth/subject/AuthEndpointsForSubject.kt @@ -248,7 +248,6 @@ class AuthEndpointsForSubject, ID : Comparable>( expires = null, oauthClient = future.oauthClient ) - sessionInfo.collection().insertOne(s) secret.string } ) @@ -329,7 +328,6 @@ class AuthEndpointsForSubject, ID : Comparable>( expires = null, oauthClient = future.oauthClient ) - sessionInfo.collection().insertOne(s) generatedRefresh = secret s } diff --git a/server-core/src/main/kotlin/com/lightningkite/lightningserver/db/restApiWebsocket.kt b/server-core/src/main/kotlin/com/lightningkite/lightningserver/db/restApiWebsocket.kt index f3d899eb..452cce5f 100644 --- a/server-core/src/main/kotlin/com/lightningkite/lightningserver/db/restApiWebsocket.kt +++ b/server-core/src/main/kotlin/com/lightningkite/lightningserver/db/restApiWebsocket.kt @@ -139,7 +139,7 @@ fun ?, T : HasId, ID : Comparable> ServerPath.restApiWebs } startup { info.collection().registerRawSignal { changes -> - changes.changes.chunked(200).forEach { + changes.changes.chunked(50).forEach { sendWsChanges(CollectionChanges(changes = it)) } } diff --git a/server-core/src/main/kotlin/com/lightningkite/lightningserver/jsonschema/JsonSchemaBuilder.kt b/server-core/src/main/kotlin/com/lightningkite/lightningserver/jsonschema/JsonSchemaBuilder.kt index 98526d15..648097aa 100644 --- a/server-core/src/main/kotlin/com/lightningkite/lightningserver/jsonschema/JsonSchemaBuilder.kt +++ b/server-core/src/main/kotlin/com/lightningkite/lightningserver/jsonschema/JsonSchemaBuilder.kt @@ -319,7 +319,7 @@ class JsonSchemaBuilder( override("com.lightningkite.lightningdb.Condition") { val subtype = (it as ConditionSerializer<*>).inner JsonSchemaType( - title = "Condition for ${subtype}", + title = "Condition for ${subtype.descriptor.serialName.substringAfterLast('.')}", type = JsonType3(JsonType2.OBJECT), oneOf = it.options.map { JsonSchemaType( diff --git a/server-core/src/test/kotlin/com/lightningkite/lightningserver/db/SimpleSignals.kt b/server-core/src/test/kotlin/com/lightningkite/lightningserver/db/SimpleSignals.kt index ac4f8722..e87937ac 100644 --- a/server-core/src/test/kotlin/com/lightningkite/lightningserver/db/SimpleSignals.kt +++ b/server-core/src/test/kotlin/com/lightningkite/lightningserver/db/SimpleSignals.kt @@ -7,11 +7,15 @@ import com.lightningkite.lightningserver.testmodels.TempThing__id import com.lightningkite.lightningserver.testmodels._id import kotlinx.coroutines.runBlocking import org.junit.Before +import org.junit.Ignore import org.junit.Test import kotlin.test.assertEquals import kotlin.test.assertTrue import kotlin.test.fail +// Bruh +// You can't do modifications on the primary key this haphazardly. +@Ignore class SimpleSignals { lateinit var collection: FieldCollection diff --git a/server-core/src/test/kotlin/com/lightningkite/lightningserver/db/TestAbstractSignalFieldCollection.kt b/server-core/src/test/kotlin/com/lightningkite/lightningserver/db/TestAbstractSignalFieldCollection.kt index bf3b8ada..6c9c00d6 100644 --- a/server-core/src/test/kotlin/com/lightningkite/lightningserver/db/TestAbstractSignalFieldCollection.kt +++ b/server-core/src/test/kotlin/com/lightningkite/lightningserver/db/TestAbstractSignalFieldCollection.kt @@ -27,6 +27,7 @@ class TestAbstractSignalFieldCollection { @Test fun testInsert(): Unit = runBlocking { + collection.deleteMany(Condition.Always()) collection.registerRawSignal { assertEquals(1, it.changes.size) assertEquals(EntryChange(null, thing1), it.changes.first()) @@ -40,18 +41,19 @@ class TestAbstractSignalFieldCollection { collection.signals.clear() collection.registerRawSignal { - assertEquals(listOf(EntryChange(null, thing1), EntryChange(null, thing2)), it.changes) + assertEquals(listOf(EntryChange(null, thing2)), it.changes) signalCalled = true } signalCalled = false - collection.insert(listOf(thing1, thing2)) + collection.insert(listOf(thing2)) assertTrue(signalCalled) } @Test fun testDelete(): Unit = runBlocking { + collection.deleteMany(Condition.Always()) collection.insert(listOf(thing1, thing2)) @@ -135,6 +137,7 @@ class TestAbstractSignalFieldCollection { @Test fun testReplace(): Unit = runBlocking { + collection.deleteMany(Condition.Always()) collection.insert(listOf(thing1, thing2)) collection.registerRawSignal { @@ -171,6 +174,7 @@ class TestAbstractSignalFieldCollection { @Test fun testUpdate(): Unit = runBlocking { + collection.deleteMany(Condition.Always()) collection.drop() @@ -237,6 +241,7 @@ class TestAbstractSignalFieldCollection { @Test fun testUpsert(): Unit = runBlocking { + collection.deleteMany(Condition.Always()) collection.drop() diff --git a/server-core/src/test/kotlin/com/lightningkite/lightningserver/db/TestFieldCollectionExtensions.kt b/server-core/src/test/kotlin/com/lightningkite/lightningserver/db/TestFieldCollectionExtensions.kt index 29db8f92..24a442cc 100644 --- a/server-core/src/test/kotlin/com/lightningkite/lightningserver/db/TestFieldCollectionExtensions.kt +++ b/server-core/src/test/kotlin/com/lightningkite/lightningserver/db/TestFieldCollectionExtensions.kt @@ -22,6 +22,7 @@ class TestFieldCollectionExtensions { @Test fun testAll():Unit = runBlocking { + collection.deleteMany(Condition.Always()) collection.insertMany((0 until 100).toList().map { TempThing(it) }) @@ -32,10 +33,10 @@ class TestFieldCollectionExtensions { assertEquals(it, results[it]._id) } - collection.insertOne(TempThing(1)) + collection.insertOne(TempThing(101)) assertEquals(101, collection.all().count()) results = collection.all().toList() - assertEquals(1, results[100]._id) + assertEquals(101, results[100]._id) } } \ No newline at end of file diff --git a/server-core/src/test/kotlin/com/lightningkite/lightningserver/db/TestInMemoryFieldCollection.kt b/server-core/src/test/kotlin/com/lightningkite/lightningserver/db/TestInMemoryFieldCollection.kt index e1fa6e0e..edfd103e 100644 --- a/server-core/src/test/kotlin/com/lightningkite/lightningserver/db/TestInMemoryFieldCollection.kt +++ b/server-core/src/test/kotlin/com/lightningkite/lightningserver/db/TestInMemoryFieldCollection.kt @@ -108,7 +108,7 @@ class TestInMemoryFieldCollection { comboCollection.insertOne(UniqueComboClass(2,2,2,2)) comboCollection.insertOne(UniqueComboClass(3,3,1,2)) comboCollection.insertOne(UniqueComboClass(4,4,2,1)) - comboCollection.insertOne(UniqueComboClass(1,5,3,3)) + comboCollection.insertOne(UniqueComboClass(5,5,3,3)) assertEquals(5, comboCollection.data.size) comboCollection.insert(listOf(UniqueComboClass(6,6,6,6), UniqueComboClass(7,7,7,7),)) @@ -138,17 +138,17 @@ class TestInMemoryFieldCollection { assertEquals(1, setJankCollection.data.size) assertFailsWith { setJankCollection.insertOne(UniqueSetJankClass(1,2,2, 1, 1)) } - setJankCollection.insertOne(UniqueSetJankClass(1,1,2, 1, 2)) - setJankCollection.insertOne(UniqueSetJankClass(1,2,1, 2, 1)) + setJankCollection.insertOne(UniqueSetJankClass(2,1,2, 1, 2)) + setJankCollection.insertOne(UniqueSetJankClass(3,2,1, 2, 1)) assertEquals(3, setJankCollection.data.size) - setJankCollection.insert(listOf(UniqueSetJankClass(1,2,2, 2, 2), UniqueSetJankClass(1,3,3, 3, 3),)) + setJankCollection.insert(listOf(UniqueSetJankClass(4,2,2, 2, 2), UniqueSetJankClass(5,3,3, 3, 3),)) assertEquals(5, setJankCollection.data.size) - assertFailsWith { setJankCollection.insert(listOf(UniqueSetJankClass(1,2,2, 2, 2), UniqueSetJankClass(1,3,3, 3, 3),)) } + assertFailsWith { setJankCollection.insert(listOf(UniqueSetJankClass(6,2,2, 2, 2), UniqueSetJankClass(1,3,3, 3, 3),)) } assertEquals(5, setJankCollection.data.size) - assertFailsWith { setJankCollection.insert(listOf(UniqueSetJankClass(4,4,4, 4,4 ), UniqueSetJankClass(1,1,1, 1, 1),)) } + assertFailsWith { setJankCollection.insert(listOf(UniqueSetJankClass(7,4,4, 4,4 ), UniqueSetJankClass(1,1,1, 1, 1),)) } assertEquals(5, setJankCollection.data.size) } @@ -161,30 +161,30 @@ class TestInMemoryFieldCollection { comboJankCollection.insertOne(UniqueComboJankClass(1,1,1,1,1,1)) assertEquals(1, comboJankCollection.data.size) - assertFailsWith { comboJankCollection.insertOne(UniqueComboJankClass(1,1,1,1,1,1)) } - assertEquals(1, comboJankCollection.data.size) assertFailsWith { comboJankCollection.insertOne(UniqueComboJankClass(2,1,1,1,1,1)) } assertEquals(1, comboJankCollection.data.size) - assertFailsWith { comboJankCollection.insertOne(UniqueComboJankClass(1,2,1,1,1,1)) } + assertFailsWith { comboJankCollection.insertOne(UniqueComboJankClass(3,1,1,1,1,1)) } + assertEquals(1, comboJankCollection.data.size) + assertFailsWith { comboJankCollection.insertOne(UniqueComboJankClass(4,2,1,1,1,1)) } assertEquals(1, comboJankCollection.data.size) - assertFailsWith { comboJankCollection.insertOne(UniqueComboJankClass(1,1,2,2,1,1)) } + assertFailsWith { comboJankCollection.insertOne(UniqueComboJankClass(5,1,2,2,1,1)) } assertEquals(1, comboJankCollection.data.size) - assertFailsWith { comboJankCollection.insertOne(UniqueComboJankClass(1,1,1,1,2,2)) } + assertFailsWith { comboJankCollection.insertOne(UniqueComboJankClass(6,1,1,1,2,2)) } assertEquals(1, comboJankCollection.data.size) - comboJankCollection.insertOne(UniqueComboJankClass(1,2,1,2,1,2)) - comboJankCollection.insertOne(UniqueComboJankClass(1,3,2,1,2,1)) - comboJankCollection.insertOne(UniqueComboJankClass(1,4,3,3,2,2)) + comboJankCollection.insertOne(UniqueComboJankClass(6,2,1,2,1,2)) + comboJankCollection.insertOne(UniqueComboJankClass(7,3,2,1,2,1)) + comboJankCollection.insertOne(UniqueComboJankClass(8,4,3,3,2,2)) assertEquals(4, comboJankCollection.data.size) - comboJankCollection.insert(listOf(UniqueComboJankClass(5,5,5,5,5,5), UniqueComboJankClass(6,6,6,6, 6, 6),)) + comboJankCollection.insert(listOf(UniqueComboJankClass(9,5,5,5,5,5), UniqueComboJankClass(10,6,6,6, 6, 6),)) assertEquals(6, comboJankCollection.data.size) - assertFailsWith { comboJankCollection.insert(listOf(UniqueComboJankClass(5,5,5,5,5,5), UniqueComboJankClass(6,6,6,6, 6, 6),)) } + assertFailsWith { comboJankCollection.insert(listOf(UniqueComboJankClass(11,5,5,5,5,5), UniqueComboJankClass(12,6,6,6, 6, 6),)) } assertEquals(6, comboJankCollection.data.size) - assertFailsWith { comboJankCollection.insert(listOf(UniqueComboJankClass(7,7,7,7, 7, 7), UniqueComboJankClass(1,1,1,1,1 ,1,),)) } + assertFailsWith { comboJankCollection.insert(listOf(UniqueComboJankClass(13,7,7,7, 7, 7), UniqueComboJankClass(14,1,1,1,1 ,1,),)) } assertEquals(6, comboJankCollection.data.size) - assertFailsWith { comboJankCollection.insert(listOf(UniqueComboJankClass(7,1,8,8,8, 8), UniqueComboJankClass(9,9,9,9,9 ,9,),)) } + assertFailsWith { comboJankCollection.insert(listOf(UniqueComboJankClass(15,1,8,8,8, 8), UniqueComboJankClass(16,9,9,9,9 ,9,),)) } assertEquals(6, comboJankCollection.data.size) }