Skip to content

Commit

Permalink
Unit test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownJoe796 committed Oct 21, 2023
1 parent 2a09653 commit f3e255f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ class AuthEndpointsForSubject<SUBJECT : HasId<ID>, ID : Comparable<ID>>(
expires = null,
oauthClient = future.oauthClient
)
sessionInfo.collection().insertOne(s)
secret.string
}
)
Expand Down Expand Up @@ -329,7 +328,6 @@ class AuthEndpointsForSubject<SUBJECT : HasId<ID>, ID : Comparable<ID>>(
expires = null,
oauthClient = future.oauthClient
)
sessionInfo.collection().insertOne(s)
generatedRefresh = secret
s
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fun <USER: HasId<*>?, T : HasId<ID>, ID : Comparable<ID>> ServerPath.restApiWebs
}
startup {
info.collection().registerRawSignal { changes ->
changes.changes.chunked(200).forEach {
changes.changes.chunked(50).forEach {
sendWsChanges(CollectionChanges(changes = it))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TempThing>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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))
Expand Down Expand Up @@ -135,6 +137,7 @@ class TestAbstractSignalFieldCollection {

@Test
fun testReplace(): Unit = runBlocking {
collection.deleteMany(Condition.Always())

collection.insert(listOf(thing1, thing2))
collection.registerRawSignal {
Expand Down Expand Up @@ -171,6 +174,7 @@ class TestAbstractSignalFieldCollection {

@Test
fun testUpdate(): Unit = runBlocking {
collection.deleteMany(Condition.Always())


collection.drop()
Expand Down Expand Up @@ -237,6 +241,7 @@ class TestAbstractSignalFieldCollection {

@Test
fun testUpsert(): Unit = runBlocking {
collection.deleteMany(Condition.Always())


collection.drop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TestFieldCollectionExtensions {

@Test
fun testAll():Unit = runBlocking {
collection.deleteMany(Condition.Always())

collection.insertMany((0 until 100).toList().map { TempThing(it) })

Expand All @@ -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)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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),))
Expand Down Expand Up @@ -138,17 +138,17 @@ class TestInMemoryFieldCollection {
assertEquals(1, setJankCollection.data.size)
assertFailsWith<UniqueViolationException> { 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<UniqueViolationException> { setJankCollection.insert(listOf(UniqueSetJankClass(1,2,2, 2, 2), UniqueSetJankClass(1,3,3, 3, 3),)) }
assertFailsWith<UniqueViolationException> { setJankCollection.insert(listOf(UniqueSetJankClass(6,2,2, 2, 2), UniqueSetJankClass(1,3,3, 3, 3),)) }
assertEquals(5, setJankCollection.data.size)
assertFailsWith<UniqueViolationException> { setJankCollection.insert(listOf(UniqueSetJankClass(4,4,4, 4,4 ), UniqueSetJankClass(1,1,1, 1, 1),)) }
assertFailsWith<UniqueViolationException> { setJankCollection.insert(listOf(UniqueSetJankClass(7,4,4, 4,4 ), UniqueSetJankClass(1,1,1, 1, 1),)) }
assertEquals(5, setJankCollection.data.size)

}
Expand All @@ -161,30 +161,30 @@ class TestInMemoryFieldCollection {

comboJankCollection.insertOne(UniqueComboJankClass(1,1,1,1,1,1))
assertEquals(1, comboJankCollection.data.size)
assertFailsWith<UniqueViolationException> { comboJankCollection.insertOne(UniqueComboJankClass(1,1,1,1,1,1)) }
assertEquals(1, comboJankCollection.data.size)
assertFailsWith<UniqueViolationException> { comboJankCollection.insertOne(UniqueComboJankClass(2,1,1,1,1,1)) }
assertEquals(1, comboJankCollection.data.size)
assertFailsWith<UniqueViolationException> { comboJankCollection.insertOne(UniqueComboJankClass(1,2,1,1,1,1)) }
assertFailsWith<UniqueViolationException> { comboJankCollection.insertOne(UniqueComboJankClass(3,1,1,1,1,1)) }
assertEquals(1, comboJankCollection.data.size)
assertFailsWith<UniqueViolationException> { comboJankCollection.insertOne(UniqueComboJankClass(4,2,1,1,1,1)) }
assertEquals(1, comboJankCollection.data.size)
assertFailsWith<UniqueViolationException> { comboJankCollection.insertOne(UniqueComboJankClass(1,1,2,2,1,1)) }
assertFailsWith<UniqueViolationException> { comboJankCollection.insertOne(UniqueComboJankClass(5,1,2,2,1,1)) }
assertEquals(1, comboJankCollection.data.size)
assertFailsWith<UniqueViolationException> { comboJankCollection.insertOne(UniqueComboJankClass(1,1,1,1,2,2)) }
assertFailsWith<UniqueViolationException> { 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<UniqueViolationException> { comboJankCollection.insert(listOf(UniqueComboJankClass(5,5,5,5,5,5), UniqueComboJankClass(6,6,6,6, 6, 6),)) }
assertFailsWith<UniqueViolationException> { comboJankCollection.insert(listOf(UniqueComboJankClass(11,5,5,5,5,5), UniqueComboJankClass(12,6,6,6, 6, 6),)) }
assertEquals(6, comboJankCollection.data.size)
assertFailsWith<UniqueViolationException> { comboJankCollection.insert(listOf(UniqueComboJankClass(7,7,7,7, 7, 7), UniqueComboJankClass(1,1,1,1,1 ,1,),)) }
assertFailsWith<UniqueViolationException> { comboJankCollection.insert(listOf(UniqueComboJankClass(13,7,7,7, 7, 7), UniqueComboJankClass(14,1,1,1,1 ,1,),)) }
assertEquals(6, comboJankCollection.data.size)
assertFailsWith<UniqueViolationException> { comboJankCollection.insert(listOf(UniqueComboJankClass(7,1,8,8,8, 8), UniqueComboJankClass(9,9,9,9,9 ,9,),)) }
assertFailsWith<UniqueViolationException> { comboJankCollection.insert(listOf(UniqueComboJankClass(15,1,8,8,8, 8), UniqueComboJankClass(16,9,9,9,9 ,9,),)) }
assertEquals(6, comboJankCollection.data.size)

}
Expand Down

0 comments on commit f3e255f

Please sign in to comment.