mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-31 07:01:17 +01:00
feat(session): query enabled sources before providers (#85)
UserSessionManager now queries the user_sources table for enabled sources before calling any provider. Providers receive the per-user JSON config directly instead of querying the DB themselves, removing their db dependency and eliminating redundant round-trips. Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { ActionDefinition, ContextEntry, FeedItem, FeedSource } from "@aelis/core"
|
||||
|
||||
import { describe, expect, mock, test } from "bun:test"
|
||||
import { Hono } from "hono"
|
||||
import { describe, expect, test } from "bun:test"
|
||||
|
||||
import type { AdminMiddleware } from "../auth/admin-middleware.ts"
|
||||
import type { AuthSession, AuthUser } from "../auth/session.ts"
|
||||
@@ -11,6 +11,39 @@ import type { FeedSourceProvider } from "../session/feed-source-provider.ts"
|
||||
import { UserSessionManager } from "../session/user-session-manager.ts"
|
||||
import { registerAdminHttpHandlers } from "./http.ts"
|
||||
|
||||
let mockEnabledSourceIds: string[] = []
|
||||
|
||||
mock.module("../sources/user-sources.ts", () => ({
|
||||
sources: (_db: Database, _userId: string) => ({
|
||||
async enabled() {
|
||||
const now = new Date()
|
||||
return mockEnabledSourceIds.map((sourceId) => ({
|
||||
id: crypto.randomUUID(),
|
||||
userId: _userId,
|
||||
sourceId,
|
||||
enabled: true,
|
||||
config: {},
|
||||
credentials: null,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
}))
|
||||
},
|
||||
async find(sourceId: string) {
|
||||
const now = new Date()
|
||||
return {
|
||||
id: crypto.randomUUID(),
|
||||
userId: _userId,
|
||||
sourceId,
|
||||
enabled: true,
|
||||
config: {},
|
||||
credentials: null,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
}
|
||||
},
|
||||
}),
|
||||
}))
|
||||
|
||||
function createStubSource(id: string): FeedSource {
|
||||
return {
|
||||
id,
|
||||
@@ -63,7 +96,8 @@ function passthroughAdminMiddleware(): AdminMiddleware {
|
||||
const fakeDb = {} as Database
|
||||
|
||||
function createApp(providers: FeedSourceProvider[]) {
|
||||
const sessionManager = new UserSessionManager({ providers })
|
||||
mockEnabledSourceIds = providers.map((p) => p.sourceId)
|
||||
const sessionManager = new UserSessionManager({ db: fakeDb, providers })
|
||||
const app = new Hono()
|
||||
registerAdminHttpHandlers(app, {
|
||||
sessionManager,
|
||||
@@ -158,5 +192,4 @@ describe("PUT /api/admin/:sourceId/config", () => {
|
||||
expect(provider!.sourceId).toBe("aelis.weather")
|
||||
expect(provider).not.toBe(originalProvider)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user