Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indices integration testing #43

Merged
merged 1 commit into from
Dec 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/scala/algolia/AlgoliaClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class AlgoliaClient(applicationId: String, apiKey: String) {

def search(query: SearchDefinition)(implicit executor: ExecutionContext): Future[Search] = request[Search](query.build())

def indexes()(implicit executor: ExecutionContext): Future[Indexes] = execute {
def indices()(implicit executor: ExecutionContext): Future[Indexes] = execute {
AlgoliaDsl.indexes
}

Expand Down
132 changes: 132 additions & 0 deletions src/test/scala/algolia/integration/IndicesIntegrationTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright (c) 2015 Algolia
* http://www.algolia.com/
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package algolia.integration

import algolia.AlgoliaDsl._
import algolia.responses._
import algolia.{AlgoliaClient, AlgoliaTest}

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

class IndicesIntegrationTest extends AlgoliaTest {

val client = new AlgoliaClient(applicationId, apiKey)

final case class Obj(name: String)

it("should create indices") {
val create: Future[TaskIndexing] = client.execute {
index into "index1" document Obj("1")
}

whenReady(create) { result =>
result.taskID should not be 0
}
}

it("should list indices") {
val create: Future[TasksMultipleIndex] = client.execute {
batch(
index into "index1" document Obj("1"),
index into "index2" document Obj("1")
)
}

whenReady(create) { result =>
result.taskID should have size 2
}

//TODO remove when waitFor is implemented
Thread.sleep(2000)

val list: Future[Indexes] = client.indices()
whenReady(list) { result =>
result.items.map(_.name) should (contain("index1") and contain("index2"))
}
}

it("should delete an index") {
val create: Future[TaskIndexing] = client.execute {
index into "indexToDelete" document Obj("1")
}

whenReady(create) { result =>
result.taskID should not be 0
}

//TODO remove when waitFor is implemented
Thread.sleep(2000)

val del = client.execute {
delete index "indexToDelete"
}

whenReady(del) { result =>
result.taskID should not be 0
}

//TODO remove when waitFor is implemented
Thread.sleep(2000)

val list: Future[Indexes] = client.indices()
whenReady(list) { result =>
result.items.map(_.name) should not contain "indexToDelete"
}
}

it("should clear index") {
val create: Future[TaskIndexing] = client.execute {
index into "indexToClear" document Obj("1")
}

whenReady(create) { result =>
result.taskID should not be 0
}

//TODO remove when waitFor is implemented
Thread.sleep(2000)

val del = client.execute {
clear index "indexToClear"
}

whenReady(del) { result =>
result.taskID should not be 0
}

//TODO remove when waitFor is implemented
Thread.sleep(2000)

val list: Future[Search] = client.execute {
search into "indexToClear" query ""
}

whenReady(list) { result =>
result.hits should have size 0
}
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
* THE SOFTWARE.
*/

package algolia
package algolia.integration

import algolia.AlgoliaDsl._
import algolia.responses._
import algolia.{AlgoliaClient, AlgoliaTest}
import org.json4s._

import scala.concurrent.ExecutionContext.Implicits.global
Expand All @@ -34,16 +35,6 @@ class IntegrationTest extends AlgoliaTest {

val client = new AlgoliaClient(applicationId, apiKey)

it("should list indexes") {
val indices: Future[Indexes] = client.indexes()

whenReady(indices) { result =>
result.nbPages should equal(1)
result.items should have size 2
result.items.map(_.name) should be(Seq("test", "toto"))
}
}

final case class Test(name: String,
age: Int,
alien: Boolean)
Expand Down