Repository navigation
Show readers the last pickup day of a ready loan #61
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
Open
fabiodalez-dev
wants to merge
4
commits into
main
Choose a base branch
from
feat/reader-pickup-deadline
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
897c948
Show readers the last pickup day of a ready loan
fabiodalez-dev 6fbb92a
Keep pickup deadlines in the Android offline cache
fabiodalez-dev 313c2f4
Keep the server calendar of a loan in the offline cache
fabiodalez-dev 2819162
Treat a blank pickup day as absent
fabiodalez-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package com.pinakes.app | ||
|
|
||
| import android.database.sqlite.SQLiteDatabase | ||
| import androidx.room.Room | ||
| import androidx.test.core.app.ApplicationProvider | ||
| import com.pinakes.app.data.local.AppDatabase | ||
| import com.pinakes.app.data.local.CachedLoan | ||
| import com.pinakes.app.data.local.toLoansData | ||
| import kotlinx.coroutines.runBlocking | ||
| import org.junit.After | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertNull | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.RobolectricTestRunner | ||
| import org.robolectric.annotation.Config | ||
| import java.io.File | ||
|
|
||
| /** | ||
| * Upgrading the offline cache keeps what v3 stored. The v3 schema below is the one Room generated | ||
| * for version 3 and never changes; Room validates the migrated tables against the current | ||
| * entities, so a column added to an entity without a migration fails here instead of on a phone. | ||
| * No destructive fallback in this builder: a missing migration is an error, not an empty cache. | ||
| */ | ||
| @RunWith(RobolectricTestRunner::class) | ||
| @Config(sdk = [34], application = android.app.Application::class) | ||
| class CacheMigrationTest { | ||
| private val context get() = ApplicationProvider.getApplicationContext<android.app.Application>() | ||
| private lateinit var file: File | ||
|
|
||
| @Before fun setup() { | ||
| file = context.getDatabasePath("migration-test.db") | ||
| file.parentFile?.mkdirs() | ||
| file.delete() | ||
| } | ||
|
|
||
| @After fun teardown() { | ||
| file.delete() | ||
| } | ||
|
|
||
| private fun createV3() { | ||
| val raw = SQLiteDatabase.openOrCreateDatabase(file, null) | ||
| V3_SCHEMA.forEach(raw::execSQL) | ||
| raw.execSQL("INSERT INTO cached_loans (bucket,id,position,bookId,title,status,dueAt,dueAttention,cancellable) VALUES ('active',7,0,70,'Kept','da_ritirare','2030-12-30',0,1)") | ||
| raw.execSQL("INSERT INTO sync_meta (`key`,`value`) VALUES ('watermark','w3')") | ||
| raw.version = 3 | ||
| raw.close() | ||
| } | ||
|
|
||
| @Test fun v3RowsSurviveAndTheNewCalendarFieldsStartEmpty() = runBlocking { | ||
| createV3() | ||
| val db = Room.databaseBuilder(context, AppDatabase::class.java, file.absolutePath) | ||
| .addMigrations(AppDatabase.MIGRATION_3_4) | ||
| .allowMainThreadQueries() | ||
| .build() | ||
| try { | ||
| val loan = db.libraryDao().loans(CachedLoan.LOAN_BUCKETS).toLoansData().active.single() | ||
| assertEquals("Kept", loan.title) | ||
| assertEquals("2030-12-30", loan.dueAt) | ||
| assertNull(loan.effectiveDueAt) | ||
| assertNull(loan.isOverdue) | ||
| assertNull(loan.pickupDeadline) | ||
| assertEquals("w3", db.syncMetaDao().get("watermark")) | ||
| assertEquals(4, db.openHelper.readableDatabase.version) | ||
| } finally { | ||
| db.close() | ||
| } | ||
| } | ||
|
|
||
| private companion object { | ||
| val V3_SCHEMA = listOf( | ||
| "CREATE TABLE IF NOT EXISTS `cached_books` (`id` INTEGER NOT NULL, `title` TEXT NOT NULL, `subtitle` TEXT, `author` TEXT, `publisher` TEXT, `genre` TEXT, `year` INTEGER, `language` TEXT, `mediaType` TEXT, `isbn13` TEXT, `isbn10` TEXT, `ean` TEXT, `pages` INTEGER, `description` TEXT, `locationLabel` TEXT, `coverUrl` TEXT, `copiesTotal` INTEGER NOT NULL, `copiesAvailable` INTEGER NOT NULL, `loanableNow` INTEGER NOT NULL, `isWanted` INTEGER NOT NULL, `updatedAt` TEXT NOT NULL, `searchKey` TEXT NOT NULL, PRIMARY KEY(`id`))", | ||
| "CREATE INDEX IF NOT EXISTS `index_cached_books_title` ON `cached_books` (`title`)", | ||
| "CREATE INDEX IF NOT EXISTS `index_cached_books_updatedAt` ON `cached_books` (`updatedAt`)", | ||
| "CREATE TABLE IF NOT EXISTS `cached_loans` (`bucket` TEXT NOT NULL, `id` INTEGER NOT NULL, `position` INTEGER NOT NULL, `bookId` INTEGER NOT NULL, `title` TEXT NOT NULL, `coverUrl` TEXT, `status` TEXT NOT NULL, `statusLabel` TEXT, `requestedAt` TEXT, `loanedAt` TEXT, `dueAt` TEXT, `dueAttention` INTEGER NOT NULL, `returnedAt` TEXT, `renewals` INTEGER, `cancellable` INTEGER NOT NULL, `queuePosition` INTEGER, `requestedFrom` TEXT, `requestedTo` TEXT, `reservedAt` TEXT, `expiresAt` TEXT, PRIMARY KEY(`bucket`, `id`))", | ||
| "CREATE TABLE IF NOT EXISTS `cached_wishlist` (`bookId` INTEGER NOT NULL, `position` INTEGER NOT NULL, `title` TEXT NOT NULL, `author` TEXT, `year` INTEGER, `coverUrl` TEXT, `copiesAvailable` INTEGER NOT NULL, `loanableNow` INTEGER NOT NULL, PRIMARY KEY(`bookId`))", | ||
| "CREATE TABLE IF NOT EXISTS `sync_meta` (`key` TEXT NOT NULL, `value` TEXT NOT NULL, PRIMARY KEY(`key`))", | ||
| "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", | ||
| "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'v3')", | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.