47 lines
1.0 KiB
Nim
Raw Normal View History

2025-02-11 14:02:30 +01:00
import pkg/chronos
import pkg/questionable/results
2025-02-12 14:48:57 +01:00
import ../../../codexcrawler/types
import ../../../codexcrawler/list
2025-02-11 14:02:30 +01:00
2025-02-11 14:29:41 +01:00
type MockList* = ref object of List
loadCalled*: bool
added*: seq[Nid]
addSuccess*: bool
removed*: seq[Nid]
removeSuccess*: bool
length*: int
2025-02-11 14:02:30 +01:00
2025-06-02 15:30:12 +02:00
method load*(this: MockList): Future[?!void] {.async: (raises: [CancelledError]).} =
2025-02-11 14:02:30 +01:00
this.loadCalled = true
2025-02-11 14:29:41 +01:00
return success()
2025-02-11 14:02:30 +01:00
2025-06-02 16:16:41 +02:00
method add*(
this: MockList, nid: Nid
): Future[?!void] {.async: (raises: [CancelledError]).} =
2025-02-11 14:02:30 +01:00
this.added.add(nid)
if this.addSuccess:
return success()
return failure("test failure")
2025-06-02 16:16:41 +02:00
method remove*(
this: MockList, nid: Nid
): Future[?!void] {.async: (raises: [CancelledError]).} =
2025-02-11 14:02:30 +01:00
this.removed.add(nid)
if this.removeSuccess:
return success()
return failure("test failure")
2025-02-11 14:29:41 +01:00
method len*(this: MockList): int =
return this.length
2025-02-11 14:02:30 +01:00
proc createMockList*(): MockList =
MockList(
loadCalled: false,
added: newSeq[Nid](),
addSuccess: true,
removed: newSeq[Nid](),
2025-02-11 14:29:41 +01:00
removeSuccess: true,
length: 0,
2025-02-11 14:02:30 +01:00
)