-
Notifications
You must be signed in to change notification settings - Fork 19
/
DocumentsSpec.scala
541 lines (497 loc) · 23.3 KB
/
DocumentsSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
/*
* Copyright 2015 IBM Corporation, Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ibm.couchdb.api
import com.ibm.couchdb.Res.DocOk
import com.ibm.couchdb._
import com.ibm.couchdb.spec.{CouchDbSpecification, SpecConfig}
import org.http4s.Status
import org.specs2.matcher.MatchResult
class DocumentsSpec extends CouchDbSpecification {
val db = "couchdb-scala-documents-spec"
val server = new Server(client)
val databases = new Databases(client)
val documents = new Documents(client, db, typeMapping)
private def clear() = recreateDb(databases, db)
clear()
"Documents API" >> {
"Create a document with an auto-generated UUID" >> {
awaitDocOk(documents.create(fixAlice))
}
"Create a document with a specified UUID" >> {
val uuid = awaitRight(server.mkUuid)
awaitDocOk(documents.create(fixAlice, uuid), uuid)
}
"Get a document by a UUID" >> {
val uuid = awaitRight(server.mkUuid)
awaitRight(documents.create(fixAlice, uuid))
awaitRight(documents.get[FixPerson](uuid)).doc mustEqual fixAlice
val aliceRes = awaitRight(documents.get[FixPerson](uuid))
aliceRes.doc.name mustEqual fixAlice.name
aliceRes.doc.age mustEqual fixAlice.age
aliceRes._id mustEqual uuid
aliceRes._rev must beRev
}
"Get a document by a non-existent UUID" >> {
val uuid = awaitRight(server.mkUuid)
awaitError(documents.get[FixPerson](uuid), "not_found")
awaitError(documents.get[FixPerson](""), "not_found")
}
"Create multiple documents in bulk" >> {
clear()
val res = awaitRight(documents.createMany(Seq(fixAlice, fixBob)))
res must haveLength(2)
checkDocOk(res.head)
checkDocOk(res(1))
}
"Create multiple documents in bulk with IDs" >> {
clear()
val docs = Map("1" -> fixAlice, "2" -> fixBob)
val res = awaitRight(documents.createMany(docs))
res must haveLength(docs.size)
res.foreach(checkDocOk)
res.map(_.id) mustEqual docs.keys.toList
val created = awaitRight(documents.getMany[FixPerson](docs.keys.toList))
created.getDocs.map(_.doc) mustEqual docs.values.toSeq
created.rows.map(_.id) mustEqual docs.keys.toSeq
}
"Get all documents" >> {
def verify(docs: CouchKeyVals[String, CouchDocRev], expected: Seq[Res.DocOk]):
MatchResult[Seq[String]] = {
docs.offset mustEqual 0
docs.total_rows must beEqualTo(expected.size)
docs.rows must haveLength(expected.size)
docs.rows.map(_.id) must containTheSameElementsAs(expected.map(_.id))
}
clear()
val created = Seq(
awaitRight(documents.create(fixAlice)), awaitRight(documents.create(fixAlice)))
val docs = awaitRight(documents.getMany.build.query)
val docsWithExcludeDocs = awaitRight(documents.getMany.excludeDocs.build.query)
verify(docs, created)
verify(docsWithExcludeDocs, created)
}
"Get multiple documents by IDs" >> {
def verify(
docs: CouchKeyVals[String, CouchDocRev], created: Seq[Res.DocOk],
expected: Seq[Res.DocOk]): MatchResult[Any] = {
docs.offset mustEqual 0
docs.total_rows must beEqualTo(created.size)
docs.rows must haveLength(expected.size)
docs.rows.map(_.id) mustEqual expected.map(_.id)
}
clear()
val created = Seq(fixAlice, fixCarl, fixBob).map(x => awaitRight(documents.create(x)))
val expected = created.take(2)
verify(
awaitRight(documents.getMany.withIds(expected.map(_.id)).build.query), created, expected)
verify(
awaitRight(
documents.getMany.disallowMissing.excludeDocs.withIds(expected.map(_.id)).build.query),
created, expected)
}
"Get multiple documents by IDs with some missing" >> {
def verify(
docs: CouchKeyValsIncludesMissing[String, CouchDocRev], missing: Seq[String],
existing: Seq[String]): MatchResult[Any] = {
docs.offset mustEqual 0
docs.rows must haveLength(missing.length + existing.length)
docs.rows.flatMap(_.toOption).map(_.id).toList mustEqual existing
docs.rows.flatMap(_.swap.toOption).map(_.key).toList mustEqual missing
}
clear()
val fixPersons = Seq(fixAlice, fixBob, fixCarl)
val createdPersons = fixPersons.map(person => awaitRight(documents.create(person)))
val missingIds = Seq("non-existent-id-1", "non-existent-id-2")
val existingIds = createdPersons.map(_.id)
verify(
awaitRight(documents.getMany.allowMissing.withIds(existingIds ++ missingIds).build.query),
missingIds, existingIds)
verify(
awaitRight(
documents.getMany.disallowMissing.allowMissing.
withIds(existingIds ++ missingIds).build.query), missingIds, existingIds)
}
"Get all documents and include the doc data" >> {
def verify(
docs: CouchDocs[String, CouchDocRev, FixPerson],
created: Seq[Res.DocOk], expected: Seq[FixPerson]): MatchResult[Any] = {
docs.offset mustEqual 0
docs.total_rows mustEqual created.size
docs.rows must haveLength(expected.size)
docs.rows.map(_.id) mustEqual created.map(_.id)
docs.rows.map(_.doc.doc) mustEqual expected
docs.getDocs.map(_.doc) mustEqual expected
docs.getDocsData mustEqual expected
}
clear()
val expected = Seq(fixAlice, fixBob)
val created = expected.map(x => awaitRight(documents.create(x)))
verify(awaitRight(documents.getMany.includeDocs[FixPerson].build.query), created, expected)
verify(
awaitRight(documents.getMany.excludeDocs.includeDocs[FixPerson].build.query), created,
expected)
}
"Get all documents by type" >> {
def verify(
docs: CouchKeyVals[(String, String), String], created: Seq[DocOk],
expected: Seq[FixXPerson]): MatchResult[Any] = {
docs.total_rows must beGreaterThanOrEqualTo(created.size)
docs.rows must haveLength(expected.size)
docs.rows.map(_.value) mustEqual created.map(_.id)
}
clear()
awaitRight(documents.createMany(Seq(fixAlice, fixBob)))
val expected = Seq(fixProfessorX, fixMagneto)
val createdXMenOnly = awaitRight(documents.createMany(expected))
verify(
awaitRight(
documents.getMany.byTypeUsingTemporaryView(
typeMapping.get(
classOf[FixXPerson]).get).build.query), createdXMenOnly, expected)
}
"Get all documents by type and include the doc data" >> {
def verify(
docs: CouchDocs[(String, String), String, FixXPerson],
created: Seq[DocOk], expected: Seq[FixXPerson]): MatchResult[Any] = {
docs.total_rows must beGreaterThanOrEqualTo(created.size)
docs.rows must haveLength(expected.size)
docs.rows.map(_.value) mustEqual created.map(_.id)
docs.rows.map(_.doc.doc) mustEqual expected
docs.getDocs.map(_.doc) mustEqual expected
docs.getDocsData mustEqual expected
}
clear()
awaitRight(documents.createMany(Seq(fixAlice, fixBob)))
val expected = Seq(fixProfessorX, fixMagneto)
val createdXMenOnly = awaitRight(documents.createMany(expected))
verify(
awaitRight(
documents.getMany.includeDocs[FixXPerson].byTypeUsingTemporaryView(
typeMapping.get(classOf[FixXPerson]).get).build.query), createdXMenOnly, expected)
}
"Get all documents by type given a permanent type filter view" >> {
def verify(
docs: CouchKeyVals[_, String], created: Seq[DocOk],
expected: Seq[FixXPerson]): MatchResult[Any] = {
docs.total_rows must beGreaterThan(created.size)
docs.rows must haveLength(expected.size)
docs.rows.map(_.value) mustEqual created.map(_.id)
}
clear()
val design = new Design(client, db)
awaitRight(design.create(fixDesign))
awaitRight(documents.createMany(Seq(fixAlice, fixBob)))
val expected = Seq(fixProfessorX, fixMagneto)
val created = awaitRight(documents.createMany(expected))
val docs = awaitRight(
documents.getMany.byType[String](
FixViews.typeFilter, fixDesign.name,
typeMapping.get(classOf[FixXPerson]).get).build.query)
verify(docs, created, expected)
val docsCustom = awaitRight(
documents.getMany.byType[(String, String, Int), String](
FixViews.typeFilterCustom,
fixDesign.name, typeMapping.get(classOf[FixXPerson]).get).build.query)
verify(docsCustom, created, expected)
}
"Get all documents by type and include the doc data, given a permanent type filter view" >> {
def verify(
docs: CouchDocs[_, String, FixXPerson], created: Seq[DocOk],
expected: Seq[FixXPerson]): MatchResult[Any] = {
docs.total_rows must beGreaterThan(created.size)
docs.rows must haveLength(expected.size)
docs.rows.map(_.value) mustEqual created.map(_.id)
docs.rows.map(_.doc.doc) mustEqual expected
docs.getDocs.map(_.doc) mustEqual expected
docs.getDocsData mustEqual expected
}
clear()
val design = new Design(client, db)
awaitRight(design.create(fixDesign))
awaitRight(documents.createMany(Seq(fixAlice, fixBob)))
val expected = Seq(fixProfessorX, fixMagneto)
val created = awaitRight(documents.createMany(expected))
val docs = awaitRight(
documents.getMany.includeDocs[FixXPerson].byType[String](
FixViews.typeFilter, fixDesign.name,
typeMapping.get(classOf[FixXPerson]).get).build.query)
verify(docs, created, expected)
val docsCustom = awaitRight(
documents.getMany.includeDocs[FixXPerson].byType[(String, String, Int), String](
FixViews
.typeFilterCustom, fixDesign.name, typeMapping.get(classOf[FixXPerson]).get)
.build.query)
verify(docsCustom, created, expected)
}
"Get multiple documents by IDs and include the doc data" >> {
def verify(
docs: CouchDocs[String, CouchDocRev, FixPerson], created: Seq[Res.DocOk],
expected: Seq[FixPerson]): MatchResult[Any] = {
docs.offset mustEqual 0
docs.total_rows must beGreaterThanOrEqualTo(3)
docs.rows must haveLength(expected.size)
docs.rows.map(_.id) mustEqual created.map(_.id)
docs.rows.map(_.doc.doc) mustEqual expected
docs.getDocs.map(_.doc) mustEqual expected
docs.getDocsData mustEqual expected
}
clear()
awaitRight(documents.create(fixBob))
val expected = Seq(fixAlice, fixCarl)
val created: Seq[Res.DocOk] = expected.map(x => awaitRight(documents.create(x)))
verify(awaitRight(documents.getMany[FixPerson](created.map(_.id))), created, expected)
verify(
awaitRight(documents.getMany.withIds(created.map(_.id)).includeDocs[FixPerson].build.query),
created, expected)
verify(
awaitRight(
documents.getMany.disallowMissing.withIds(created.map(_.id)).includeDocs[FixPerson].
build.query), created, expected)
}
"Get multiple documents by IDs with some missing and include the doc data" >> {
def verify(
docs: CouchDocsIncludesMissing[String, CouchDocRev, FixPerson],
missing: Seq[String], existing: Seq[String],
expected: Seq[FixPerson]): MatchResult[Any] = {
docs.offset mustEqual 0
docs.rows must haveLength(missing.length + existing.length)
docs.rows.flatMap(_.toOption).map(_.id).toList mustEqual existing
docs.rows.flatMap(_.toOption).map(_.doc.doc) mustEqual expected
docs.getDocs.flatMap(_.toOption).map(_.doc) mustEqual expected
docs.getDocsData mustEqual expected
docs.rows.flatMap(_.swap.toOption).map(_.key).toList mustEqual missing
}
clear()
val fixPersons = Seq(fixAlice, fixBob, fixCarl)
val createdPersons = fixPersons.map(person => awaitRight(documents.create(person)))
val missingIds = Seq("non-existent-id-1", "non-existent-id-2")
val existingIds = createdPersons.map(_.id)
val docs = awaitRight(
documents.getMany.includeDocs[FixPerson].allowMissing.withIds(existingIds ++ missingIds).
build.query)
verify(docs, missingIds, existingIds, fixPersons)
}
"Get a document containing unicode values" >> {
clear()
val created = awaitRight(documents.create[FixPerson](fixHaile))
awaitRight(documents.get[FixPerson](created.id)).doc mustEqual fixHaile
}
"Update a document" >> {
val created = awaitRight(documents.create(fixAlice))
val aliceRes = awaitRight(documents.get[FixPerson](created.id))
val docOk = awaitRight(documents.update((_docPersonAge modify (_ + 1)) (aliceRes)))
checkDocOk(docOk, aliceRes._id)
val aliceRes2 = awaitRight(documents.get[FixPerson](aliceRes._id))
aliceRes2._id mustEqual aliceRes._id
aliceRes2._rev mustEqual docOk.rev
aliceRes2.doc.name mustEqual fixAlice.name
aliceRes2.doc.age mustEqual fixAlice.age + 1
}
"Fail to update a document without ID" >> {
val created = awaitRight(documents.create(fixAlice))
val aliceRes = awaitRight(documents.get[FixPerson](created.id))
awaitError(documents.update(aliceRes.copy(_id = "")), "cannot_update")
}
"Fail to update a document with an outdated revision" >> {
val created = awaitRight(documents.create(fixAlice))
val aliceRes = awaitRight(documents.get[FixPerson](created.id))
await(documents.update((_docPersonAge set 26) (aliceRes)))
val error = awaitLeft(documents.update((_docPersonAge set 27) (aliceRes)))
error.status mustEqual Status.Conflict
error.error mustEqual "conflict"
}
"Delete a document" >> {
val created = awaitRight(documents.create(fixAlice))
val aliceRes = awaitRight(documents.get[FixPerson](created.id))
awaitDocOk(documents.delete(aliceRes), aliceRes._id)
awaitError(documents.get[FixPerson](aliceRes._id), "not_found")
}
"Attach a byte array to a document" >> {
val created = awaitRight(documents.create(fixAlice))
val aliceRes = awaitRight(documents.get[FixPerson](created.id))
awaitDocOk(documents.attach(aliceRes, fixAttachmentName, fixAttachmentData), aliceRes._id)
}
"Get a byte array attachment" >> {
val created = awaitRight(documents.create(fixAlice))
val aliceRes = awaitRight(documents.get[FixPerson](created.id))
awaitDocOk(documents.attach(aliceRes, fixAttachmentName, fixAttachmentData))
val url = s"http://${SpecConfig.couchDbHost}:${SpecConfig.couchDbPort}" +
s"/$db/${aliceRes._id}/$fixAttachmentName"
awaitRight(documents.getAttachmentUrl(aliceRes, fixAttachmentName)) mustEqual url
awaitRight(documents.getAttachment(aliceRes, fixAttachmentName)) mustEqual fixAttachmentData
}
"Get a document with attachment stubs" >> {
val created = awaitRight(documents.create(fixAlice))
val aliceRes = awaitRight(documents.get[FixPerson](created.id))
awaitDocOk(
documents.attach(aliceRes, fixAttachmentName, fixAttachmentData, fixAttachmentContentType),
aliceRes._id)
val doc = awaitRight(documents.get[FixPerson](aliceRes._id))
doc._id mustEqual aliceRes._id
doc.doc.name mustEqual aliceRes.doc.name
doc._attachments must haveLength(1)
doc._attachments must haveKey(fixAttachmentName)
val meta = doc._attachments(fixAttachmentName)
meta.content_type mustEqual fixAttachmentContentType
meta.length mustEqual fixAttachmentData.length
meta.stub mustEqual true
meta.digest must not be empty
}
"Get a document with attachments inline" >> {
val created = awaitRight(documents.create(fixAlice))
val aliceRes = awaitRight(documents.get[FixPerson](created.id))
awaitDocOk(
documents.attach(aliceRes, fixAttachmentName, fixAttachmentData, fixAttachmentContentType),
aliceRes._id)
val doc = awaitRight(documents.get.attachments().query[FixPerson](aliceRes._id))
doc._id mustEqual aliceRes._id
doc.doc.name mustEqual aliceRes.doc.name
doc._attachments must haveLength(1)
doc._attachments must haveKey(fixAttachmentName)
val attachment = doc._attachments(fixAttachmentName)
attachment.content_type mustEqual fixAttachmentContentType
attachment.length mustEqual -1
attachment.stub mustEqual false
attachment.digest must not be empty
attachment.toBytes mustEqual fixAttachmentData
}
"Create and get a document with attachments" >> {
val attachments = Map[String, CouchAttachment](
fixAttachmentName -> CouchAttachment.fromBytes(
fixAttachmentData, fixAttachmentContentType),
fixAttachment2Name -> CouchAttachment.fromBytes(
fixAttachment2Data, fixAttachment2ContentType))
val created = awaitRight(documents.create(fixAlice, attachments))
val doc = awaitRight(documents.get.attachments().query[FixPerson](created.id))
doc._id mustEqual created.id
doc._attachments must haveLength(2)
doc._attachments must haveKeys(fixAttachmentName, fixAttachment2Name)
val attachment = doc._attachments(fixAttachmentName)
attachment.content_type mustEqual fixAttachmentContentType
attachment.length mustEqual -1
attachment.stub mustEqual false
attachment.digest must not be empty
attachment.toBytes mustEqual fixAttachmentData
val attachment2 = doc._attachments(fixAttachment2Name)
attachment2.content_type mustEqual fixAttachment2ContentType.toString
attachment2.length mustEqual -1
attachment2.stub mustEqual false
attachment2.digest must not be empty
attachment2.toBytes mustEqual fixAttachment2Data
}
"Update a document with attachments" >> {
val created = awaitRight(documents.create(fixAlice))
val aliceRes = awaitRight(documents.get[FixPerson](created.id))
val aliceWithAttachments = aliceRes.copy(
_attachments = Map(
fixAttachmentName -> CouchAttachment.fromBytes(
fixAttachmentData, fixAttachmentContentType),
fixAttachment2Name -> CouchAttachment.fromBytes(
fixAttachment2Data, fixAttachment2ContentType)))
val docOk = awaitRight(documents.update(aliceWithAttachments))
checkDocOk(docOk, aliceRes._id)
val doc = awaitRight(documents.get.attachments().query[FixPerson](created.id))
doc._id mustEqual created.id
doc._attachments.keys must containTheSameElementsAs(
Seq(fixAttachmentName, fixAttachment2Name))
val attachment = doc._attachments(fixAttachmentName)
attachment.content_type mustEqual fixAttachmentContentType
attachment.length mustEqual -1
attachment.stub mustEqual false
attachment.digest must not be empty
attachment.toBytes mustEqual fixAttachmentData
val attachment2 = doc._attachments(fixAttachment2Name)
attachment2.content_type mustEqual fixAttachment2ContentType.toString
attachment2.length mustEqual -1
attachment2.stub mustEqual false
attachment2.digest must not be empty
attachment2.toBytes mustEqual fixAttachment2Data
}
"Delete an attachment to a document" >> {
clear()
val created = awaitRight(documents.create(fixAlice))
val aliceRes = awaitRight(documents.get[FixPerson](created.id))
val attachment = awaitRight(documents.attach(aliceRes, fixAttachmentName, fixAttachmentData))
val aliceWithAttachment = awaitRight(documents.get[FixPerson](created.id))
awaitDocOk(documents.deleteAttachment(aliceWithAttachment, fixAttachmentName), attachment.id)
awaitError(documents.getAttachment(aliceRes, fixAttachmentName), "not_found")
}
"Bulk update should" >> {
val fixes = Seq(fixAlice, fixBob, fixHaile)
def change(v: String): String = s"$v-updated"
def create(x: Seq[FixPerson]): Seq[CouchDoc[FixPerson]] = {
clear()
val newIds = awaitRight(documents.createMany(x)).map(_.id)
awaitRight(documents.getMany[FixPerson](newIds)).getDocs
}
def modify(orig: Seq[CouchDoc[FixPerson]]): Seq[CouchDoc[FixPerson]] =
orig.map(x => (_docPersonName modify change) (x))
def createAndModify: (Seq[FixPerson]) => Seq[CouchDoc[FixPerson]] = create _ andThen modify
"update all documents when valid Ids and Rev" >> {
val modified = createAndModify(fixes)
val updatedDocs = awaitRight(documents.updateMany(modified)).map(_.id)
updatedDocs.size mustEqual fixes.size
val updateDocs = awaitRight(documents.getMany[FixPerson](modified.map(_._id)))
updateDocs.getDocs.map(_.doc) mustEqual fixes.map(
x => FixPerson(change(x.name), age = x.age))
}
"fail if one or more elements is missing Id" >> {
val modified = createAndModify(fixes)
val withInvalidId = modified.updated(2, modified(2).copy(_id = ""))
awaitError(documents.updateMany(withInvalidId), "cannot_update")
awaitRight(documents.getMany[FixPerson](modified.map(_._id)))
.getDocs.map(_.doc) mustEqual fixes
}
"fail if one or more elements is missing Rev" >> {
val modified = createAndModify(fixes)
val withInvalidRev = modified.updated(1, modified(1).copy(_rev = ""))
awaitError(documents.updateMany(withInvalidRev), "cannot_update")
awaitRight(documents.getMany[FixPerson](modified.map(_._id)))
.getDocs.map(_.doc) mustEqual fixes
}
}
"Bulk delete should" >> {
val fixes = Seq(fixAlice, fixBob, fixHaile)
def create(x: Seq[FixPerson]): Seq[CouchDoc[FixPerson]] = {
clear()
val newIds = awaitRight(documents.createMany(x)).map(_.id)
awaitRight(documents.getMany[FixPerson](newIds)).getDocs
}
"delete all documents" >> {
val created = create(fixes)
val deleted = awaitRight(documents.deleteMany(created)).map(_.id)
deleted.size mustEqual fixes.size
val getDeleted = awaitRight(documents.getMany[FixPerson](created.map(_._id)))
getDeleted.getDocs.size mustEqual fixes.size
getDeleted.getDocs.count(Option(_).isDefined) mustEqual 0
}
"fail if one or more elements is missing an Id" >> {
val created = create(fixes)
val withInvalidId = created.updated(1, created(1).copy(_id = ""))
awaitError(documents.deleteMany(withInvalidId), "cannot_update")
awaitRight(documents.getMany[FixPerson](created.map(_._id)))
.getDocs.map(_.doc) mustEqual fixes
}
"fail if one or more elements is missing a Rev" >> {
val created = create(fixes)
val withInvalidRev = created.updated(2, created(2).copy(_id = ""))
awaitError(documents.deleteMany(withInvalidRev), "cannot_update")
awaitRight(documents.getMany[FixPerson](created.map(_._id)))
.getDocs.map(_.doc) mustEqual fixes
}
}
}
}