@@ -40,7 +40,7 @@ test("GET /health is open without a token; every other route 401s", async () =>
4040 assert . equal ( health . status , 200 ) ;
4141 assert . deepEqual ( await health . json ( ) , { ok : true } ) ;
4242
43- for ( const path of [ "/status" , "/memories" , "/memories/x" , "/search?q=x" ] ) {
43+ for ( const path of [ "/status" , "/profile" , "/rules" , "/ memories", "/memories/x" , "/search?q=x" ] ) {
4444 const res = await fetch ( `${ base } ${ path } ` ) ;
4545 assert . equal ( res . status , 401 , `${ path } requires a token` ) ;
4646 assert . deepEqual ( await res . json ( ) , { error : "unauthorized" } ) ;
@@ -53,6 +53,39 @@ test("GET /health is open without a token; every other route 401s", async () =>
5353 }
5454} ) ;
5555
56+ test ( "GET /profile and /rules return saved settings" , async ( ) => {
57+ const { base, auth, settings, close } = await setup ( ) ;
58+ try {
59+ settings . setProfile ( "我是后端工程师" ) ;
60+ settings . setRules ( [ "先验证再修改" , "默认使用中文回复" ] ) ;
61+
62+ const profile = await fetch ( `${ base } /profile` , { headers : auth } ) ;
63+ assert . equal ( profile . status , 200 ) ;
64+ assert . deepEqual ( await profile . json ( ) , { profile : "我是后端工程师" } ) ;
65+
66+ const rules = await fetch ( `${ base } /rules` , { headers : auth } ) ;
67+ assert . equal ( rules . status , 200 ) ;
68+ assert . deepEqual ( await rules . json ( ) , { rules : [ "先验证再修改" , "默认使用中文回复" ] } ) ;
69+ } finally {
70+ close ( ) ;
71+ }
72+ } ) ;
73+
74+ test ( "GET /profile and /rules return empty values when unset" , async ( ) => {
75+ const { base, auth, close } = await setup ( ) ;
76+ try {
77+ const profile = await fetch ( `${ base } /profile` , { headers : auth } ) ;
78+ assert . equal ( profile . status , 200 ) ;
79+ assert . deepEqual ( await profile . json ( ) , { profile : "" } ) ;
80+
81+ const rules = await fetch ( `${ base } /rules` , { headers : auth } ) ;
82+ assert . equal ( rules . status , 200 ) ;
83+ assert . deepEqual ( await rules . json ( ) , { rules : [ ] } ) ;
84+ } finally {
85+ close ( ) ;
86+ }
87+ } ) ;
88+
5689test ( "token is persisted into settings kv and reused across restarts" , async ( ) => {
5790 const store = createStore ( ":memory:" ) ;
5891 const service = createService ( { store, mirror : null , config : { } } ) ;
0 commit comments