Skip to content

Commit

Permalink
added: support new customSearchParameters field in ABTest variants fo…
Browse files Browse the repository at this point in the history
…r AA testing
  • Loading branch information
aseure committed Feb 14, 2019
1 parent b465cb1 commit ad6628b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/main/scala/algolia/inputs/ABTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ package algolia.inputs

import java.time.LocalDateTime

import algolia.objects.Query

case class ABTest(name: String, variants: Seq[ABTestVariant], endAt: LocalDateTime)

case class ABTestVariant(index: String, trafficPercentage: Int, description: Option[String] = None)
case class ABTestVariant(index: String,
trafficPercentage: Int,
description: Option[String] = None,
customSearchParameters: Option[Query] = None)
5 changes: 4 additions & 1 deletion src/main/scala/algolia/responses/ABTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ package algolia.responses

import java.time.LocalDateTime

import algolia.objects.Query

case class ABTestsResponse(abtests: Seq[ABTestResponse], count: Int, total: Int)

case class ABTestResponse(abTestID: Int,
Expand All @@ -48,4 +50,5 @@ case class VariantResponse(averageClickPosition: Option[Int],
noResultCount: Option[Int],
searchCount: Option[Int],
trafficPercentage: Int,
userCount: Option[Int])
userCount: Option[Int],
customSearchParameters: Option[Query])
53 changes: 49 additions & 4 deletions src/test/scala/algolia/integration/ABTestIntegrationTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import algolia.AlgoliaDsl._
import algolia.AlgoliaTest
import algolia.inputs.{ABTest, ABTestVariant}
import algolia.`4XXAPIException`

import algolia.objects.{IgnorePlurals, Query}
import org.scalatest.RecoverMethods._

class ABTestIntegrationTest extends AlgoliaTest {
Expand Down Expand Up @@ -60,9 +60,21 @@ class ABTestIntegrationTest extends AlgoliaTest {
endAt = now.plus(10, ChronoUnit.DAYS)
)

def dummyAATest = ABTest(
name = s"aaTestName-$nowStr",
variants = Seq(
ABTestVariant(indexName1, 90),
ABTestVariant(indexName1,
10,
customSearchParameters =
Some(Query(ignorePlurals = Some(IgnorePlurals.`true`))))
),
endAt = now.plus(1, ChronoUnit.DAYS)
)

describe("AB testing") {

it("should send an API test") {
it("should send an AB test") {
val inputAbTest = dummyABTest

taskShouldBeCreatedAndWaitForIt(client.execute(add abTest inputAbTest), indexName1)
Expand Down Expand Up @@ -93,7 +105,40 @@ class ABTestIntegrationTest extends AlgoliaTest {
}
}

it("should stop an API test") {
it("should send an AA test") {
val inputAaTest = dummyAATest

taskShouldBeCreatedAndWaitForIt(client.execute(add abTest inputAaTest), indexName1)

val task = client.execute(get all abTests)

whenReady(task) { abTests =>
abTests.abtests should have size 1
abTests.abtests.map { abTest =>
{
abTest.name should be(inputAaTest.name)
abTest.endAt should be(inputAaTest.endAt)

abTest.variants.size should be(inputAaTest.variants.size)
abTest.variants.forall { variant =>
val isVariantFound =
inputAaTest.variants
.map { expectedVariant =>
expectedVariant.index == variant.index &&
expectedVariant.trafficPercentage == variant.trafficPercentage &&
expectedVariant.customSearchParameters == variant.customSearchParameters
}
.reduce((a, b) => a || b)

isVariantFound
}
}
}
}

}

it("should stop an AB test") {
val inputAbTest = dummyABTest

val addTask = client.execute(add abTest inputAbTest)
Expand All @@ -112,7 +157,7 @@ class ABTestIntegrationTest extends AlgoliaTest {
}
}

it("should delete an API test") {
it("should delete an AB test") {
val inputAbTest = dummyABTest

val addTask = client.execute(add abTest inputAbTest)
Expand Down

0 comments on commit ad6628b

Please sign in to comment.