Skip to content

Commit

Permalink
Remove dataStore arg from check providers
Browse files Browse the repository at this point in the history
  • Loading branch information
antweb committed Oct 27, 2024
1 parent 7d75ed4 commit af1c2ed
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import java.time.Instant
import java.time.OffsetDateTime
import java.util.*

class AsyncCheckProvider(private val config: ConfigStore, private val dataStore: BlockingEntityStore<Persistable>, private val db: SyncDatabase) : TicketCheckProvider {
class AsyncCheckProvider(private val config: ConfigStore, private val db: SyncDatabase) : TicketCheckProvider {
private var sentry: SentryInterface = DummySentryImplementation()

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import java.util.*
class OnlineCheckProvider(
private val config: ConfigStore,
httpClientFactory: HttpClientFactory?,
private val dataStore: BlockingEntityStore<Persistable>,
private val db: SyncDatabase,
private val fileStore: FileStorage,
private val fallback: TicketCheckProvider? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {
fun setUpFakes() {
configStore = FakeConfigStore()
fakeApi = FakePretixApi()
p = AsyncCheckProvider(configStore!!, dataStore, db)
p = AsyncCheckProvider(configStore!!, db)

EventSyncAdapter(db, "demo", "demo", fakeApi!!, "", null).standaloneRefreshFromJSON(jsonResource("events/event1.json"))
EventSyncAdapter(db, "demo2", "demo2", fakeApi!!, "", null).standaloneRefreshFromJSON(jsonResource("events/event2.json"))
Expand Down Expand Up @@ -151,7 +151,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testSimpleValidUntil() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)

p2.setNow(ISODateTimeFormat.dateTime().parseDateTime("2023-03-04T00:00:01.000Z"))
var r = p2.check(mapOf("demo" to 1L), "dz4OBvVsTDSJ6T1nY1dD")
Expand All @@ -164,7 +164,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testSimpleValidFrom() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)

p2.setNow(ISODateTimeFormat.dateTime().parseDateTime("2023-03-03T23:59:59.000Z"))
var r = p2.check(mapOf("demo" to 1L), "uG3H4hgRYEIrw4YNclyH")
Expand Down Expand Up @@ -457,7 +457,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testRulesEntriesToday() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)

p2.setNow(ISODateTimeFormat.dateTime().parseDateTime("2020-01-01T10:00:00.000Z"))
setRuleOnList2("{\"<\": [{\"var\": \"entries_today\"}, 3]}")
Expand Down Expand Up @@ -491,7 +491,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testRulesEntriesDays() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)

// Ticket is valid unlimited times, but only on two arbitrary days
setRuleOnList2("{\"or\": [{\">\": [{\"var\": \"entries_today\"}, 0]}, {\"<\": [{\"var\": \"entries_days\"}, 2]}]}")
Expand Down Expand Up @@ -527,7 +527,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testRulesEntriesSince() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)

// Ticket is valid once before X and once after X
setRuleOnList2("{\n" +
Expand Down Expand Up @@ -559,7 +559,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testRulesEntriesSinceTimeOfDay() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)

// Ticket is valid once before X and once after X
setRuleOnList2("{\n" +
Expand Down Expand Up @@ -592,7 +592,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testRulesEntriesBefore() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)

// Ticket is valid after 23:00 only if people already showed up before
setRuleOnList2("{\n" +
Expand Down Expand Up @@ -623,7 +623,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testRulesEntriesDaysSince() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)

// Ticket is valid once before X and on one day after X
setRuleOnList2("{" +
Expand Down Expand Up @@ -663,7 +663,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testRulesEntriesDaysBefore() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)

// Ticket is valid after 23:00 only if people already showed up on two days before
setRuleOnList2("{" +
Expand Down Expand Up @@ -699,7 +699,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testRulesMinutesSinceLastEntry() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)
setRuleOnList2("{\"or\": [{\"<=\": [{\"var\": \"minutes_since_last_entry\"}, -1]}, {\">\": [{\"var\": \"minutes_since_last_entry\"}, 180]}]}")

