Skip to content

Commit

Permalink
Merge pull request #422 from algolia/fix/indices-optional-params
Browse files Browse the repository at this point in the history
fix(search): make some props optional when listing indices
  • Loading branch information
Fluf22 authored Aug 6, 2024
2 parents 448dc28 + cc46cdf commit df91ba3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,30 @@ public data class ResponseListIndices(
/**
* Last build time in seconds.
*/
@SerialName(Key.LastBuildTimeS) val lastBuildTimeS: Int,
@SerialName(Key.LastBuildTimeS) val lastBuildTimeSOrNull: Int? = null,
/**
* Number of pending indexing operations.
*/
@SerialName(Key.NumberOfPendingTasks) val numberOfPendingTasks: Int,
@SerialName(Key.NumberOfPendingTasks) val numberOfPendingTasksOrNull: Int? = null,
/**
* A boolean which says whether the index has pending tasks.
*/
@SerialName(Key.PendingTask) val pendingTask: Boolean,
@SerialName(Key.PendingTask) val pendingTaskOrNull: Boolean? = null,
@SerialName(Key.Replicas) val replicasOrNull: List<IndexName>? = null,
@SerialName(Key.Primary) val primaryOrNull: IndexName? = null,
@SerialName(Key.SourceABTest) val sourceABTestOrNull: IndexName? = null,
@SerialName(Key.ABTest) val abTestOrNull: ResponseABTestShort? = null
) {

public val lastBuildTimeS: Int
get() = lastBuildTimeSOrNull!!

public val numberOfPendingTasks: Int
get() = numberOfPendingTasksOrNull!!

public val pendingTask: Boolean
get() = pendingTaskOrNull!!

public val replicas: List<IndexName>
get() = replicasOrNull!!

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package model.response

import com.algolia.search.model.ClientDate
import com.algolia.search.model.IndexName
import com.algolia.search.model.response.ResponseListIndices
import com.algolia.search.serialize.internal.Key
import shouldEqual
import kotlin.test.Test
import kotlinx.serialization.json.*

internal class TestResponseListIndices {

@Test
fun dx() {
val json = buildJsonObject {
put(Key.Name, "indexName")
put(Key.CreatedAt, "2024-07-26T13:20:00Z")
put(Key.UpdatedAt, "2024-08-05T15:17:04Z")
put(Key.Entries, 0)
put(Key.DataSize, 0)
put(Key.FileSize, 0)
put(Key.NumberOfPendingTasks, 0)
put(Key.Replicas,
buildJsonArray { add("replicas") }
)
put(Key.Primary, "primary")
put(Key.SourceABTest, "sourceABTest")
}
val item = ResponseListIndices.Item(
indexName = IndexName("indexName"),
createdAt = ClientDate(1722000000000),
updatedAt = ClientDate(1722871024000),
entries = 0,
dataSize = 0,
fileSize = 0,
numberOfPendingTasksOrNull = 0,
replicasOrNull = listOf(IndexName("replicas")),
primaryOrNull = IndexName("primary"),
sourceABTestOrNull = IndexName("sourceABTest"),
abTestOrNull = null
)

Json.encodeToJsonElement(ResponseListIndices.Item.serializer(), item) shouldEqual json
}
}

0 comments on commit df91ba3

Please sign in to comment.