mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-07 16:33:08 +00:00
feat(archive): respond with error on more than 10 content topics query
This commit is contained in:
parent
982cd28265
commit
3ee87d1848
@ -214,6 +214,29 @@ procSuite "Waku Archive - find messages":
|
|||||||
response.messages.anyIt(it == msg1)
|
response.messages.anyIt(it == msg1)
|
||||||
response.messages.anyIt(it == msg3)
|
response.messages.anyIt(it == msg3)
|
||||||
|
|
||||||
|
test "handle query with more than 10 content filters":
|
||||||
|
## Setup
|
||||||
|
let
|
||||||
|
driver = newTestArchiveDriver()
|
||||||
|
archive = newTestWakuArchive(driver)
|
||||||
|
|
||||||
|
let queryTopics = toSeq(1..15).mapIt(ContentTopic($it))
|
||||||
|
|
||||||
|
## Given
|
||||||
|
let req = ArchiveQuery(contentTopics: queryTopics)
|
||||||
|
|
||||||
|
## When
|
||||||
|
let queryRes = archive.findMessages(req)
|
||||||
|
|
||||||
|
## Then
|
||||||
|
check:
|
||||||
|
queryRes.isErr()
|
||||||
|
|
||||||
|
let error = queryRes.tryError()
|
||||||
|
check:
|
||||||
|
error.kind == ArchiveErrorKind.INVALID_QUERY
|
||||||
|
error.cause == "too many content topics"
|
||||||
|
|
||||||
test "handle query with pubsub topic filter":
|
test "handle query with pubsub topic filter":
|
||||||
## Setup
|
## Setup
|
||||||
let
|
let
|
||||||
|
|||||||
@ -126,6 +126,8 @@ proc findMessages*(w: WakuArchive, query: ArchiveQuery): ArchiveResult {.gcsafe.
|
|||||||
else: min(query.pageSize, MaxPageSize)
|
else: min(query.pageSize, MaxPageSize)
|
||||||
qAscendingOrder = query.ascending
|
qAscendingOrder = query.ascending
|
||||||
|
|
||||||
|
if qContentTopics.len > 10:
|
||||||
|
return err(ArchiveError.invalidQuery("too many content topics"))
|
||||||
|
|
||||||
let queryStartTime = getTime().toUnixFloat()
|
let queryStartTime = getTime().toUnixFloat()
|
||||||
|
|
||||||
|
|||||||
@ -85,3 +85,6 @@ proc `$`*(err: ArchiveError): string =
|
|||||||
"INVALID_QUERY: " & err.cause
|
"INVALID_QUERY: " & err.cause
|
||||||
of ArchiveErrorKind.UNKNOWN:
|
of ArchiveErrorKind.UNKNOWN:
|
||||||
"UNKNOWN"
|
"UNKNOWN"
|
||||||
|
|
||||||
|
proc invalidQuery*(T: type ArchiveError, cause: string): T =
|
||||||
|
ArchiveError(kind: ArchiveErrorKind.INVALID_QUERY, cause: cause)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user