1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-23 07:14:55 +00:00

Tests for undoing read marks

This commit is contained in:
J. King 2019-04-10 18:27:57 -04:00
parent daeff63239
commit 2d18be959c
2 changed files with 17 additions and 1 deletions

View file

@ -302,7 +302,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
// may not actually signify a mark, but we'll otherwise also count back fifteen seconds // may not actually signify a mark, but we'll otherwise also count back fifteen seconds
$c = new Context; $c = new Context;
$lastUnread = Date::normalize($lastUnread, "sql"); $lastUnread = Date::normalize($lastUnread, "sql");
$since = Date::sub("DT15S", $lastUnread); $since = Date::sub("PT15S", $lastUnread);
$c->unread(false)->markedSince($since); $c->unread(false)->markedSince($since);
Arsse::$db->articleMark(Arsse::$user->id, ['read' => false], $c); Arsse::$db->articleMark(Arsse::$user->id, ['read' => false], $c);
} }

View file

@ -467,4 +467,20 @@ class TestAPI extends \JKingWeb\Arsse\Test\AbstractTest {
$act = $this->h->dispatch($this->req("api")); $act = $this->h->dispatch($this->req("api"));
$this->assertMessage($exp, $act); $this->assertMessage($exp, $act);
} }
public function testUndoReadMarks() {
$unread = [['id' => 4],['id' => 5],['id' => 6]];
$out = ['unread_item_ids' => "4,5,6"];
\Phake::when(Arsse::$db)->articleList(Arsse::$user->id, (new Context)->limit(1), ["marked_date"], ["marked_date desc"])->thenReturn(new Result([['marked_date' => "2000-01-01 00:00:00"]]));
\Phake::when(Arsse::$db)->articleList(Arsse::$user->id, (new Context)->unread(true))->thenReturn(new Result($unread));
\Phake::when(Arsse::$db)->articleMark->thenReturn(0);
$exp = new JsonResponse($out);
$act = $this->h->dispatch($this->req("api", ['unread_recently_read' => 1]));
$this->assertMessage($exp, $act);
\Phake::verify(Arsse::$db)->articleMark(Arsse::$user->id, ['read' => false], (new Context)->unread(false)->markedSince("1999-12-31T23:59:45Z"));
\Phake::when(Arsse::$db)->articleList(Arsse::$user->id, (new Context)->limit(1), ["marked_date"], ["marked_date desc"])->thenReturn(new Result([]));
$act = $this->h->dispatch($this->req("api", ['unread_recently_read' => 1]));
$this->assertMessage($exp, $act);
\Phake::verify(Arsse::$db)->articleMark; // only called one time, above
}
} }