-
Notifications
You must be signed in to change notification settings - Fork 4
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 #36 from SettingDust/feature/loader-order
feat: prefer the loader by order in lock file
- Loading branch information
Showing
4 changed files
with
210 additions
and
4 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 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
118 changes: 118 additions & 0 deletions
118
src/commonTest/kotlin/teksturepako/pakku/api/platforms/CurseForgeTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,129 @@ | ||
package teksturepako.pakku.api.platforms | ||
|
||
import io.mockk.every | ||
import io.mockk.mockk | ||
import teksturepako.pakku.api.models.cf.CfModModel | ||
import teksturepako.pakku.api.platforms.CurseForge.LOADER_VERSION_TYPE_ID | ||
import teksturepako.pakku.api.platforms.CurseForge.sortByLoaders | ||
import kotlin.test.Test | ||
import kotlin.test.assertContentEquals | ||
import kotlin.test.assertEquals | ||
|
||
class CurseForgeTest | ||
{ | ||
@Test | ||
fun requestProject() | ||
{ | ||
} | ||
|
||
@Test | ||
fun sortByLoaders_WithValidLoaders_ShouldSortCorrectly() { | ||
val files = listOf( | ||
mockk<CfModModel.File> { | ||
every { sortableGameVersions } returns listOf( | ||
mockk<CfModModel.File.SortableGameVersion> { | ||
every { gameVersionTypeId } returns LOADER_VERSION_TYPE_ID | ||
every { gameVersionName } returns "loaderB" | ||
}, | ||
mockk<CfModModel.File.SortableGameVersion> { | ||
every { gameVersionTypeId } returns LOADER_VERSION_TYPE_ID | ||
every { gameVersionName } returns "loaderC" | ||
} | ||
) | ||
}, | ||
mockk<CfModModel.File> { | ||
every { sortableGameVersions } returns listOf( | ||
mockk<CfModModel.File.SortableGameVersion> { | ||
every { gameVersionTypeId } returns LOADER_VERSION_TYPE_ID | ||
every { gameVersionName } returns "loaderA" | ||
}, | ||
mockk<CfModModel.File.SortableGameVersion> { | ||
every { gameVersionTypeId } returns LOADER_VERSION_TYPE_ID | ||
every { gameVersionName } returns "loaderB" | ||
} | ||
) | ||
}, | ||
mockk<CfModModel.File> { | ||
every { sortableGameVersions } returns listOf( | ||
mockk<CfModModel.File.SortableGameVersion> { | ||
every { gameVersionTypeId } returns LOADER_VERSION_TYPE_ID | ||
every { gameVersionName } returns "loaderB" | ||
}, | ||
mockk<CfModModel.File.SortableGameVersion> { | ||
every { gameVersionTypeId } returns LOADER_VERSION_TYPE_ID | ||
every { gameVersionName } returns "loaderB" | ||
} | ||
) | ||
}, | ||
mockk<CfModModel.File> { | ||
every { sortableGameVersions } returns listOf( | ||
mockk<CfModModel.File.SortableGameVersion> { | ||
every { gameVersionTypeId } returns LOADER_VERSION_TYPE_ID | ||
every { gameVersionName } returns "loaderA" | ||
}, | ||
mockk<CfModModel.File.SortableGameVersion> { | ||
every { gameVersionTypeId } returns LOADER_VERSION_TYPE_ID | ||
every { gameVersionName } returns "loaderC" | ||
} | ||
) | ||
} | ||
) | ||
|
||
val loaders = listOf("loadera", "loaderb", "loaderc") | ||
val sortedFiles = files.toList().sortByLoaders(loaders) | ||
|
||
assertContentEquals(listOf(files[1], files[3], files[0], files[2]), sortedFiles) | ||
} | ||
|
||
@Test | ||
fun sortByLoaders_WithNoMatchingLoaders_ShouldNotChangeOrder() { | ||
val files = listOf( | ||
mockk<CfModModel.File> { | ||
every { sortableGameVersions } returns listOf( | ||
mockk<CfModModel.File.SortableGameVersion> { | ||
every { gameVersionTypeId } returns LOADER_VERSION_TYPE_ID | ||
every { gameVersionName } returns "loaderB" | ||
} | ||
) | ||
}, | ||
mockk<CfModModel.File> { | ||
every { sortableGameVersions } returns listOf( | ||
mockk<CfModModel.File.SortableGameVersion> { | ||
every { gameVersionTypeId } returns LOADER_VERSION_TYPE_ID | ||
every { gameVersionName } returns "loaderA" | ||
} | ||
) | ||
} | ||
) | ||
|
||
val loaders = listOf("loader1", "loader2") | ||
val sortedFiles = files.toList().sortByLoaders(loaders) | ||
assertContentEquals(files, sortedFiles) | ||
} | ||
|
||
@Test | ||
fun sortByLoaders_WithSomeMatchingLoaders_ShouldSortCorrectly() { | ||
val files = listOf( | ||
mockk<CfModModel.File> { | ||
every { sortableGameVersions } returns listOf( | ||
mockk<CfModModel.File.SortableGameVersion> { | ||
every { gameVersionTypeId } returns LOADER_VERSION_TYPE_ID | ||
every { gameVersionName } returns "loaderA" | ||
} | ||
) | ||
}, | ||
mockk<CfModModel.File> { | ||
every { sortableGameVersions } returns listOf( | ||
mockk<CfModModel.File.SortableGameVersion> { | ||
every { gameVersionTypeId } returns LOADER_VERSION_TYPE_ID | ||
every { gameVersionName } returns "loader1" | ||
} | ||
) | ||
} | ||
) | ||
|
||
val loaders = listOf("loader1", "loader2") | ||
val sortedFiles = files.toList().sortByLoaders(loaders) | ||
assertEquals(files[0], sortedFiles[1]) | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/commonTest/kotlin/teksturepako/pakku/api/platforms/ModrinthTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package teksturepako.pakku.api.platforms | ||
|
||
import io.mockk.every | ||
import io.mockk.mockk | ||
import teksturepako.pakku.api.models.mr.MrVersionModel | ||
import teksturepako.pakku.api.platforms.Modrinth.sortByLoaders | ||
import kotlin.test.Test | ||
import kotlin.test.assertContentEquals | ||
import kotlin.test.assertEquals | ||
|
||
class ModrinthTest | ||
{ | ||
@Test | ||
fun sortByLoaders_WithValidLoaders_ShouldSortCorrectly() { | ||
val versions = listOf( | ||
mockk<MrVersionModel> { | ||
every { loaders } returns listOf("loaderb", "loaderc") | ||
}, | ||
mockk<MrVersionModel> { | ||
every { loaders } returns listOf("loadera", "loaderb") | ||
}, | ||
mockk<MrVersionModel> { | ||
every { loaders } returns listOf("loaderb", "loaderb") | ||
}, | ||
mockk<MrVersionModel> { | ||
every { loaders } returns listOf("loadera", "loaderc") | ||
} | ||
) | ||
|
||
val loaders = listOf("loadera", "loaderb", "loaderc") | ||
val sortedVersions = versions.toList().sortByLoaders(loaders) | ||
|
||
assertContentEquals(listOf(versions[1], versions[3], versions[0], versions[2]), sortedVersions) | ||
} | ||
|
||
@Test | ||
fun sortByLoaders_WithNoMatchingLoaders_ShouldNotChangeOrder() { | ||
val versions = listOf( | ||
mockk<MrVersionModel> { | ||
every { loaders } returns listOf("loaderB") | ||
}, | ||
mockk<MrVersionModel> { | ||
every { loaders } returns listOf("loaderA") | ||
} | ||
) | ||
|
||
val loaders = listOf("loader1", "loader2") | ||
val sortedVersions = versions.toList().sortByLoaders(loaders) | ||
|
||
assertContentEquals(versions, sortedVersions) | ||
} | ||
|
||
@Test | ||
fun sortByLoaders_WithSomeMatchingLoaders_ShouldSortCorrectly() { | ||
val versions = listOf( | ||
mockk<MrVersionModel> { | ||
every { loaders } returns listOf("loadera") | ||
}, | ||
mockk<MrVersionModel> { | ||
every { loaders } returns listOf("loader1") | ||
} | ||
) | ||
|
||
val loaders = listOf("loader1", "loader2") | ||
val sortedVersions = versions.toList().sortByLoaders(loaders) | ||
|
||
assertEquals(versions[0], sortedVersions[1]) | ||
} | ||
} |