package solutions.bitbadger.documents.integration.common import solutions.bitbadger.documents.* import solutions.bitbadger.documents.common.Field import solutions.bitbadger.documents.integration.JsonDocument import solutions.bitbadger.documents.integration.TEST_TABLE import solutions.bitbadger.documents.integration.ThrowawayDatabase import kotlin.test.assertEquals /** * Integration tests for the `Delete` object */ object Delete { fun byIdMatch(db: ThrowawayDatabase) { JsonDocument.load(db) assertEquals(5, db.conn.countAll(TEST_TABLE), "There should be 5 documents in the table") db.conn.deleteById(TEST_TABLE, "four") assertEquals(4, db.conn.countAll(TEST_TABLE), "There should now be 4 documents in the table") } fun byIdNoMatch(db: ThrowawayDatabase) { JsonDocument.load(db) assertEquals(5, db.conn.countAll(TEST_TABLE), "There should be 5 documents in the table") db.conn.deleteById(TEST_TABLE, "negative four") assertEquals(5, db.conn.countAll(TEST_TABLE), "There should still be 5 documents in the table") } fun byFieldsMatch(db: ThrowawayDatabase) { JsonDocument.load(db) assertEquals(5, db.conn.countAll(TEST_TABLE), "There should be 5 documents in the table") db.conn.deleteByFields(TEST_TABLE, listOf(Field.notEqual("value", "purple"))) assertEquals(2, db.conn.countAll(TEST_TABLE), "There should now be 2 documents in the table") } fun byFieldsNoMatch(db: ThrowawayDatabase) { JsonDocument.load(db) assertEquals(5, db.conn.countAll(TEST_TABLE), "There should be 5 documents in the table") db.conn.deleteByFields(TEST_TABLE, listOf(Field.equal("value", "crimson"))) assertEquals(5, db.conn.countAll(TEST_TABLE), "There should still be 5 documents in the table") } fun byContainsMatch(db: ThrowawayDatabase) { JsonDocument.load(db) assertEquals(5, db.conn.countAll(TEST_TABLE), "There should be 5 documents in the table") db.conn.deleteByContains(TEST_TABLE, mapOf("value" to "purple")) assertEquals(3, db.conn.countAll(TEST_TABLE), "There should now be 3 documents in the table") } fun byContainsNoMatch(db: ThrowawayDatabase) { JsonDocument.load(db) assertEquals(5, db.conn.countAll(TEST_TABLE), "There should be 5 documents in the table") db.conn.deleteByContains(TEST_TABLE, mapOf("target" to "acquired")) assertEquals(5, db.conn.countAll(TEST_TABLE), "There should still be 5 documents in the table") } fun byJsonPathMatch(db: ThrowawayDatabase) { JsonDocument.load(db) assertEquals(5, db.conn.countAll(TEST_TABLE), "There should be 5 documents in the table") db.conn.deleteByJsonPath(TEST_TABLE, "$.value ? (@ == \"purple\")") assertEquals(3, db.conn.countAll(TEST_TABLE), "There should now be 3 documents in the table") } fun byJsonPathNoMatch(db: ThrowawayDatabase) { JsonDocument.load(db) assertEquals(5, db.conn.countAll(TEST_TABLE), "There should be 5 documents in the table") db.conn.deleteByJsonPath(TEST_TABLE, "$.numValue ? (@ > 100)") assertEquals(5, db.conn.countAll(TEST_TABLE), "There should still be 5 documents in the table") } }