p2.setNow(ISODateTimeFormat.dateTime().parseDateTime("2020-01-01T10:00:00.000Z"))
Expand All @@ -725,7 +725,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testRulesMinutesSinceFirstEntry() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)
setRuleOnList2("{\"or\": [{\"<=\": [{\"var\": \"minutes_since_first_entry\"}, -1]}, {\"<\": [{\"var\": \"minutes_since_first_entry\"}, 180]}]}")

p2.setNow(ISODateTimeFormat.dateTime().parseDateTime("2020-01-01T10:00:00.000Z"))
Expand All @@ -743,7 +743,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testRulesIsAfterTolerance() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)

// Ticket is valid unlimited times, but only on two arbitrary days
setRuleOnList2("{\"isAfter\": [{\"var\": \"now\"}, {\"buildTime\": [\"date_admission\"]}, 10]}")
Expand All @@ -763,7 +763,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testRulesIsAfterSubevent() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)

// Ticket is valid unlimited times, but only on two arbitrary days
setRuleOnList2("{\"isAfter\": [{\"var\": \"now\"}, {\"buildTime\": [\"date_admission\"]}, 10]}")
Expand All @@ -783,7 +783,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testRulesIsAfterNoTolerance() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)

// Ticket is valid unlimited times, but only on two arbitrary days
setRuleOnList2("{\"isAfter\": [{\"var\": \"now\"}, {\"buildTime\": [\"date_admission\"]}, null]}")
Expand All @@ -799,7 +799,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testRulesIsBeforeTolerance() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)

// Ticket is valid unlimited times, but only on two arbitrary days
setRuleOnList2("{\"isBefore\": [{\"var\": \"now\"}, {\"buildTime\": [\"date_to\"]}, 10]}")
Expand All @@ -815,7 +815,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testRulesIsBeforeNoTolerance() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)

// Ticket is valid unlimited times, but only on two arbitrary days
setRuleOnList2("{\"isBefore\": [{\"var\": \"now\"}, {\"buildTime\": [\"date_to\"]}]}")
Expand All @@ -831,7 +831,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testRulesIsAfterCustomDateTime() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)

// Ticket is valid unlimited times, but only on two arbitrary days
setRuleOnList2("{\"isAfter\": [{\"var\": \"now\"}, {\"buildTime\": [\"custom\", \"2020-01-01T22:00:00.000Z\"]}]}")
Expand All @@ -847,7 +847,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testRulesIsAfterCustomTime() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)

// Ticket is valid unlimited times, but only on two arbitrary days
setRuleOnList2("{\"isAfter\": [{\"var\": \"now\"}, {\"buildTime\": [\"customtime\", \"14:00\"]}]}")
Expand All @@ -863,7 +863,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testRulesCompareIsoweekday() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)

// Ticket is valid unlimited times, but only on two arbitrary days
setRuleOnList2("{\">=\": [{\"var\": \"now_isoweekday\"}, 6]}")
Expand Down Expand Up @@ -1033,7 +1033,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testSignedAndNotYetValid() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)
p2.setNow(ISODateTimeFormat.dateTime().parseDateTime("2023-02-03T22:59:59.000Z"))

val r = p2.check(mapOf("demo" to 1L), "Ok4EsqDRCr2cL6yDRtqeP7j5Usr1Vj1Db7J0izOuRGx6Qn0BS1ISW2nxlW8PXkYRk7PJhIBmsK1V1ucq5obBoBAMG4p9jCPKBAheRdFV0REVDZUCKAEAVAQA")
Expand All @@ -1048,7 +1048,7 @@ class AsyncCheckProviderTest : BaseDatabaseTest() {

@Test
fun testSignedAndNotLongerValid() {
val p2 = AsyncCheckProvider(configStore!!, dataStore, db)
val p2 = AsyncCheckProvider(configStore!!, db)
p2.setNow(ISODateTimeFormat.dateTime().parseDateTime("2023-02-03T11:01:01.000Z"))

val r = p2.check(mapOf("demo" to 1L), "EU9dJn3k5jzwfY4JQAKrTOVFmo+BvZKwH6UAIFOz3XTxABa7tmjU5UoLD8hJr3440uY7IFEHzau1DVk0sP994bgnzLNswAAKBARdUdGMmNVSHVUCKAEAVAQA")
Expand Down

0 comments on commit af1c2ed

Please sign in to comment.