@@ -391,6 +391,158 @@ class ContentProviderTest : InstrumentedTest() {
391391 }
392392 }
393393
394+ @Test
395+ fun testQueryCardReps () {
396+ val noteId = createdNotes.first().lastPathSegment!! .toLong()
397+ val note = col.getNote(noteId)
398+ val card = note.cards(col).single()
399+ val expectedReps = 7
400+
401+ card.update {
402+ reps = expectedReps
403+ }
404+
405+ val cursor =
406+ checkNotNull(
407+ contentResolver.query(
408+ FlashCardsContract .Card .CONTENT_URI ,
409+ arrayOf(FlashCardsContract .Card .REPS ),
410+ " cid:${card.id} " ,
411+ null ,
412+ null ,
413+ ),
414+ ) { " cursor from /cards" }
415+
416+ cursor.use {
417+ assertEquals(1 , it.count)
418+ assertTrue(it.moveToFirst())
419+ assertEquals(listOf (FlashCardsContract .Card .REPS ), it.columnNames.toList())
420+ assertEquals(expectedReps, it.getInt(it.getColumnIndex(FlashCardsContract .Card .REPS )))
421+ }
422+ }
423+
424+ @Test
425+ fun testQueryCardLapses () {
426+ val noteId = createdNotes.first().lastPathSegment!! .toLong()
427+ val noteUri = Uri .withAppendedPath(FlashCardsContract .Note .CONTENT_URI , noteId.toString())
428+ val noteCardsUri = Uri .withAppendedPath(noteUri, " cards" )
429+ val card = col.getNote(noteId).cards(col).single()
430+ val expectedLapses = 3
431+
432+ card.update {
433+ lapses = expectedLapses
434+ }
435+
436+ val cursor =
437+ checkNotNull(
438+ contentResolver.query(
439+ noteCardsUri,
440+ arrayOf(FlashCardsContract .Card .LAPSES ),
441+ null ,
442+ null ,
443+ null ,
444+ ),
445+ ) { " cursor from /notes/#/cards" }
446+
447+ cursor.use {
448+ assertEquals(1 , it.count)
449+ assertTrue(it.moveToFirst())
450+ assertEquals(listOf (FlashCardsContract .Card .LAPSES ), it.columnNames.toList())
451+ assertEquals(expectedLapses, it.getInt(it.getColumnIndex(FlashCardsContract .Card .LAPSES )))
452+ }
453+ }
454+
455+ @Test
456+ fun testQueryCardType () {
457+ val noteId = createdNotes.first().lastPathSegment!! .toLong()
458+ val card = col.getNote(noteId).cards(col).single()
459+ val expectedType = 2
460+ val cardUri =
461+ Uri .withAppendedPath(
462+ FlashCardsContract .Card .CONTENT_URI ,
463+ card.id.toString(),
464+ )
465+
466+ card.moveToReviewQueue()
467+
468+ val cursor =
469+ checkNotNull(
470+ contentResolver.query(
471+ cardUri,
472+ arrayOf(FlashCardsContract .Card .TYPE ),
473+ null ,
474+ null ,
475+ null ,
476+ ),
477+ ) { " cursor from /cards/#" }
478+
479+ cursor.use {
480+ assertEquals(1 , it.count)
481+ assertTrue(it.moveToFirst())
482+ assertEquals(listOf (FlashCardsContract .Card .TYPE ), it.columnNames.toList())
483+ assertEquals(expectedType, it.getInt(it.getColumnIndex(FlashCardsContract .Card .TYPE )))
484+ }
485+ }
486+
487+ @Test
488+ fun testQueryCardOriginalDeckId () {
489+ val noteId = createdNotes.first().lastPathSegment!! .toLong()
490+ val noteUri = Uri .withAppendedPath(FlashCardsContract .Note .CONTENT_URI , noteId.toString())
491+ val noteCardsUri = Uri .withAppendedPath(noteUri, " cards" )
492+ val card = col.getNote(noteId).cards(col).single()
493+ val expectedOriginalDeckId = testDeckIds[0 ]
494+ val noteCardUri = Uri .withAppendedPath(noteCardsUri, card.ord.toString())
495+
496+ card.update {
497+ oDid = expectedOriginalDeckId
498+ }
499+
500+ val cursor =
501+ checkNotNull(
502+ contentResolver.query(
503+ noteCardUri,
504+ arrayOf(FlashCardsContract .Card .ORIGINAL_DECK_ID ),
505+ null ,
506+ null ,
507+ null ,
508+ ),
509+ ) { " cursor from /notes/#/cards/#" }
510+
511+ cursor.use {
512+ assertEquals(1 , it.count)
513+ assertTrue(it.moveToFirst())
514+ assertEquals(listOf (FlashCardsContract .Card .ORIGINAL_DECK_ID ), it.columnNames.toList())
515+ assertEquals(
516+ expectedOriginalDeckId,
517+ it.getLong(it.getColumnIndex(FlashCardsContract .Card .ORIGINAL_DECK_ID )),
518+ )
519+ }
520+ }
521+
522+ @Test
523+ fun testQueryCardDefaultProjectionOmitsRawProperties () {
524+ val noteId = createdNotes.first().lastPathSegment!! .toLong()
525+ val card = col.getNote(noteId).cards(col).single()
526+ val cardUri =
527+ Uri .withAppendedPath(
528+ FlashCardsContract .Card .CONTENT_URI ,
529+ card.id.toString(),
530+ )
531+
532+ val cursor =
533+ checkNotNull(contentResolver.query(cardUri, null , null , null , null )) {
534+ " cursor from default projection query"
535+ }
536+
537+ cursor.use {
538+ assertTrue(it.moveToFirst())
539+ assertEquals(- 1 , it.getColumnIndex(FlashCardsContract .Card .TYPE ))
540+ assertEquals(- 1 , it.getColumnIndex(FlashCardsContract .Card .REPS ))
541+ assertEquals(- 1 , it.getColumnIndex(FlashCardsContract .Card .LAPSES ))
542+ assertEquals(- 1 , it.getColumnIndex(FlashCardsContract .Card .ORIGINAL_DECK_ID ))
543+ }
544+ }
545+
394546 @Test
395547 fun testQueryCardsRoot_returnsCards () {
396548 val cursor =
0 commit comments