Skip to content

Commit

Permalink
Add loadPost() for tests and clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Feb 2, 2024
1 parent ec4854c commit aae137b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions core/category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export async function deleteCategory(categoryId: string): Promise<void> {
}

export async function loadCategory(
feedId: string
categoryId: string
): Promise<CategoryValue | undefined> {
return loadValue(Category(feedId))
return loadValue(Category(categoryId, getClient()))
}

export const GENERAL_CATEGORY: CategoryValue = {
Expand Down
2 changes: 1 addition & 1 deletion core/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function getFeed(feedId: string): SyncMapStore<FeedValue> {
}

export async function loadFeed(feedId: string): Promise<FeedValue | undefined> {
return loadValue(getFeed(feedId))
return loadValue(Feed(feedId, getClient()))
}

export async function changeFeed(
Expand Down
8 changes: 6 additions & 2 deletions core/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ export async function loadPosts(
return value.list
}

export function getPost(feedId: string): SyncMapStore<PostValue> {
return Post(feedId, getClient())
export function getPost(postId: string): SyncMapStore<PostValue> {
return Post(postId, getClient())
}

export async function loadPost(postId: string): Promise<PostValue | undefined> {
return loadValue(Post(postId, getClient()))
}

export function deletePost(postId: string): Promise<void> {
Expand Down
4 changes: 3 additions & 1 deletion core/test/post.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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])
Expand Down

0 comments on commit aae137b

Please sign in to comment.