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:
@@ -21,7 +21,7 @@ namespace RSSuper {
|
||||
var feedItems = db.getFeedItems(subscription_id);
|
||||
callback.set_success(feedItems);
|
||||
} catch (Error e) {
|
||||
callback.set_error("Failed to get feed items", e);
|
||||
callback.set_error("Failed to get feed items", new ErrorDetails(ErrorType.NETWORK, e.message, true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace RSSuper {
|
||||
var subscriptions = db.getAllSubscriptions();
|
||||
callback.set_success(subscriptions);
|
||||
} catch (Error e) {
|
||||
callback.set_error("Failed to get subscriptions", e);
|
||||
callback.set_error("Failed to get subscriptions", new ErrorDetails(ErrorType.DATABASE, e.message, true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace RSSuper {
|
||||
var subscriptions = db.getEnabledSubscriptions();
|
||||
callback.set_success(subscriptions);
|
||||
} catch (Error e) {
|
||||
callback.set_error("Failed to get enabled subscriptions", e);
|
||||
callback.set_error("Failed to get enabled subscriptions", new ErrorDetails(ErrorType.DATABASE, e.message, true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace RSSuper {
|
||||
var subscriptions = db.getSubscriptionsByCategory(category);
|
||||
callback.set_success(subscriptions);
|
||||
} catch (Error e) {
|
||||
callback.set_error("Failed to get subscriptions by category", e);
|
||||
callback.set_error("Failed to get subscriptions by category", new ErrorDetails(ErrorType.DATABASE, e.message, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
111
linux/src/tests/error-tests.vala
Normal file
111
linux/src/tests/error-tests.vala
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* ErrorTests.vala
|
||||
*
|
||||
* Unit tests for error types and error handling.
|
||||
*/
|
||||
|
||||
using Gio = Org.Gnome.Valetta.Gio;
|
||||
|
||||
public class RSSuper.ErrorTests {
|
||||
|
||||
public static int main(string[] args) {
|
||||
var tests = new ErrorTests();
|
||||
|
||||
tests.test_error_type_enum();
|
||||
tests.test_error_details_creation();
|
||||
tests.test_error_details_properties();
|
||||
tests.test_error_details_comparison();
|
||||
|
||||
print("All error tests passed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void test_error_type_enum() {
|
||||
assert(ErrorType.NETWORK == ErrorType.NETWORK);
|
||||
assert(ErrorType.DATABASE == ErrorType.DATABASE);
|
||||
assert(ErrorType.PARSING == ErrorType.PARSING);
|
||||
assert(ErrorType.AUTH == ErrorType.AUTH);
|
||||
assert(ErrorType.UNKNOWN == ErrorType.UNKNOWN);
|
||||
|
||||
print("PASS: test_error_type_enum\n");
|
||||
}
|
||||
|
||||
public void test_error_details_creation() {
|
||||
// Test default constructor
|
||||
var error1 = new ErrorDetails(ErrorType.NETWORK, "Connection failed", true);
|
||||
assert(error1.type == ErrorType.NETWORK);
|
||||
assert(error1.message == "Connection failed");
|
||||
assert(error1.retryable == true);
|
||||
|
||||
// Test with retryable=false
|
||||
var error2 = new ErrorDetails(ErrorType.DATABASE, "Table locked", false);
|
||||
assert(error2.type == ErrorType.DATABASE);
|
||||
assert(error2.message == "Table locked");
|
||||
assert(error2.retryable == false);
|
||||
|
||||
// Test with null message
|
||||
var error3 = new ErrorDetails(ErrorType.PARSING, null, true);
|
||||
assert(error3.type == ErrorType.PARSING);
|
||||
assert(error3.message == null);
|
||||
assert(error3.retryable == true);
|
||||
|
||||
print("PASS: test_error_details_creation\n");
|
||||
}
|
||||
|
||||
public void test_error_details_properties() {
|
||||
var error = new ErrorDetails(ErrorType.DATABASE, "Query timeout", true);
|
||||
|
||||
// Test property getters
|
||||
assert(error.type == ErrorType.DATABASE);
|
||||
assert(error.message == "Query timeout");
|
||||
assert(error.retryable == true);
|
||||
|
||||
// Test property setters
|
||||
error.type = ErrorType.PARSING;
|
||||
error.message = "Syntax error";
|
||||
error.retryable = false;
|
||||
|
||||
assert(error.type == ErrorType.PARSING);
|
||||
assert(error.message == "Syntax error");
|
||||
assert(error.retryable == false);
|
||||
|
||||
print("PASS: test_error_details_properties\n");
|
||||
}
|
||||
|
||||
public void test_error_details_comparison() {
|
||||
var error1 = new ErrorDetails(ErrorType.NETWORK, "Timeout", true);
|
||||
var error2 = new ErrorDetails(ErrorType.NETWORK, "Timeout", true);
|
||||
var error3 = new ErrorDetails(ErrorType.DATABASE, "Timeout", true);
|
||||
|
||||
// Same type, message, retryable - equal
|
||||
assert(error1.type == error2.type);
|
||||
assert(error1.message == error2.message);
|
||||
assert(error1.retryable == error2.retryable);
|
||||
|
||||
// Different type - not equal
|
||||
assert(error1.type != error3.type);
|
||||
|
||||
// Different retryable - not equal
|
||||
var error4 = new ErrorDetails(ErrorType.NETWORK, "Timeout", false);
|
||||
assert(error1.retryable != error4.retryable);
|
||||
|
||||
print("PASS: test_error_details_comparison\n");
|
||||
}
|
||||
|
||||
public void test_error_from_gio_error() {
|
||||
// Simulate Gio.Error
|
||||
var error = new Gio.Error();
|
||||
error.set_code(Gio.Error.Code.NOT_FOUND);
|
||||
error.set_domain("gio");
|
||||
error.set_message("File not found");
|
||||
|
||||
// Convert to ErrorDetails
|
||||
var details = new ErrorDetails(ErrorType.DATABASE, error.message, true);
|
||||
|
||||
assert(details.type == ErrorType.DATABASE);
|
||||
assert(details.message == "File not found");
|
||||
assert(details.retryable == true);
|
||||
|
||||
print("PASS: test_error_from_gio_error\n");
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
185
linux/src/tests/state-tests.vala
Normal file
185
linux/src/tests/state-tests.vala
Normal file
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* StateTests.vala
|
||||
*
|
||||
* Unit tests for state management types.
|
||||
*/
|
||||
|
||||
using Gio = Org.Gnome.Valetta.Gio;
|
||||
|
||||
public class RSSuper.StateTests {
|
||||
|
||||
public static int main(string[] args) {
|
||||
var tests = new StateTests();
|
||||
|
||||
tests.test_state_enum_values();
|
||||
tests.test_state_class_initialization();
|
||||
tests.test_state_setters();
|
||||
tests.test_state_getters();
|
||||
tests.test_state_comparison();
|
||||
tests.test_state_signal_emission();
|
||||
|
||||
print("All state tests passed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void test_state_enum_values() {
|
||||
assert(State.IDLE == State.IDLE);
|
||||
assert(State.LOADING == State.LOADING);
|
||||
assert(State.SUCCESS == State.SUCCESS);
|
||||
assert(State.ERROR == State.ERROR);
|
||||
|
||||
print("PASS: test_state_enum_values\n");
|
||||
}
|
||||
|
||||
public void test_state_class_initialization() {
|
||||
var state = new State<string>();
|
||||
|
||||
assert(state.get_state() == State.IDLE);
|
||||
assert(state.is_idle());
|
||||
assert(!state.is_loading());
|
||||
assert(!state.is_success());
|
||||
assert(!state.is_error());
|
||||
|
||||
print("PASS: test_state_class_initialization\n");
|
||||
}
|
||||
|
||||
public void test_state_setters() {
|
||||
var state = new State<string>();
|
||||
|
||||
// Test set_idle
|
||||
state.set_idle();
|
||||
assert(state.get_state() == State.IDLE);
|
||||
assert(state.is_idle());
|
||||
|
||||
// Test set_loading
|
||||
state.set_loading();
|
||||
assert(state.get_state() == State.LOADING);
|
||||
assert(state.is_loading());
|
||||
|
||||
// Test set_success
|
||||
string data = "test data";
|
||||
state.set_success(data);
|
||||
assert(state.get_state() == State.SUCCESS);
|
||||
assert(state.is_success());
|
||||
assert(state.get_data() == data);
|
||||
|
||||
// Test set_error
|
||||
state.set_error("test error");
|
||||
assert(state.get_state() == State.ERROR);
|
||||
assert(state.is_error());
|
||||
assert(state.get_message() == "test error");
|
||||
|
||||
print("PASS: test_state_setters\n");
|
||||
}
|
||||
|
||||
public void test_state_getters() {
|
||||
var state = new State<int>();
|
||||
|
||||
// Test initial values
|
||||
assert(state.get_state() == State.IDLE);
|
||||
assert(state.get_data() == null);
|
||||
assert(state.get_message() == null);
|
||||
assert(state.get_error() == null);
|
||||
|
||||
// Test after set_success
|
||||
state.set_success(42);
|
||||
assert(state.get_state() == State.SUCCESS);
|
||||
assert(state.get_data() == 42);
|
||||
assert(state.get_message() == null);
|
||||
assert(state.get_error() == null);
|
||||
|
||||
// Test after set_error
|
||||
state.set_error("database error");
|
||||
assert(state.get_state() == State.ERROR);
|
||||
assert(state.get_data() == null);
|
||||
assert(state.get_message() == "database error");
|
||||
assert(state.get_error() != null);
|
||||
|
||||
print("PASS: test_state_getters\n");
|
||||
}
|
||||
|
||||
public void test_state_comparison() {
|
||||
var state1 = new State<string>();
|
||||
var state2 = new State<string>();
|
||||
|
||||
// Initially equal
|
||||
assert(state1.get_state() == state2.get_state());
|
||||
|
||||
// After different states, not equal
|
||||
state1.set_success("value1");
|
||||
state2.set_error("error");
|
||||
assert(state1.get_state() != state2.get_state());
|
||||
|
||||
// Same state, different data
|
||||
var state3 = new State<string>();
|
||||
state3.set_success("value2");
|
||||
assert(state3.get_state() == state1.get_state());
|
||||
assert(state3.get_data() != state1.get_data());
|
||||
|
||||
print("PASS: test_state_comparison\n");
|
||||
}
|
||||
|
||||
public void test_state_signal_emission() {
|
||||
var state = new State<string>();
|
||||
|
||||
// Track signal emissions
|
||||
int state_changed_count = 0;
|
||||
int data_changed_count = 0;
|
||||
|
||||
state.connect_signal("state_changed", (sender, signal) => {
|
||||
state_changed_count++;
|
||||
});
|
||||
|
||||
state.connect_signal("data_changed", (sender, signal) => {
|
||||
data_changed_count++;
|
||||
});
|
||||
|
||||
// Initial state - no signals
|
||||
assert(state_changed_count == 0);
|
||||
assert(data_changed_count == 0);
|
||||
|
||||
// set_loading emits state_changed
|
||||
state.set_loading();
|
||||
assert(state_changed_count == 1);
|
||||
assert(data_changed_count == 0);
|
||||
|
||||
// set_success emits both signals
|
||||
state.set_success("test");
|
||||
assert(state_changed_count == 2);
|
||||
assert(data_changed_count == 1);
|
||||
|
||||
// set_error emits state_changed only
|
||||
state.set_error("error");
|
||||
assert(state_changed_count == 3);
|
||||
assert(data_changed_count == 1);
|
||||
|
||||
print("PASS: test_state_signal_emission\n");
|
||||
}
|
||||
|
||||
public void test_generic_state_t() {
|
||||
// Test State<int>
|
||||
var intState = new State<int>();
|
||||
intState.set_success(123);
|
||||
assert(intState.get_data() == 123);
|
||||
assert(intState.is_success());
|
||||
|
||||
// Test State<bool>
|
||||
var boolState = new State<bool>();
|
||||
boolState.set_success(true);
|
||||
assert(boolState.get_data() == true);
|
||||
assert(boolState.is_success());
|
||||
|
||||
// Test State<string>
|
||||
var stringState = new State<string>();
|
||||
stringState.set_success("hello");
|
||||
assert(stringState.get_data() == "hello");
|
||||
assert(stringState.is_success());
|
||||
|
||||
// Test State<object>
|
||||
var objectState = new State<object>();
|
||||
objectState.set_success("test");
|
||||
assert(objectState.get_data() == "test");
|
||||
|
||||
print("PASS: test_generic_state_t\n");
|
||||
}
|
||||
}
|
||||
@@ -1,123 +1,242 @@
|
||||
/*
|
||||
* ViewModelTests.vala
|
||||
*
|
||||
* Unit tests for view models.
|
||||
* Unit tests for feed and subscription view models.
|
||||
*/
|
||||
|
||||
using Gio = Org.Gnome.Valetta.Gio;
|
||||
|
||||
public class RSSuper.ViewModelTests {
|
||||
|
||||
public static int main(string[] args) {
|
||||
var tests = new ViewModelTests();
|
||||
|
||||
tests.test_feed_view_model_state();
|
||||
tests.test_feed_view_model_initialization();
|
||||
tests.test_feed_view_model_loading();
|
||||
tests.test_feed_view_model_success();
|
||||
tests.test_feed_view_model_error();
|
||||
tests.test_subscription_view_model_state();
|
||||
tests.test_feed_view_model_mark_as_read();
|
||||
tests.test_feed_view_model_mark_as_starred();
|
||||
tests.test_feed_view_model_refresh();
|
||||
|
||||
tests.test_subscription_view_model_initialization();
|
||||
tests.test_subscription_view_model_loading();
|
||||
tests.test_subscription_view_model_set_enabled();
|
||||
tests.test_subscription_view_model_set_error();
|
||||
tests.test_subscription_view_model_update_timestamps();
|
||||
tests.test_subscription_view_model_refresh();
|
||||
|
||||
print("All view model tests passed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void test_feed_view_model_state() {
|
||||
// Create a test database
|
||||
public void test_feed_view_model_initialization() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new FeedRepositoryImpl(db);
|
||||
var model = new FeedViewModel(repo);
|
||||
|
||||
// Create feed view model
|
||||
var model = new FeedViewModel(db);
|
||||
assert(model.feedState.get_state() == State.IDLE);
|
||||
assert(model.unreadCountState.get_state() == State.IDLE);
|
||||
|
||||
// Test initial state
|
||||
assert(model.feed_state == FeedState.idle);
|
||||
|
||||
print("PASS: test_feed_view_model_state\n");
|
||||
print("PASS: test_feed_view_model_initialization\n");
|
||||
}
|
||||
|
||||
public void test_feed_view_model_loading() {
|
||||
// Create a test database
|
||||
var db = new Database(":memory:");
|
||||
var repo = new FeedRepositoryImpl(db);
|
||||
var model = new FeedViewModel(repo);
|
||||
|
||||
// Create feed view model
|
||||
var model = new FeedViewModel(db);
|
||||
model.load_feed_items("test-subscription");
|
||||
|
||||
// Test loading state
|
||||
model.load_feed_items("test-subscription-id");
|
||||
|
||||
assert(model.feed_state is FeedState.loading);
|
||||
assert(model.feedState.is_loading() == true);
|
||||
assert(model.feedState.is_success() == false);
|
||||
assert(model.feedState.is_error() == false);
|
||||
|
||||
print("PASS: test_feed_view_model_loading\n");
|
||||
}
|
||||
|
||||
public void test_feed_view_model_success() {
|
||||
// Create a test database
|
||||
var db = new Database(":memory:");
|
||||
var repo = new FeedRepositoryImpl(db);
|
||||
var model = new FeedViewModel(repo);
|
||||
|
||||
// Create subscription
|
||||
db.create_subscription(
|
||||
id: "test-sub",
|
||||
url: "https://example.com/feed.xml",
|
||||
title: "Test Feed"
|
||||
);
|
||||
// Mock success state
|
||||
var items = db.getFeedItems("test-subscription");
|
||||
model.feedState.set_success(items);
|
||||
|
||||
// Create feed view model
|
||||
var model = new FeedViewModel(db);
|
||||
|
||||
// Test success state (mocked for unit test)
|
||||
// In a real test, we would mock the database or use a test database
|
||||
var items = new FeedItem[0];
|
||||
model.feed_state = FeedState.success(items);
|
||||
|
||||
assert(model.feed_state is FeedState.success);
|
||||
|
||||
var success_state = (FeedState.success) model.feed_state;
|
||||
assert(success_state.items.length == 0);
|
||||
assert(model.feedState.is_success() == true);
|
||||
assert(model.feedState.get_data().length > 0);
|
||||
|
||||
print("PASS: test_feed_view_model_success\n");
|
||||
}
|
||||
|
||||
public void test_feed_view_model_error() {
|
||||
// Create a test database
|
||||
var db = new Database(":memory:");
|
||||
var repo = new FeedRepositoryImpl(db);
|
||||
var model = new FeedViewModel(repo);
|
||||
|
||||
// Create feed view model
|
||||
var model = new FeedViewModel(db);
|
||||
// Mock error state
|
||||
model.feedState.set_error("Connection failed");
|
||||
|
||||
// Test error state
|
||||
model.feed_state = FeedState.error("Test error");
|
||||
|
||||
assert(model.feed_state is FeedState.error);
|
||||
|
||||
var error_state = (FeedState.error) model.feed_state;
|
||||
assert(error_state.message == "Test error");
|
||||
assert(model.feedState.is_error() == true);
|
||||
assert(model.feedState.get_message() == "Connection failed");
|
||||
|
||||
print("PASS: test_feed_view_model_error\n");
|
||||
}
|
||||
|
||||
public void test_subscription_view_model_state() {
|
||||
// Create a test database
|
||||
public void test_feed_view_model_mark_as_read() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new FeedRepositoryImpl(db);
|
||||
var model = new FeedViewModel(repo);
|
||||
|
||||
// Create subscription view model
|
||||
var model = new SubscriptionViewModel(db);
|
||||
model.mark_as_read("test-item-1", true);
|
||||
|
||||
// Test initial state
|
||||
assert(model.subscription_state is SubscriptionState.idle);
|
||||
assert(model.unreadCountState.is_loading() == true);
|
||||
|
||||
print("PASS: test_subscription_view_model_state\n");
|
||||
print("PASS: test_feed_view_model_mark_as_read\n");
|
||||
}
|
||||
|
||||
public void test_feed_view_model_mark_as_starred() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new FeedRepositoryImpl(db);
|
||||
var model = new FeedViewModel(repo);
|
||||
|
||||
model.mark_as_starred("test-item-2", true);
|
||||
|
||||
assert(model.feedState.is_loading() == true);
|
||||
|
||||
print("PASS: test_feed_view_model_mark_as_starred\n");
|
||||
}
|
||||
|
||||
public void test_feed_view_model_refresh() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new FeedRepositoryImpl(db);
|
||||
var model = new FeedViewModel(repo);
|
||||
|
||||
model.refresh("test-subscription");
|
||||
|
||||
assert(model.feedState.is_loading() == true);
|
||||
assert(model.unreadCountState.is_loading() == true);
|
||||
|
||||
print("PASS: test_feed_view_model_refresh\n");
|
||||
}
|
||||
|
||||
public void test_subscription_view_model_initialization() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new SubscriptionRepositoryImpl(db);
|
||||
var model = new SubscriptionViewModel(repo);
|
||||
|
||||
assert(model.subscriptionsState.get_state() == State.IDLE);
|
||||
assert(model.enabledSubscriptionsState.get_state() == State.IDLE);
|
||||
|
||||
print("PASS: test_subscription_view_model_initialization\n");
|
||||
}
|
||||
|
||||
public void test_subscription_view_model_loading() {
|
||||
// Create a test database
|
||||
var db = new Database(":memory:");
|
||||
var repo = new SubscriptionRepositoryImpl(db);
|
||||
var model = new SubscriptionViewModel(repo);
|
||||
|
||||
// Create subscription view model
|
||||
var model = new SubscriptionViewModel(db);
|
||||
model.load_all_subscriptions();
|
||||
|
||||
// Test loading state
|
||||
model.load_subscriptions();
|
||||
|
||||
assert(model.subscription_state is SubscriptionState.loading);
|
||||
assert(model.subscriptionsState.is_loading() == true);
|
||||
assert(model.subscriptionsState.is_success() == false);
|
||||
assert(model.subscriptionsState.is_error() == false);
|
||||
|
||||
print("PASS: test_subscription_view_model_loading\n");
|
||||
}
|
||||
|
||||
public void test_subscription_view_model_set_enabled() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new SubscriptionRepositoryImpl(db);
|
||||
var model = new SubscriptionViewModel(repo);
|
||||
|
||||
model.set_enabled("test-sub-1", false);
|
||||
|
||||
assert(model.enabledSubscriptionsState.is_loading() == true);
|
||||
|
||||
print("PASS: test_subscription_view_model_set_enabled\n");
|
||||
}
|
||||
|
||||
public void test_subscription_view_model_set_error() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new SubscriptionRepositoryImpl(db);
|
||||
var model = new SubscriptionViewModel(repo);
|
||||
|
||||
model.set_error("test-sub-2", "Connection failed");
|
||||
|
||||
assert(model.subscriptionsState.is_error() == true);
|
||||
assert(model.subscriptionsState.get_message() == "Connection failed");
|
||||
|
||||
print("PASS: test_subscription_view_model_set_error\n");
|
||||
}
|
||||
|
||||
public void test_subscription_view_model_update_timestamps() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new SubscriptionRepositoryImpl(db);
|
||||
var model = new SubscriptionViewModel(repo);
|
||||
|
||||
var last_fetched = Time.now().unix_timestamp;
|
||||
var next_fetch = Time.now().unix_timestamp + 3600;
|
||||
|
||||
model.update_last_fetched_at("test-sub-3", last_fetched);
|
||||
model.update_next_fetch_at("test-sub-3", next_fetch);
|
||||
|
||||
assert(model.subscriptionsState.is_loading() == true);
|
||||
|
||||
print("PASS: test_subscription_view_model_update_timestamps\n");
|
||||
}
|
||||
|
||||
public void test_subscription_view_model_refresh() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new SubscriptionRepositoryImpl(db);
|
||||
var model = new SubscriptionViewModel(repo);
|
||||
|
||||
model.refresh();
|
||||
|
||||
assert(model.subscriptionsState.is_loading() == true);
|
||||
assert(model.enabledSubscriptionsState.is_loading() == true);
|
||||
|
||||
print("PASS: test_subscription_view_model_refresh\n");
|
||||
}
|
||||
|
||||
public void test_feed_view_model_signal_propagation() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new FeedRepositoryImpl(db);
|
||||
var model = new FeedViewModel(repo);
|
||||
|
||||
// Track signal emissions
|
||||
int stateChangedCount = 0;
|
||||
model.feedState.connect_signal("state_changed", (sender, signal) => {
|
||||
stateChangedCount++;
|
||||
});
|
||||
|
||||
// Load items - should emit state_changed
|
||||
model.load_feed_items("test-sub");
|
||||
|
||||
// Verify signal was emitted during loading
|
||||
assert(stateChangedCount >= 1);
|
||||
|
||||
print("PASS: test_feed_view_model_signal_propagation\n");
|
||||
}
|
||||
|
||||
public void test_subscription_view_model_signal_propagation() {
|
||||
var db = new Database(":memory:");
|
||||
var repo = new SubscriptionRepositoryImpl(db);
|
||||
var model = new SubscriptionViewModel(repo);
|
||||
|
||||
// Track signal emissions
|
||||
int stateChangedCount = 0;
|
||||
model.subscriptionsState.connect_signal("state_changed", (sender, signal) => {
|
||||
stateChangedCount++;
|
||||
});
|
||||
|
||||
// Load subscriptions - should emit state_changed
|
||||
model.load_all_subscriptions();
|
||||
|
||||
// Verify signal was emitted during loading
|
||||
assert(stateChangedCount >= 1);
|
||||
|
||||
print("PASS: test_subscription_view_model_signal_propagation\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace RSSuper {
|
||||
public void load_feed_items(string? subscription_id = null) {
|
||||
feedState.set_loading();
|
||||
repository.get_feed_items(subscription_id, (state) => {
|
||||
feedState = state;
|
||||
feedState.set_success(state.get_data());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace RSSuper {
|
||||
var count = repository.get_unread_count(subscription_id);
|
||||
unreadCountState.set_success(count);
|
||||
} catch (Error e) {
|
||||
unreadCountState.set_error("Failed to load unread count", e);
|
||||
unreadCountState.set_error("Failed to load unread count", new ErrorDetails(ErrorType.DATABASE, e.message, true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace RSSuper {
|
||||
repository.mark_as_read(id, is_read);
|
||||
load_unread_count();
|
||||
} catch (Error e) {
|
||||
unreadCountState.set_error("Failed to update read state", e);
|
||||
unreadCountState.set_error("Failed to update read state", new ErrorDetails(ErrorType.DATABASE, e.message, true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace RSSuper {
|
||||
try {
|
||||
repository.mark_as_starred(id, is_starred);
|
||||
} catch (Error e) {
|
||||
feedState.set_error("Failed to update starred state", e);
|
||||
feedState.set_error("Failed to update starred state", new ErrorDetails(ErrorType.DATABASE, e.message, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,14 +31,14 @@ namespace RSSuper {
|
||||
public void load_all_subscriptions() {
|
||||
subscriptionsState.set_loading();
|
||||
repository.get_all_subscriptions((state) => {
|
||||
subscriptionsState = state;
|
||||
subscriptionsState.set_success(state.get_data());
|
||||
});
|
||||
}
|
||||
|
||||
public void load_enabled_subscriptions() {
|
||||
enabledSubscriptionsState.set_loading();
|
||||
repository.get_enabled_subscriptions((state) => {
|
||||
enabledSubscriptionsState = state;
|
||||
enabledSubscriptionsState.set_success(state.get_data());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace RSSuper {
|
||||
repository.set_enabled(id, enabled);
|
||||
load_enabled_subscriptions();
|
||||
} catch (Error e) {
|
||||
enabledSubscriptionsState.set_error("Failed to update subscription enabled state", e);
|
||||
enabledSubscriptionsState.set_error("Failed to update subscription enabled state", new ErrorDetails(ErrorType.DATABASE, e.message, true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace RSSuper {
|
||||
try {
|
||||
repository.set_error(id, error);
|
||||
} catch (Error e) {
|
||||
subscriptionsState.set_error("Failed to set subscription error", e);
|
||||
subscriptionsState.set_error("Failed to set subscription error", new ErrorDetails(ErrorType.DATABASE, e.message, true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace RSSuper {
|
||||
try {
|
||||
repository.update_last_fetched_at(id, last_fetched_at);
|
||||
} catch (Error e) {
|
||||
subscriptionsState.set_error("Failed to update last fetched time", e);
|
||||
subscriptionsState.set_error("Failed to update last fetched time", new ErrorDetails(ErrorType.DATABASE, e.message, true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace RSSuper {
|
||||
try {
|
||||
repository.update_next_fetch_at(id, next_fetch_at);
|
||||
} catch (Error e) {
|
||||
subscriptionsState.set_error("Failed to update next fetch time", e);
|
||||
subscriptionsState.set_error("Failed to update next fetch time", new ErrorDetails(ErrorType.DATABASE, e.message, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user