conflicting pathing
Some checks failed
CI - Multi-Platform Native / Build iOS (RSSuper) (push) Has been cancelled
CI - Multi-Platform Native / Build macOS (push) Has been cancelled
CI - Multi-Platform Native / Build Android (push) Has been cancelled
CI - Multi-Platform Native / Build Linux (push) Has been cancelled
CI - Multi-Platform Native / Integration Tests (push) Has been cancelled
CI - Multi-Platform Native / Build Summary (push) Has been cancelled
Some checks failed
CI - Multi-Platform Native / Build iOS (RSSuper) (push) Has been cancelled
CI - Multi-Platform Native / Build macOS (push) Has been cancelled
CI - Multi-Platform Native / Build Android (push) Has been cancelled
CI - Multi-Platform Native / Build Linux (push) Has been cancelled
CI - Multi-Platform Native / Integration Tests (push) Has been cancelled
CI - Multi-Platform Native / Build Summary (push) Has been cancelled
This commit is contained in:
@@ -1,247 +1,423 @@
|
||||
/*
|
||||
* RepositoryTests.vala
|
||||
*
|
||||
* Unit tests for repository layer.
|
||||
* Unit tests for feed and subscription repositories.
|
||||
*/
|
||||
|
||||
using Gio = Org.Gnome.Valetta.Gio;
|
||||
|
||||
public class RSSuper.RepositoryTests {
|
||||
|
||||
public static int main(string[] args) {
|
||||
var tests = new RepositoryTests();
|
||||
|
||||
tests.test_bookmark_repository_create();
|
||||
tests.test_bookmark_repository_read();
|
||||
tests.test_bookmark_repository_update();
|
||||
tests.test_bookmark_repository_delete();
|
||||
tests.test_bookmark_repository_tags();
|
||||
tests.test_bookmark_repository_by_feed_item();
|
||||
tests.test_feed_repository_get_items();
|
||||
tests.test_feed_repository_get_item_by_id();
|
||||
tests.test_feed_repository_insert_item();
|
||||
tests.test_feed_repository_insert_items();
|
||||
tests.test_feed_repository_update_item();
|
||||
tests.test_feed_repository_mark_as_read();
|
||||
tests.test_feed_repository_mark_as_starred();
|
||||
tests.test_feed_repository_delete_item();
|
||||
tests.test_feed_repository_get_unread_count();
|
||||
|
||||
tests.test_subscription_repository_get_all();
|
||||
tests.test_subscription_repository_get_enabled();
|
||||
tests.test_subscription_repository_get_by_category();
|
||||
tests.test_subscription_repository_get_by_id();
|
||||
tests.test_subscription_repository_get_by_url();
|
||||
tests.test_subscription_repository_insert();
|
||||
tests.test_subscription_repository_update();
|
||||
tests.test_subscription_repository_delete();
|
||||
tests.test_subscription_repository_set_enabled();
|
||||
tests.test_subscription_repository_set_error();
|
||||
tests.test_subscription_repository_update_timestamps();
|
||||
|
||||
print("All repository tests passed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void test_bookmark_repository_create() {
|
||||
// Create a test database
|
||||
public void test_feed_repository_get_items() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new FeedRepositoryImpl(db);
|
||||
|
||||
// Create bookmark repository
|
||||
var repo = new BookmarkRepositoryImpl(db);
|
||||
var state = new State<FeedItem[]>();
|
||||
repo.get_feed_items(null, (s) => {
|
||||
state.set_success(db.getFeedItems(null));
|
||||
});
|
||||
|
||||
// Create a test bookmark
|
||||
var bookmark = Bookmark.new_internal(
|
||||
id: "test-bookmark-1",
|
||||
feed_item_id: "test-item-1",
|
||||
created_at: Time.now()
|
||||
);
|
||||
assert(state.is_loading() == true);
|
||||
assert(state.is_success() == false);
|
||||
assert(state.is_error() == false);
|
||||
|
||||
// Test creation
|
||||
var result = repo.add(bookmark);
|
||||
|
||||
if (result.is_error()) {
|
||||
printerr("FAIL: Bookmark creation failed: %s\n", result.error.message);
|
||||
return;
|
||||
}
|
||||
|
||||
print("PASS: test_bookmark_repository_create\n");
|
||||
print("PASS: test_feed_repository_get_items\n");
|
||||
}
|
||||
|
||||
public void test_bookmark_repository_read() {
|
||||
// Create a test database
|
||||
public void test_feed_repository_get_item_by_id() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new FeedRepositoryImpl(db);
|
||||
|
||||
// Create bookmark repository
|
||||
var repo = new BookmarkRepositoryImpl(db);
|
||||
|
||||
// Create a test bookmark
|
||||
var bookmark = Bookmark.new_internal(
|
||||
id: "test-bookmark-2",
|
||||
feed_item_id: "test-item-2",
|
||||
created_at: Time.now()
|
||||
var item = db.create_feed_item(
|
||||
id: "test-item-1",
|
||||
title: "Test Item",
|
||||
url: "https://example.com/article/1"
|
||||
);
|
||||
|
||||
var create_result = repo.add(bookmark);
|
||||
if (create_result.is_error()) {
|
||||
printerr("FAIL: Could not create bookmark: %s\n", create_result.error.message);
|
||||
return;
|
||||
}
|
||||
var result = repo.get_feed_item_by_id("test-item-1");
|
||||
|
||||
// Test reading
|
||||
var read_result = repo.get_by_id("test-bookmark-2");
|
||||
assert(result != null);
|
||||
assert(result.id == "test-item-1");
|
||||
assert(result.title == "Test Item");
|
||||
|
||||
if (read_result.is_error()) {
|
||||
printerr("FAIL: Bookmark read failed: %s\n", read_result.error.message);
|
||||
return;
|
||||
}
|
||||
|
||||
var saved = read_result.value;
|
||||
if (saved.id != "test-bookmark-2") {
|
||||
printerr("FAIL: Expected id 'test-bookmark-2', got '%s'\n", saved.id);
|
||||
return;
|
||||
}
|
||||
|
||||
print("PASS: test_bookmark_repository_read\n");
|
||||
print("PASS: test_feed_repository_get_item_by_id\n");
|
||||
}
|
||||
|
||||
public void test_bookmark_repository_update() {
|
||||
// Create a test database
|
||||
public void test_feed_repository_insert_item() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new FeedRepositoryImpl(db);
|
||||
|
||||
// Create bookmark repository
|
||||
var repo = new BookmarkRepositoryImpl(db);
|
||||
|
||||
// Create a test bookmark
|
||||
var bookmark = Bookmark.new_internal(
|
||||
id: "test-bookmark-3",
|
||||
feed_item_id: "test-item-3",
|
||||
created_at: Time.now()
|
||||
var item = FeedItem.new(
|
||||
id: "test-item-2",
|
||||
title: "New Item",
|
||||
url: "https://example.com/article/2",
|
||||
published_at: Time.now()
|
||||
);
|
||||
|
||||
var create_result = repo.add(bookmark);
|
||||
if (create_result.is_error()) {
|
||||
printerr("FAIL: Could not create bookmark: %s\n", create_result.error.message);
|
||||
return;
|
||||
}
|
||||
var result = repo.insert_feed_item(item);
|
||||
|
||||
// Update the bookmark
|
||||
bookmark.tags = ["important", "read-later"];
|
||||
var update_result = repo.update(bookmark);
|
||||
assert(result.is_error() == false);
|
||||
|
||||
if (update_result.is_error()) {
|
||||
printerr("FAIL: Bookmark update failed: %s\n", update_result.error.message);
|
||||
return;
|
||||
}
|
||||
var retrieved = repo.get_feed_item_by_id("test-item-2");
|
||||
assert(retrieved != null);
|
||||
assert(retrieved.id == "test-item-2");
|
||||
|
||||
// Verify update
|
||||
var read_result = repo.get_by_id("test-bookmark-3");
|
||||
if (read_result.is_error()) {
|
||||
printerr("FAIL: Could not read bookmark: %s\n", read_result.error.message);
|
||||
return;
|
||||
}
|
||||
|
||||
var saved = read_result.value;
|
||||
if (saved.tags.length != 2) {
|
||||
printerr("FAIL: Expected 2 tags, got %d\n", saved.tags.length);
|
||||
return;
|
||||
}
|
||||
|
||||
print("PASS: test_bookmark_repository_update\n");
|
||||
print("PASS: test_feed_repository_insert_item\n");
|
||||
}
|
||||
|
||||
public void test_bookmark_repository_delete() {
|
||||
// Create a test database
|
||||
public void test_feed_repository_insert_items() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new FeedRepositoryImpl(db);
|
||||
|
||||
// Create bookmark repository
|
||||
var repo = new BookmarkRepositoryImpl(db);
|
||||
var items = new FeedItem[2];
|
||||
|
||||
// Create a test bookmark
|
||||
var bookmark = Bookmark.new_internal(
|
||||
id: "test-bookmark-4",
|
||||
feed_item_id: "test-item-4",
|
||||
created_at: Time.now()
|
||||
items[0] = FeedItem.new(
|
||||
id: "test-item-3",
|
||||
title: "Item 1",
|
||||
url: "https://example.com/article/3",
|
||||
published_at: Time.now()
|
||||
);
|
||||
|
||||
var create_result = repo.add(bookmark);
|
||||
if (create_result.is_error()) {
|
||||
printerr("FAIL: Could not create bookmark: %s\n", create_result.error.message);
|
||||
return;
|
||||
}
|
||||
items[1] = FeedItem.new(
|
||||
id: "test-item-4",
|
||||
title: "Item 2",
|
||||
url: "https://example.com/article/4",
|
||||
published_at: Time.now()
|
||||
);
|
||||
|
||||
// Delete the bookmark
|
||||
var delete_result = repo.remove("test-bookmark-4");
|
||||
var result = repo.insert_feed_items(items);
|
||||
|
||||
if (delete_result.is_error()) {
|
||||
printerr("FAIL: Bookmark deletion failed: %s\n", delete_result.error.message);
|
||||
return;
|
||||
}
|
||||
assert(result.is_error() == false);
|
||||
|
||||
// Verify deletion
|
||||
var read_result = repo.get_by_id("test-bookmark-4");
|
||||
if (!read_result.is_error()) {
|
||||
printerr("FAIL: Bookmark should have been deleted\n");
|
||||
return;
|
||||
}
|
||||
var all_items = repo.get_feed_items(null);
|
||||
assert(all_items.length == 2);
|
||||
|
||||
print("PASS: test_bookmark_repository_delete\n");
|
||||
print("PASS: test_feed_repository_insert_items\n");
|
||||
}
|
||||
|
||||
public void test_bookmark_repository_tags() {
|
||||
// Create a test database
|
||||
public void test_feed_repository_update_item() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new FeedRepositoryImpl(db);
|
||||
|
||||
// Create bookmark repository
|
||||
var repo = new BookmarkRepositoryImpl(db);
|
||||
|
||||
// Create multiple bookmarks with different tags
|
||||
var bookmark1 = Bookmark.new_internal(
|
||||
id: "test-bookmark-5",
|
||||
feed_item_id: "test-item-5",
|
||||
created_at: Time.now()
|
||||
var item = db.create_feed_item(
|
||||
id: "test-item-5",
|
||||
title: "Original Title",
|
||||
url: "https://example.com/article/5"
|
||||
);
|
||||
bookmark1.tags = ["important"];
|
||||
repo.add(bookmark1);
|
||||
|
||||
var bookmark2 = Bookmark.new_internal(
|
||||
id: "test-bookmark-6",
|
||||
feed_item_id: "test-item-6",
|
||||
created_at: Time.now()
|
||||
);
|
||||
bookmark2.tags = ["read-later"];
|
||||
repo.add(bookmark2);
|
||||
item.title = "Updated Title";
|
||||
|
||||
// Test tag-based query
|
||||
var by_tag_result = repo.get_by_tag("important");
|
||||
var result = repo.update_feed_item(item);
|
||||
|
||||
if (by_tag_result.is_error()) {
|
||||
printerr("FAIL: Tag query failed: %s\n", by_tag_result.error.message);
|
||||
return;
|
||||
}
|
||||
assert(result.is_error() == false);
|
||||
|
||||
var bookmarks = by_tag_result.value;
|
||||
if (bookmarks.length != 1) {
|
||||
printerr("FAIL: Expected 1 bookmark with tag 'important', got %d\n", bookmarks.length);
|
||||
return;
|
||||
}
|
||||
var updated = repo.get_feed_item_by_id("test-item-5");
|
||||
assert(updated != null);
|
||||
assert(updated.title == "Updated Title");
|
||||
|
||||
print("PASS: test_bookmark_repository_tags\n");
|
||||
print("PASS: test_feed_repository_update_item\n");
|
||||
}
|
||||
|
||||
public void test_bookmark_repository_by_feed_item() {
|
||||
// Create a test database
|
||||
public void test_feed_repository_mark_as_read() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new FeedRepositoryImpl(db);
|
||||
|
||||
// Create bookmark repository
|
||||
var repo = new BookmarkRepositoryImpl(db);
|
||||
|
||||
// Create multiple bookmarks for the same feed item
|
||||
var bookmark1 = Bookmark.new_internal(
|
||||
id: "test-bookmark-7",
|
||||
feed_item_id: "test-item-7",
|
||||
created_at: Time.now()
|
||||
var item = db.create_feed_item(
|
||||
id: "test-item-6",
|
||||
title: "Read Item",
|
||||
url: "https://example.com/article/6"
|
||||
);
|
||||
repo.add(bookmark1);
|
||||
|
||||
var bookmark2 = Bookmark.new_internal(
|
||||
id: "test-bookmark-8",
|
||||
feed_item_id: "test-item-7",
|
||||
created_at: Time.now()
|
||||
var result = repo.mark_as_read("test-item-6", true);
|
||||
|
||||
assert(result.is_error() == false);
|
||||
|
||||
var unread = repo.get_unread_count(null);
|
||||
assert(unread == 0);
|
||||
|
||||
print("PASS: test_feed_repository_mark_as_read\n");
|
||||
}
|
||||
|
||||
public void test_feed_repository_mark_as_starred() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new FeedRepositoryImpl(db);
|
||||
|
||||
var item = db.create_feed_item(
|
||||
id: "test-item-7",
|
||||
title: "Starred Item",
|
||||
url: "https://example.com/article/7"
|
||||
);
|
||||
repo.add(bookmark2);
|
||||
|
||||
// Test feed item-based query
|
||||
var by_item_result = repo.get_by_feed_item("test-item-7");
|
||||
var result = repo.mark_as_starred("test-item-7", true);
|
||||
|
||||
if (by_item_result.is_error()) {
|
||||
printerr("FAIL: Feed item query failed: %s\n", by_item_result.error.message);
|
||||
return;
|
||||
}
|
||||
assert(result.is_error() == false);
|
||||
|
||||
var bookmarks = by_item_result.value;
|
||||
if (bookmarks.length != 2) {
|
||||
printerr("FAIL: Expected 2 bookmarks for feed item, got %d\n", bookmarks.length);
|
||||
return;
|
||||
}
|
||||
print("PASS: test_feed_repository_mark_as_starred\n");
|
||||
}
|
||||
|
||||
public void test_feed_repository_delete_item() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new FeedRepositoryImpl(db);
|
||||
|
||||
print("PASS: test_bookmark_repository_by_feed_item\n");
|
||||
var item = db.create_feed_item(
|
||||
id: "test-item-8",
|
||||
title: "Delete Item",
|
||||
url: "https://example.com/article/8"
|
||||
);
|
||||
|
||||
var result = repo.delete_feed_item("test-item-8");
|
||||
|
||||
assert(result.is_error() == false);
|
||||
|
||||
var deleted = repo.get_feed_item_by_id("test-item-8");
|
||||
assert(deleted == null);
|
||||
|
||||
print("PASS: test_feed_repository_delete_item\n");
|
||||
}
|
||||
|
||||
public void test_feed_repository_get_unread_count() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new FeedRepositoryImpl(db);
|
||||
|
||||
var count = repo.get_unread_count(null);
|
||||
|
||||
assert(count == 0);
|
||||
|
||||
print("PASS: test_feed_repository_get_unread_count\n");
|
||||
}
|
||||
|
||||
public void test_subscription_repository_get_all() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new SubscriptionRepositoryImpl(db);
|
||||
|
||||
var state = new State<FeedSubscription[]>();
|
||||
repo.get_all_subscriptions((s) => {
|
||||
state.set_success(db.getAllSubscriptions());
|
||||
});
|
||||
|
||||
assert(state.is_loading() == true);
|
||||
assert(state.is_success() == false);
|
||||
|
||||
print("PASS: test_subscription_repository_get_all\n");
|
||||
}
|
||||
|
||||
public void test_subscription_repository_get_enabled() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new SubscriptionRepositoryImpl(db);
|
||||
|
||||
var state = new State<FeedSubscription[]>();
|
||||
repo.get_enabled_subscriptions((s) => {
|
||||
state.set_success(db.getEnabledSubscriptions());
|
||||
});
|
||||
|
||||
assert(state.is_loading() == true);
|
||||
assert(state.is_success() == false);
|
||||
|
||||
print("PASS: test_subscription_repository_get_enabled\n");
|
||||
}
|
||||
|
||||
public void test_subscription_repository_get_by_category() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new SubscriptionRepositoryImpl(db);
|
||||
|
||||
var state = new State<FeedSubscription[]>();
|
||||
repo.get_subscriptions_by_category("technology", (s) => {
|
||||
state.set_success(db.getSubscriptionsByCategory("technology"));
|
||||
});
|
||||
|
||||
assert(state.is_loading() == true);
|
||||
assert(state.is_success() == false);
|
||||
|
||||
print("PASS: test_subscription_repository_get_by_category\n");
|
||||
}
|
||||
|
||||
public void test_subscription_repository_get_by_id() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new SubscriptionRepositoryImpl(db);
|
||||
|
||||
var subscription = db.create_subscription(
|
||||
id: "test-sub-1",
|
||||
url: "https://example.com/feed.xml",
|
||||
title: "Test Subscription"
|
||||
);
|
||||
|
||||
var result = repo.get_subscription_by_id("test-sub-1");
|
||||
|
||||
assert(result != null);
|
||||
assert(result.id == "test-sub-1");
|
||||
|
||||
print("PASS: test_subscription_repository_get_by_id\n");
|
||||
}
|
||||
|
||||
public void test_subscription_repository_get_by_url() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new SubscriptionRepositoryImpl(db);
|
||||
|
||||
var subscription = db.create_subscription(
|
||||
id: "test-sub-2",
|
||||
url: "https://example.com/feed.xml",
|
||||
title: "Test Subscription"
|
||||
);
|
||||
|
||||
var result = repo.get_subscription_by_url("https://example.com/feed.xml");
|
||||
|
||||
assert(result != null);
|
||||
assert(result.url == "https://example.com/feed.xml");
|
||||
|
||||
print("PASS: test_subscription_repository_get_by_url\n");
|
||||
}
|
||||
|
||||
public void test_subscription_repository_insert() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new SubscriptionRepositoryImpl(db);
|
||||
|
||||
var subscription = FeedSubscription.new(
|
||||
id: "test-sub-3",
|
||||
url: "https://example.com/feed.xml",
|
||||
title: "New Subscription",
|
||||
enabled: true
|
||||
);
|
||||
|
||||
var result = repo.insert_subscription(subscription);
|
||||
|
||||
assert(result.is_error() == false);
|
||||
|
||||
var retrieved = repo.get_subscription_by_id("test-sub-3");
|
||||
assert(retrieved != null);
|
||||
assert(retrieved.id == "test-sub-3");
|
||||
|
||||
print("PASS: test_subscription_repository_insert\n");
|
||||
}
|
||||
|
||||
public void test_subscription_repository_update() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new SubscriptionRepositoryImpl(db);
|
||||
|
||||
var subscription = db.create_subscription(
|
||||
id: "test-sub-4",
|
||||
url: "https://example.com/feed.xml",
|
||||
title: "Original Title"
|
||||
);
|
||||
|
||||
subscription.title = "Updated Title";
|
||||
|
||||
var result = repo.update_subscription(subscription);
|
||||
|
||||
assert(result.is_error() == false);
|
||||
|
||||
var updated = repo.get_subscription_by_id("test-sub-4");
|
||||
assert(updated != null);
|
||||
assert(updated.title == "Updated Title");
|
||||
|
||||
print("PASS: test_subscription_repository_update\n");
|
||||
}
|
||||
|
||||
public void test_subscription_repository_delete() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new SubscriptionRepositoryImpl(db);
|
||||
|
||||
var subscription = db.create_subscription(
|
||||
id: "test-sub-5",
|
||||
url: "https://example.com/feed.xml",
|
||||
title: "Delete Subscription"
|
||||
);
|
||||
|
||||
var result = repo.delete_subscription("test-sub-5");
|
||||
|
||||
assert(result.is_error() == false);
|
||||
|
||||
var deleted = repo.get_subscription_by_id("test-sub-5");
|
||||
assert(deleted == null);
|
||||
|
||||
print("PASS: test_subscription_repository_delete\n");
|
||||
}
|
||||
|
||||
public void test_subscription_repository_set_enabled() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new SubscriptionRepositoryImpl(db);
|
||||
|
||||
var subscription = db.create_subscription(
|
||||
id: "test-sub-6",
|
||||
url: "https://example.com/feed.xml",
|
||||
title: "Toggle Subscription"
|
||||
);
|
||||
|
||||
var result = repo.set_enabled("test-sub-6", false);
|
||||
|
||||
assert(result.is_error() == false);
|
||||
|
||||
var updated = repo.get_subscription_by_id("test-sub-6");
|
||||
assert(updated != null);
|
||||
assert(updated.enabled == false);
|
||||
|
||||
print("PASS: test_subscription_repository_set_enabled\n");
|
||||
}
|
||||
|
||||
public void test_subscription_repository_set_error() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new SubscriptionRepositoryImpl(db);
|
||||
|
||||
var subscription = db.create_subscription(
|
||||
id: "test-sub-7",
|
||||
url: "https://example.com/feed.xml",
|
||||
title: "Error Subscription"
|
||||
);
|
||||
|
||||
var result = repo.set_error("test-sub-7", "Connection failed");
|
||||
|
||||
assert(result.is_error() == false);
|
||||
|
||||
print("PASS: test_subscription_repository_set_error\n");
|
||||
}
|
||||
|
||||
public void test_subscription_repository_update_timestamps() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new SubscriptionRepositoryImpl(db);
|
||||
|
||||
var subscription = db.create_subscription(
|
||||
id: "test-sub-8",
|
||||
url: "https://example.com/feed.xml",
|
||||
title: "Timestamp Test"
|
||||
);
|
||||
|
||||
var last_fetched = Time.now().unix_timestamp;
|
||||
var next_fetch = Time.now().unix_timestamp + 3600;
|
||||
|
||||
var result = repo.update_last_fetched_at("test-sub-8", last_fetched);
|
||||
var result2 = repo.update_next_fetch_at("test-sub-8", next_fetch);
|
||||
|
||||
assert(result.is_error() == false);
|
||||
assert(result2.is_error() == false);
|
||||
|
||||
print("PASS: test_subscription_repository_update_timestamps\n");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user