diff --git a/server/src/org/isoron/uhabits/sync/app/StorageModule.kt b/server/src/org/isoron/uhabits/sync/app/StorageModule.kt index 5d1a17679..fb85b7edf 100644 --- a/server/src/org/isoron/uhabits/sync/app/StorageModule.kt +++ b/server/src/org/isoron/uhabits/sync/app/StorageModule.kt @@ -50,5 +50,14 @@ fun Routing.storage(app: SyncApplication) { call.respond(HttpStatusCode.Conflict, currData) } } + get("version") { + val key = call.parameters["key"]!! + try { + val data = app.server.get(key) + call.respond(HttpStatusCode.OK, data.version) + } catch(e: KeyNotFoundException) { + call.respond(HttpStatusCode.NotFound) + } + } } } \ No newline at end of file diff --git a/server/test/org/isoron/uhabits/sync/app/StorageModuleTest.kt b/server/test/org/isoron/uhabits/sync/app/StorageModuleTest.kt index 01e23b328..0ef5f014c 100644 --- a/server/test/org/isoron/uhabits/sync/app/StorageModuleTest.kt +++ b/server/test/org/isoron/uhabits/sync/app/StorageModuleTest.kt @@ -41,6 +41,17 @@ class StorageModuleTest : BaseApplicationTest() { } } + @Test + fun `when get version succeeds should return version`() { + `when`(server.get("k1")).thenReturn(data1) + withTestApplication(app()) { + handleGet("/db/k1/version").apply { + assertEquals(HttpStatusCode.OK, response.status()) + assertEquals("1", response.content) + } + } + } + @Test fun `when get with invalid key should return 404`() { `when`(server.get("k1")).thenThrow(KeyNotFoundException())