From aae137baf88280749bd4615abcbb5e6327d9f50f Mon Sep 17 00:00:00 2001 From: Andrey Sitnik Date: Fri, 2 Feb 2024 12:58:29 +0100 Subject: [PATCH] Add loadPost() for tests and clean up code --- core/category.ts | 4 ++-- core/feed.ts | 2 +- core/post.ts | 8 ++++++-- core/test/post.test.ts | 4 +++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/core/category.ts b/core/category.ts index dfa96d96..4b18d231 100644 --- a/core/category.ts +++ b/core/category.ts @@ -51,9 +51,9 @@ export async function deleteCategory(categoryId: string): Promise { } export async function loadCategory( - feedId: string + categoryId: string ): Promise { - return loadValue(Category(feedId)) + return loadValue(Category(categoryId, getClient())) } export const GENERAL_CATEGORY: CategoryValue = { diff --git a/core/feed.ts b/core/feed.ts index 93b35cc0..1efff2bc 100644 --- a/core/feed.ts +++ b/core/feed.ts @@ -93,7 +93,7 @@ export function getFeed(feedId: string): SyncMapStore { } export async function loadFeed(feedId: string): Promise { - return loadValue(getFeed(feedId)) + return loadValue(Feed(feedId, getClient())) } export async function changeFeed( diff --git a/core/post.ts b/core/post.ts index 66bfb208..7765531a 100644 --- a/core/post.ts +++ b/core/post.ts @@ -54,8 +54,12 @@ export async function loadPosts( return value.list } -export function getPost(feedId: string): SyncMapStore { - return Post(feedId, getClient()) +export function getPost(postId: string): SyncMapStore { + return Post(postId, getClient()) +} + +export async function loadPost(postId: string): Promise { + return loadValue(Post(postId, getClient())) } export function deletePost(postId: string): Promise { diff --git a/core/test/post.test.ts b/core/test/post.test.ts index fc07bb81..484b2e13 100644 --- a/core/test/post.test.ts +++ b/core/test/post.test.ts @@ -2,7 +2,7 @@ import { keepMount } from 'nanostores' import { deepStrictEqual, equal } from 'node:assert' import { afterEach, beforeEach, test } from 'node:test' -import { addPost, deletePost, getPost, loadPosts } from '../index.js' +import { addPost, deletePost, getPost, loadPost, loadPosts } from '../index.js' import { cleanClientTest, enableClientTest } from './utils.js' beforeEach(() => { @@ -28,6 +28,8 @@ test('adds, loads and removes posts', async () => { equal(added.length, 1) equal(added[0]!.reading, 'fast') + deepStrictEqual(await loadPost(id), added[0]) + let post = getPost(id) keepMount(post) equal(post.get(), added[0])