Skip to content

Commit

Permalink
Add real Lunchmoney API tests. Version 1.0.0 #test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Marchuk authored and smaugfm committed Jul 4, 2023
1 parent d877d1e commit e6ca952
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: Push to DockerHub
name: Test against real Lunchmoney API
on: [ push ]
env:
DOCKER_USER: ${{secrets.DOCKER_USER}}
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
LUNCHMONEY_TEST_TOKEN: ${{secrets.LUNCHMONEY_TEST_TOKEN}}
jobs:
push-to-docker-hub:
test-against-lunchmoney-api:
runs-on: ubuntu-latest
if: ${{ contains(github.event.head_commit.message, '#test') }}
steps:
Expand All @@ -14,5 +13,5 @@ jobs:
distribution: temurin
java-version: 11
cache: gradle
- name: Code build
run: ./gradlew build --no-daemon -x test -x check
- name: Test against real Lunchmoney API
run: ./gradlew test --no-daemon
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repositories {
}

dependencies {
implementation("io.github.smaugfm:lunchmoney:0.0.2")
implementation("io.github.smaugfm:lunchmoney:1.0.0")
}
```

Expand Down
6 changes: 5 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
import org.jlleitschuh.gradle.ktlint.KtlintExtension
Expand All @@ -17,7 +18,7 @@ plugins {
}

group = "io.github.smaugfm"
version = "0.0.2"
version = "1.0.0"
val isReleaseVersion = !version.toString().endsWith("SNAPSHOT")

repositories {
Expand Down Expand Up @@ -66,6 +67,9 @@ detekt {

tasks {
test {
testLogging {
events = setOf(TestLogEvent.PASSED, TestLogEvent.FAILED, TestLogEvent.SKIPPED)
}
useJUnitPlatform()
}
withType<DetektCreateBaselineTask> {
Expand Down
4 changes: 2 additions & 2 deletions detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<SmellBaseline>
<ManuallySuppressedIssues>
<ID>LongParameterList:LunchmoneyApi.kt$LunchmoneyApi$( assetId: Long, typeName: LunchmoneyAssetType? = null, subtypeName: String? = null, name: String? = null, displayName: String? = null, balance: BigDecimal? = null, balanceAsOf: Instant? = null, currency: Currency? = null, institutionName: String? = null, closedOn: LocalDate? = null, excludeTransactions: Boolean? = null )</ID>
<ID>LongParameterList:LunchmoneyApi.kt$LunchmoneyApi$( categoryId: Long, name: String? = null, description: String? = null, isIncome: Boolean? = null, excludeFromBudget: Boolean? = null, excludeFromTotals: Boolean? = null, categoryIds: List&lt;Long>? = null, groupId: Long? = null )</ID>
<ID>LongParameterList:LunchmoneyApi.kt$LunchmoneyApi$( categoryId: Long, isIncome: Boolean, excludeFromBudget: Boolean, excludeFromTotals: Boolean, name: String? = null, description: String? = null, categoryIds: List&lt;Long>? = null, groupId: Long? = null )</ID>
<ID>LongParameterList:LunchmoneyApi.kt$LunchmoneyApi$( cryptoAssetId: Long, name: String? = null, displayName: String? = null, institutionName: String? = null, currency: String? = null, balance: BigDecimal? = null )</ID>
<ID>LongParameterList:LunchmoneyApi.kt$LunchmoneyApi$( date: LocalDate, payee: String, transactions: List&lt;Long>, categoryId: Long? = null, notes: String? = null, tags: List&lt;LunchmoneyTransactionTag>? = null )</ID>
<ID>LongParameterList:LunchmoneyApi.kt$LunchmoneyApi$( name: String, description: String? = null, isIncome: Boolean? = null, excludeFromBudget: Boolean? = null, excludeFromTotals: Boolean? = null, categoryIds: List&lt;Long>? = null, groupId: Long? = null )</ID>
<ID>LongParameterList:LunchmoneyApi.kt$LunchmoneyApi$( name: String, description: String? = null, isIncome: Boolean? = null, excludeFromBudget: Boolean? = null, excludeFromTotals: Boolean? = null, categoryIds: List&lt;Long>? = null, newCategories: List&lt;String>? = null )</ID>
<ID>LongParameterList:LunchmoneyApi.kt$LunchmoneyApi$( name: String, isIncome: Boolean, excludeFromBudget: Boolean, excludeFromTotals: Boolean, description: String? = null, categoryIds: List&lt;Long>? = null, groupId: Long? = null )</ID>
<ID>LongParameterList:LunchmoneyApi.kt$LunchmoneyApi$( name: String, typeName: LunchmoneyAssetType, balance: BigDecimal, subtypeName: String? = null, displayName: String? = null, balanceAsOf: Instant? = null, currency: Currency? = null, institutionName: String? = null, closedOn: LocalDate? = null, excludeTransactions: Boolean? = null )</ID>
<ID>LongParameterList:LunchmoneyApi.kt$LunchmoneyApi$( tagId: Long? = null, recurringId: Long? = null, plaidAccountId: Long? = null, categoryId: Long? = null, assetId: Long? = null, groupId: Long? = null, isGroup: Boolean? = null, status: LunchmoneyTransactionStatus? = null, offset: Long? = null, limit: Long? = null, startDate: LocalDate? = null, endDate: LocalDate? = null, debitAsNegative: Boolean? = null, pending: Boolean? = null )</ID>
<ID>LongParameterList:LunchmoneyApi.kt$LunchmoneyApi$( transactions: List&lt;LunchmoneyInsertTransaction>, applyRules: Boolean? = null, skipDuplicates: Boolean? = null, checkForRecurring: Boolean? = null, debitAsNegative: Boolean? = null, skipBalanceUpdate: Boolean? = null )</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ data class LunchmoneyBudget(
val categoryId: Long? = null,
val categoryGroupName: String? = null,
val groupId: Long? = null,
val isGroup: Boolean,
val isGroup: Boolean? = null,
val isIncome: Boolean,
val excludeFromBudget: Boolean,
val excludeFromTotals: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import java.util.Currency

@Serializable
data class LunchmoneyBudgetData(
val numTransactions: Long,
val spendingToBase: Double,
val numTransactions: Long? = null,
val spendingToBase: Double? = null,
val budgetToBase: Double? = null,
val budgetAmount: Double? = null,
val budgetCurrency: Currency? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import java.util.Currency
@Serializable
data class LunchmoneyRecurringExpense(
val id: Long,
val startDate: LocalDate,
val startDate: LocalDate? = null,
val endDate: LocalDate? = null,
val cadence: String,
val payee: String,
Expand Down
146 changes: 138 additions & 8 deletions src/test/kotlin/io/github/smaugfm/lunchmoney/JsonSchemaUpToDateTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@ package io.github.smaugfm.lunchmoney

import assertk.assertThat
import assertk.assertions.hasSize
import assertk.assertions.isBetween
import assertk.assertions.isEqualTo
import assertk.assertions.isGreaterThan
import assertk.assertions.isNull
import assertk.assertions.isTrue
import assertk.assertions.prop
import assertk.assertions.size
import io.github.smaugfm.lunchmoney.api.LunchmoneyApi
import io.github.smaugfm.lunchmoney.model.LunchmoneyCategorySingle
import io.github.smaugfm.lunchmoney.model.LunchmoneyInsertTransaction
import io.github.smaugfm.lunchmoney.model.LunchmoneyTransaction
import io.github.smaugfm.lunchmoney.model.LunchmoneyUpdateTransaction
import io.github.smaugfm.lunchmoney.model.LunchmoneyUser
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable
import reactor.tools.agent.ReactorDebugAgent
import java.math.BigDecimal
import java.time.LocalDate

@EnabledIfEnvironmentVariable(named = "LUNCHMONEY_TEST_TOKEN", matches = "\\w+")
class JsonSchemaUpToDateTest {
Expand Down Expand Up @@ -43,22 +52,40 @@ class JsonSchemaUpToDateTest {
fun getAllCategoriesTest() {
val categories = api.getAllCategories().block()!!
assertThat(categories)
.hasSize(11)
.size()
.isBetween(11, 12)
}

@Test
fun getSingleCategoryTest() {
val cat = api.getSingleCategory(489281).block()!!
assertThat(cat)
.prop(LunchmoneyCategorySingle::id)
.isEqualTo(489281)
fun crudCategoryTest() {
val catName = "test-category"
val catName2 = "test-category2"
val id = api.createCategory(catName, false, true, true).block()!!
try {
var cat = api.getSingleCategory(id).block()!!
assertThat(cat)
.prop(LunchmoneyCategorySingle::id)
.isEqualTo(id)
assertThat(cat)
.prop(LunchmoneyCategorySingle::name)
.isEqualTo(catName)

assertThat(api.updateCategory(id, true, false, false, catName2).block()!!).isTrue()
cat = api.getSingleCategory(id).block()!!
assertThat(cat)
.prop(LunchmoneyCategorySingle::name)
.isEqualTo(catName2)

} finally {
assertThat(api.forceDeleteCategory(id).block()!!).isTrue()
}
}

@Test
fun crudCategoryTest() {
fun crudCategoryGroupTest() {
val catName = "test-category"
val catName2 = "test-category2"
val id = api.createCategory(catName, false, true, true).block()!!
val id = api.createCategoryGroup(catName).block()!!
try {
var cat = api.getSingleCategory(id).block()!!
assertThat(cat)
Expand All @@ -78,4 +105,107 @@ class JsonSchemaUpToDateTest {
assertThat(api.forceDeleteCategory(id).block()!!).isTrue()
}
}

@Test
fun getAllTagsTest() {
val tags = api.getAllTags().block()!!
assertThat(tags)
.hasSize(5)
}

@Test
fun getAllTransactionsTest() {
val transactions = api.getAllTransactions().block()!!
assertThat(transactions)
.size()
.isGreaterThan(23)
}

@Test
fun crudTransactionTest() {
val ids = api.insertTransactions(
listOf(
LunchmoneyInsertTransaction(LocalDate.now(), BigDecimal.ONE)
)
).block()!!
assertThat(ids)
.hasSize(1)
val transaction = api.getSingleTransaction(ids[0]).block()!!
assertThat(transaction)
.prop(LunchmoneyTransaction::id)
.isEqualTo(ids[0])

assertThat(
api.updateTransaction(ids[0], LunchmoneyUpdateTransaction(LocalDate.now()))
.block()!!.updated
).isTrue()

}

@Test
fun crudTransactionGroupTest() {
val transactions = api.getAllTransactions().block()!!
.filter { it.recurringId == null && it.groupId == null && !it.isGroup }
.subList(0, 2)
val id = api.createTransactionGroup(
LocalDate.now(),
"vasa",
transactions.map { it.id }
).block()!!
try {
val transaction = api.getSingleTransaction(id).block()!!
assertThat(transaction)
.prop(LunchmoneyTransaction::id)
.isEqualTo(id)

} finally {
assertThat(api.deleteTransactionGroup(id).block()!!.toSet())
.isEqualTo(transactions.map { it.id }.toSet())
}
}

@Test
fun getRecurringExpensesTest() {
val from = LocalDate.of(2023, 6, 1)
val exp = api.getRecurringExpenses(from).block()!!
assertThat(exp)
.hasSize(6)
}

@Test
fun getBudgetTest() {
val from = LocalDate.of(2023, 6, 1)
val to = LocalDate.of(2023, 6, 30)
val budgets = api.getBudgetSummary(from, to).block()!!
assertThat(budgets)
.size()
.isBetween(11, 12)
}

@Test
fun budgetCrudTest() {
val catId = 489282L
val from = LocalDate.of(2023, 6, 1)
val amount = 123.123

assertThat(api.upsertBudget(from, catId, amount).block()).isNull()
assertThat(api.removeBudget(from, catId).block()!!).isTrue()
}

@Test
fun getAllAssetsTest() {
val assets = api.getAllAssets().block()!!
assertThat(assets)
.hasSize(4)
}

@Test
fun getAllPlaidAccounts() {
assertThat(api.getAllPlaidAccounts().block()!!).hasSize(0)
}

@Test
fun getAllCryptoAccounts() {
assertThat(api.getAllCrypto().block()!!).hasSize(0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import io.github.smaugfm.lunchmoney.TestMockServerBase
import io.github.smaugfm.lunchmoney.Util.getResourceAsString
import io.github.smaugfm.lunchmoney.exception.LunchmoneyApiResponseException
import io.github.smaugfm.lunchmoney.request.category.params.CreateCategoryGroupRequestParams
import io.github.smaugfm.lunchmoney.response.ApiErrorResponse
import io.github.smaugfm.lunchmoney.response.CreateCategoryResponse
import org.junit.jupiter.api.Test
import org.mockserver.model.HttpRequest.request
Expand Down Expand Up @@ -64,6 +63,6 @@ internal class CreateCategoryGroupRequestTest : TestMockServerBase() {
.isNotNull()
.isInstanceOf(LunchmoneyApiResponseException::class)
.prop(LunchmoneyApiResponseException::message)
.isEqualTo(listOf("A category with the same name (vasa) already exists."))
.isEqualTo("A category with the same name (vasa) already exists.")
}
}

0 comments on commit e6ca952

Please sign in to comment.