-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Astra-Interactive/multiplatform
Multiplatform
- Loading branch information
Showing
81 changed files
with
1,949 additions
and
1,392 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -6,8 +6,7 @@ makeevrserg.java.ktarget=17 | |
# Project | ||
makeevrserg.project.name=AstraMarket | ||
makeevrserg.project.group=ru.astrainteractive.astramarket | ||
makeevrserg.project.version.string=1.7.0 | ||
makeevrserg.project.version.string=1.9.0 | ||
makeevrserg.project.description=Market plugin for EmpireSMP | ||
makeevrserg.project.developers=makeevrserg|Makeev Roman|[email protected] | ||
makeevrserg.project.url=https://empireprojekt.ru | ||
makeevrserg.publish.developers=makeevrserg|Makeev Roman|[email protected] |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
17 changes: 14 additions & 3 deletions
17
...ainteractive/astramarket/di/DataModule.kt → ...ainteractive/astramarket/di/DataModule.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import kotlinx.coroutines.runBlocking | ||
import ru.astrainteractive.astralibs.encoding.IO | ||
import ru.astrainteractive.astralibs.orm.DBConnection | ||
import ru.astrainteractive.astralibs.orm.DBSyntax | ||
import ru.astrainteractive.astramarket.api.market.AuctionsAPI | ||
import ru.astrainteractive.astramarket.db.market.entity.AuctionTable | ||
import ru.astrainteractive.astramarket.di.DataModule | ||
import ru.astrainteractive.klibs.mikro.core.dispatchers.DefaultKotlinDispatchers | ||
import java.io.File | ||
import java.util.UUID | ||
import kotlin.random.Random | ||
import kotlin.test.AfterTest | ||
import kotlin.test.BeforeTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class AuctionsTests { | ||
private val moduleFactory = { | ||
DataModule.Default( | ||
dispatchers = DefaultKotlinDispatchers, | ||
dbSyntax = DBSyntax.SQLite, | ||
dbConnection = DBConnection.SQLite("db") | ||
) | ||
} | ||
private var module: DataModule? = null | ||
private val auctionsApi: AuctionsAPI | ||
get() = module?.auctionApi ?: error("Module is null") | ||
|
||
private val randomAuction: ru.astrainteractive.astramarket.api.market.dto.AuctionDTO | ||
get() = ru.astrainteractive.astramarket.api.market.dto.AuctionDTO( | ||
id = -1, | ||
discordId = UUID.randomUUID().toString(), | ||
minecraftUuid = UUID.randomUUID().toString(), | ||
time = System.currentTimeMillis(), | ||
item = IO.ByteArray(ByteArray(0)), | ||
price = Random.nextInt().toFloat(), | ||
expired = false | ||
) | ||
|
||
@BeforeTest | ||
fun setup(): Unit = runBlocking { | ||
val module = moduleFactory.invoke() | ||
module.database.openConnection() | ||
AuctionTable.create(module.database) | ||
this@AuctionsTests.module = module | ||
} | ||
|
||
@AfterTest | ||
fun destroy(): Unit = runBlocking { | ||
module?.database?.closeConnection() | ||
(module?.database?.dbConnection as? DBConnection.SQLite)?.let { | ||
File(it.dbName).delete() | ||
} | ||
module = null | ||
} | ||
|
||
@Test | ||
fun `Insert, fetch, expire same auction`(): Unit = runBlocking { | ||
val auction = randomAuction | ||
// Insert and fetch | ||
val id = auctionsApi.insertAuction(auction)!! | ||
var auctionDTO = auctionsApi.fetchAuction(id)!! | ||
assertEquals(auctionDTO.minecraftUuid, auction.minecraftUuid) | ||
// Get unexpiredAuctions | ||
var amount = auctionsApi.getUserAuctions(auctionDTO.minecraftUuid, false)!!.size | ||
assertEquals(amount, 1) | ||
// Expire | ||
auctionsApi.expireAuction(auctionDTO) | ||
assertEquals(auctionDTO.expired, false) | ||
auctionDTO = auctionsApi.fetchAuction(id)!! | ||
assertEquals(auctionDTO.expired, true) | ||
// Get expiredAuctions | ||
amount = auctionsApi.getUserAuctions(auctionDTO.minecraftUuid, true)!!.size | ||
assertEquals(amount, 1) | ||
// Get unexpiredAuctions | ||
amount = auctionsApi.getUserAuctions(auctionDTO.minecraftUuid, false)!!.size | ||
assertEquals(amount, 0) | ||
// Count auctions | ||
amount = auctionsApi.countPlayerAuctions(auctionDTO.minecraftUuid)!! | ||
assertEquals(amount, 1) | ||
// Delete and count auction | ||
auctionsApi.deleteAuction(auctionDTO) | ||
amount = auctionsApi.countPlayerAuctions(auctionDTO.minecraftUuid)!! | ||
assertEquals(amount, 0) | ||
val oldAuctionDTO = randomAuction.copy(time = 0) | ||
auctionsApi.insertAuction(oldAuctionDTO) | ||
amount = auctionsApi.getAuctionsOlderThan(System.currentTimeMillis() - 1)!!.size | ||
assertEquals(amount, 1) | ||
} | ||
} |
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,30 @@ | ||
// import ru.astrainteractive.gradleplugin.sourceset.JvmSourceSet.Companion.configureAstraSourceSet | ||
|
||
plugins { | ||
kotlin("jvm") | ||
kotlin("plugin.serialization") | ||
id("ru.astrainteractive.gradleplugin.minecraft.multiplatform") | ||
} | ||
|
||
minecraftMultiplatform { | ||
bukkit() | ||
} | ||
|
||
dependencies { | ||
// Kotlin | ||
implementation(libs.bundles.kotlin) | ||
// AstraLibs | ||
implementation(libs.minecraft.astralibs.ktxcore) | ||
implementation(libs.minecraft.astralibs.spigot.core) | ||
implementation(libs.minecraft.astralibs.spigot.gui) | ||
implementation(libs.minecraft.astralibs.orm) | ||
implementation(libs.klibs.kdi) | ||
implementation(libs.minecraft.bstats) | ||
// Test | ||
testImplementation(libs.bundles.testing.kotlin) | ||
testImplementation(libs.tests.kotlin.test) | ||
// Bukkit | ||
"bukkitMainCompileOnly"(libs.minecraft.paper.api) | ||
// Local | ||
implementation(projects.modules.data) | ||
} |
Oops, something went wrong.