all repos — litestore @ b91628c6939b5ce9532cf6bed88a18f4e71f2f32

A minimalist nosql document store.

Fixed and improved tests.
* Closes #45.
h3rald h3rald@h3rald.com
Sat, 22 Sep 2018 21:10:24 +0200
commit

b91628c6939b5ce9532cf6bed88a18f4e71f2f32

parent

222044c72061043482a6528cc6f7e699797c47fc

3 files changed, 22 insertions(+), 6 deletions(-)

jump to
M src/litestorepkg/lib/api_v4.nimsrc/litestorepkg/lib/api_v4.nim

@@ -161,22 +161,22 @@ of "tags":

options.tags = pair[1] of "created-after": try: - options.createdAfter = pair[1].parseInt.fromUnix.local.format("yyyy-MM-dd'T'HH:mm:ss'Z'") + options.createdAfter = pair[1].parseInt.fromUnix.utc.format("yyyy-MM-dd'T'HH:mm:ss'Z'") except: raise newException(EInvalidRequest, "Invalid created-after value: $1" % getCurrentExceptionMsg()) of "created-before": try: - options.createdBefore = pair[1].parseInt.fromUnix.local.format("yyyy-MM-dd'T'HH:mm:ss'Z'") + options.createdBefore = pair[1].parseInt.fromUnix.utc.format("yyyy-MM-dd'T'HH:mm:ss'Z'") except: raise newException(EInvalidRequest, "Invalid created-before value: $1" % getCurrentExceptionMsg()) of "modified-after": try: - options.modifiedAfter = pair[1].parseInt.fromUnix.local.format("yyyy-MM-dd'T'HH:mm:ss'Z'") + options.modifiedAfter = pair[1].parseInt.fromUnix.utc.format("yyyy-MM-dd'T'HH:mm:ss'Z'") except: raise newException(EInvalidRequest, "Invalid modified.after value: $1" % getCurrentExceptionMsg()) of "modified-before": try: - options.modifiedBefore = pair[1].parseInt.fromUnix.local.format("yyyy-MM-dd'T'HH:mm:ss'Z'") + options.modifiedBefore = pair[1].parseInt.fromUnix.utc.format("yyyy-MM-dd'T'HH:mm:ss'Z'") except: raise newException(EInvalidRequest, "Invalid modified-before value: $1" % getCurrentExceptionMsg()) of "limit":

@@ -195,6 +195,8 @@ if orderby != "":

options.orderby = orderby else: raise newException(EInvalidRequest, "Invalid sort value: $1" % pair[1]) + of "contents", "raw": + discard else: raise newException(EInvalidRequest, "Invalid option: $1" % pair[0])
M src/litestorepkg/lib/utils.nimsrc/litestorepkg/lib/utils.nim

@@ -170,7 +170,7 @@ var obj = newJObject()

for field in options.jsonSelect: let keys = field.path.replace("$.", "").split(".") let res = result["data"]{keys} - if res.len == 0: + if res.isNil: obj[field.alias] = newJNull() else: obj[field.alias] = %res
M test/http_api.nimtest/http_api.nim

@@ -1,4 +1,4 @@

-import unittest, json, httpclient, strutils, os +import unittest, json, httpclient, strutils, os, times suite "LiteStore HTTP API":

@@ -7,6 +7,7 @@ for i in 1..8:

contents.add parseFile("data/$1.json" % i.intToStr) var rpost: Response; var ids = newSeq[string](0) + let t_now = now().utc.toTime.toUnix const srv = "http://localhost:9500/" let cli = newHttpClient()

@@ -205,3 +206,16 @@ var json = rget.body.parseJson

check(json["results"][2]["data"]["age"] == %31) check(json["results"][5]["data"]["name"]["first"] == %"Hart") + test "GET documents in range": + var rget = jget("docs/?created-after=$1&created-before=$2" % [$t_now, $(t_now+10)]) + var json = rget.body.parseJson + check(json["total"] == %8) + + test "GET tags": + var rget = jget("tags") + var json = rget.body.parseJson + rget = jget("tags/?like=tag*") + json = rget.body.parseJson + check(json["total"] == %10) + check(json["results"][0]["id"] == %"tag0") + check(json["results"][0]["documents"] == %4)