Skip to content

Commit

Permalink
Tests and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
a2xchip committed Jan 22, 2025
1 parent b457a52 commit a32aae2
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 27 deletions.
18 changes: 11 additions & 7 deletions src/integrationTest/kotlin/OrganizationsIntegrationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<OrganizationDatabaseUsageResponse>(usage)
}
Expand All @@ -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<List<OrganizationPlan>>(plans)
assertIs<OrganizationPlansResponse>(plans)
}

@Test
Expand Down
14 changes: 13 additions & 1 deletion src/main/kotlin/model/Organization.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,34 @@ data class UpdateOrganizationRequest(
@SerialName("overages") val overages: Boolean,
)

@Serializable
data class OrganizationPlansResponse(
@SerialName("plans") val plans: List<OrganizationPlan>,
)

@Serializable
data class OrganizationPlan(
@SerialName("name") val name: String,
@SerialName("price") val price: String,
@SerialName("prices") val prices: List<PlanPrices>,
@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
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/resource/Organizations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -103,13 +103,13 @@ class Organizations(val client: TursoClient) : ResponseHandler() {
*
* @see <a href="https://docs.turso.tech/api-reference/organizations/plans">API Reference</a>
*/
suspend fun plans(organizationName: String): List<OrganizationPlan> =
suspend fun plans(organizationName: String): OrganizationPlansResponse =
client.httpClient.get(
Path.plans(organizationName),
) {
contentType(ContentType.Application.Json)
}.let { response ->
handleResponse<List<OrganizationPlan>>(response)
handleResponse<OrganizationPlansResponse>(response)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/test/kotlin/resource/OrganizationsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -270,7 +270,7 @@ class OrganizationsTest {
fun `can list available plans`() {
runBlocking {
client(mockEngine()).organizations.plans("test").let { response ->
assertIs<List<OrganizationPlan>>(response)
assertIs<OrganizationPlansResponse>(response)
}
}
}
Expand Down
104 changes: 90 additions & 14 deletions src/test/resources/fixtures/organization/plans.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
]
]
}

0 comments on commit a32aae2

Please sign in to comment.