From a32aae2b2867c9e5815533622333e9ecfd60d0d3 Mon Sep 17 00:00:00 2001 From: Alexandr Jeliuc Date: Wed, 22 Jan 2025 15:50:48 +0200 Subject: [PATCH] Tests and fixes --- .../kotlin/OrganizationsIntegrationTest.kt | 18 +-- src/main/kotlin/model/Organization.kt | 14 ++- src/main/kotlin/resource/Organizations.kt | 6 +- src/test/kotlin/resource/OrganizationsTest.kt | 4 +- .../fixtures/organization/plans.json | 104 +++++++++++++++--- 5 files changed, 119 insertions(+), 27 deletions(-) diff --git a/src/integrationTest/kotlin/OrganizationsIntegrationTest.kt b/src/integrationTest/kotlin/OrganizationsIntegrationTest.kt index 94af112..b7bf9a9 100644 --- a/src/integrationTest/kotlin/OrganizationsIntegrationTest.kt +++ b/src/integrationTest/kotlin/OrganizationsIntegrationTest.kt @@ -10,6 +10,8 @@ import com.jeliuc.turso.sdk.model.ListAuditLogsResponse import com.jeliuc.turso.sdk.model.ListInvitesResponse import com.jeliuc.turso.sdk.model.ListMembersResponse import com.jeliuc.turso.sdk.model.Organization +import com.jeliuc.turso.sdk.model.OrganizationDatabaseUsageResponse +import com.jeliuc.turso.sdk.model.OrganizationPlansResponse import com.jeliuc.turso.sdk.model.OrganizationResponse import com.jeliuc.turso.sdk.model.SubscriptionResponse import com.jeliuc.turso.sdk.resource.organizations @@ -60,9 +62,10 @@ class OrganizationsIntegrationTest { @Test fun `can get organization usage`() { - val usage = runBlocking { - getClient().organizations.usage() - } + val usage = + runBlocking { + getClient().organizations.usage(organization) + } assertIs(usage) } @@ -79,11 +82,12 @@ class OrganizationsIntegrationTest { @Test fun `can list plans`() { - val plans = runBlocking { - getClient().organizations.plans(organization) - } + val plans = + runBlocking { + getClient().organizations.plans(organization) + } - assertIs>(plans) + assertIs(plans) } @Test diff --git a/src/main/kotlin/model/Organization.kt b/src/main/kotlin/model/Organization.kt index e8cf170..2be600b 100644 --- a/src/main/kotlin/model/Organization.kt +++ b/src/main/kotlin/model/Organization.kt @@ -43,22 +43,34 @@ data class UpdateOrganizationRequest( @SerialName("overages") val overages: Boolean, ) +@Serializable +data class OrganizationPlansResponse( + @SerialName("plans") val plans: List, +) + @Serializable data class OrganizationPlan( @SerialName("name") val name: String, @SerialName("price") val price: String, + @SerialName("prices") val prices: List, @SerialName("quotas") val quotas: PlanQuotas, ) +@Serializable +data class PlanPrices( + @SerialName("value") val value: String, + @SerialName("timeline") val timeline: String, +) + @Serializable data class PlanQuotas( @SerialName("rowsRead") val rowRead: Long, @SerialName("rowsWritten") val rowsWritten: Long, - @SerialName("databases") val databases: Int, @SerialName("locations") val locations: Int, @SerialName("storage") val storage: Long, @SerialName("groups") val groups: Int, @SerialName("bytesSynced") val bytesSynced: Long, + @SerialName("databases") val databases: Int? = null, ) @Serializable diff --git a/src/main/kotlin/resource/Organizations.kt b/src/main/kotlin/resource/Organizations.kt index 9af03a6..63175a8 100644 --- a/src/main/kotlin/resource/Organizations.kt +++ b/src/main/kotlin/resource/Organizations.kt @@ -17,7 +17,7 @@ import com.jeliuc.turso.sdk.model.ListMembersResponse import com.jeliuc.turso.sdk.model.MemberResponse import com.jeliuc.turso.sdk.model.Organization import com.jeliuc.turso.sdk.model.OrganizationDatabaseUsageResponse -import com.jeliuc.turso.sdk.model.OrganizationPlan +import com.jeliuc.turso.sdk.model.OrganizationPlansResponse import com.jeliuc.turso.sdk.model.OrganizationResponse import com.jeliuc.turso.sdk.model.SubscriptionResponse import com.jeliuc.turso.sdk.model.UpdateMemberRequest @@ -103,13 +103,13 @@ class Organizations(val client: TursoClient) : ResponseHandler() { * * @see API Reference */ - suspend fun plans(organizationName: String): List = + suspend fun plans(organizationName: String): OrganizationPlansResponse = client.httpClient.get( Path.plans(organizationName), ) { contentType(ContentType.Application.Json) }.let { response -> - handleResponse>(response) + handleResponse(response) } /** diff --git a/src/test/kotlin/resource/OrganizationsTest.kt b/src/test/kotlin/resource/OrganizationsTest.kt index 0e20774..fb36b15 100644 --- a/src/test/kotlin/resource/OrganizationsTest.kt +++ b/src/test/kotlin/resource/OrganizationsTest.kt @@ -20,7 +20,7 @@ import com.jeliuc.turso.sdk.model.MemberResponse import com.jeliuc.turso.sdk.model.MemberRole import com.jeliuc.turso.sdk.model.Organization import com.jeliuc.turso.sdk.model.OrganizationDatabaseUsageResponse -import com.jeliuc.turso.sdk.model.OrganizationPlan +import com.jeliuc.turso.sdk.model.OrganizationPlansResponse import com.jeliuc.turso.sdk.model.OrganizationResponse import com.jeliuc.turso.sdk.model.SubscriptionResponse import com.jeliuc.turso.sdk.model.UpdateMemberRequest @@ -270,7 +270,7 @@ class OrganizationsTest { fun `can list available plans`() { runBlocking { client(mockEngine()).organizations.plans("test").let { response -> - assertIs>(response) + assertIs(response) } } } diff --git a/src/test/resources/fixtures/organization/plans.json b/src/test/resources/fixtures/organization/plans.json index 5c634a1..850d4aa 100644 --- a/src/test/resources/fixtures/organization/plans.json +++ b/src/test/resources/fixtures/organization/plans.json @@ -1,15 +1,91 @@ -[ - { - "name": "starter", - "price": "0", - "quotas": { - "rowsRead": 1000000000, - "rowsWritten": 25000000, - "databases": 500, - "locations": 3, - "storage": 9000000000, - "groups": 1, - "bytesSynced": 3000000000 +{ + "plans": [ + { + "name": "starter", + "price": "0", + "prices": [ + { + "value": "0", + "timeline": "monthly" + } + ], + "quotas": { + "rowsRead": 1000000000, + "rowsWritten": 25000000, + "databases": 500, + "locations": 3, + "storage": 9000000000, + "groups": 1, + "bytesSynced": 3000000000 + } + }, + { + "name": "hobby", + "price": "9", + "prices": [ + { + "value": "9", + "timeline": "monthly" + }, + { + "value": "99", + "timeline": "yearly" + } + ], + "quotas": { + "rowsRead": 1000000000, + "rowsWritten": 25000000, + "databases": 500, + "locations": 3, + "storage": 9000000000, + "groups": 1, + "bytesSynced": 3000000000 + } + }, + { + "name": "scaler", + "price": "29", + "prices": [ + { + "value": "29", + "timeline": "monthly" + }, + { + "value": "299", + "timeline": "yearly" + } + ], + "quotas": { + "rowsRead": 100000000000, + "rowsWritten": 100000000, + "databases": 10000, + "locations": 6, + "storage": 24000000000, + "groups": 6, + "bytesSynced": 12000000000 + } + }, + { + "name": "pro", + "price": "499", + "prices": [ + { + "value": "499", + "timeline": "monthly" + }, + { + "value": "4999", + "timeline": "yearly" + } + ], + "quotas": { + "rowsRead": 500000000000, + "rowsWritten": 250000000, + "locations": 10, + "storage": 50000000000, + "groups": 10, + "bytesSynced": 50000000000 + } } - } -] \ No newline at end of file + ] +}