1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Implement TTRSS feed updating; fixes #86

This commit is contained in:
J. King 2017-10-03 16:14:37 -04:00
parent 03d5d554a9
commit 69b34a4e5a
3 changed files with 35 additions and 2 deletions

View file

@ -497,7 +497,7 @@ class Database {
$q = new Query(
"SELECT
arsse_subscriptions.id as id,
url,favicon,source,folder,pinned,err_count,err_msg,order_type,added,
feed,url,favicon,source,folder,pinned,err_count,err_msg,order_type,added,
topmost.top as top_folder,
coalesce(arsse_subscriptions.title, arsse_feeds.title) as title,
(SELECT count(*) from arsse_articles where feed is arsse_subscriptions.feed) - (SELECT count(*) from arsse_marks where subscription is arsse_subscriptions.id and read is 1) as unread

View file

@ -342,7 +342,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
public function opRenameFeed(array $data) {
if (!isset($data['feed_id']) || !ValueInfo::id($data['feed_id']) || !isset($data['caption'])) {
// if the feed is invalid, throw an error
// if the feed is invalid or there is no caption, throw an error
throw new Exception("INCORRECT_USAGE");
}
$info = ValueInfo::str($data['caption']);
@ -379,4 +379,17 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
'num_feeds' => Arsse::$db->subscriptionCount(Arsse::$user->id),
];
}
public function opUpdateFeed(array $data): array {
if (!isset($data['feed_id']) || !ValueInfo::id($data['feed_id'])) {
// if the feed is invalid, throw an error
throw new Exception("INCORRECT_USAGE");
}
try {
Arsse::$db->feedUpdate(Arsse::$db->subscriptionPropertiesGet(Arsse::$user->id, (int) $data['feed_id'])['feed']);
} catch(ExceptionInput $e) {
throw new Exception("FEED_NOT_FOUND");
}
return ['status' => "OK"];
}
}

View file

@ -609,4 +609,24 @@ class TestTinyTinyAPI extends Test\AbstractTest {
$this->assertEquals($this->respGood($exp[0]), $this->h->dispatch(new Request("POST", "", json_encode($in))));
$this->assertEquals($this->respGood($exp[1]), $this->h->dispatch(new Request("POST", "", json_encode($in))));
}
public function testUpdateAFeed() {
$in = [
['op' => "updateFeed", 'sid' => "PriestsOfSyrinx", 'feed_id' => 1],
['op' => "updateFeed", 'sid' => "PriestsOfSyrinx", 'feed_id' => 2],
['op' => "updateFeed", 'sid' => "PriestsOfSyrinx", 'feed_id' => -1],
['op' => "updateFeed", 'sid' => "PriestsOfSyrinx"],
];
Phake::when(Arsse::$db)->feedUpdate(11)->thenReturn(true);
Phake::when(Arsse::$db)->subscriptionPropertiesGet(Arsse::$user->id, 1)->thenReturn(['id' => 1, 'feed' => 11]);
Phake::when(Arsse::$db)->subscriptionPropertiesGet(Arsse::$user->id, 2)->thenThrow(new ExceptionInput("subjectMissing"));
$exp = $this->respGood(['status' => "OK"]);
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[0]))));
Phake::verify(Arsse::$db)->feedUpdate(11);
$exp = $this->respErr("FEED_NOT_FOUND");
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[1]))));
$exp = $this->respErr("INCORRECT_USAGE");
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[2]))));
$this->assertEquals($exp, $this->h->dispatch(new Request("POST", "", json_encode($in[3]))));
}
}