@@ -10,6 +10,8 @@ import { GET, PATCH } from "@/app/api/settings/route";
1010import { POST as POST_TEST } from "@/app/api/settings/test-connection/route" ;
1111import { GET as GET_SYSTEM_INFO } from "@/app/api/settings/system-info/route" ;
1212import { GET as GET_EXPORT } from "@/app/api/export/route" ;
13+ import { GET as GET_OPENROUTER_MODELS } from "@/app/api/settings/openrouter/models/route" ;
14+ import { GET as GET_PROVIDER_MODELS } from "@/app/api/settings/provider-models/route" ;
1315
1416describe ( "/api/settings" , ( ) => {
1517 beforeEach ( ( ) => {
@@ -140,4 +142,75 @@ describe("/api/settings", () => {
140142 const body = await res . text ( ) ;
141143 expect ( body . startsWith ( "[" ) ) . toBe ( true ) ;
142144 } ) ;
145+
146+ it ( "records last_backup_at on a successful export" , async ( ) => {
147+ const res = await GET_EXPORT (
148+ await authedGet ( "http://localhost/api/export?format=json" )
149+ ) ;
150+ expect ( res . status ) . toBe ( 200 ) ;
151+
152+ const db = getDb ( ) ;
153+ const lastBackupAt = settings . get ( db , "last_backup_at" ) ;
154+ expect ( lastBackupAt ) . not . toBeNull ( ) ;
155+ expect ( ( ) => new Date ( lastBackupAt as string ) . toISOString ( ) ) . not . toThrow ( ) ;
156+ } ) ;
157+
158+ describe ( "unauthenticated access" , ( ) => {
159+ it ( "rejects GET /api/settings with 401" , async ( ) => {
160+ const res = await GET ( new Request ( "http://localhost/api/settings" ) ) ;
161+ expect ( res . status ) . toBe ( 401 ) ;
162+ } ) ;
163+
164+ it ( "rejects PATCH /api/settings with 401" , async ( ) => {
165+ const res = await PATCH (
166+ new Request ( "http://localhost/api/settings" , {
167+ method : "PATCH" ,
168+ headers : { "Content-Type" : "application/json" } ,
169+ body : JSON . stringify ( { ai_model : "openai/gpt-4" } ) ,
170+ } )
171+ ) ;
172+ expect ( res . status ) . toBe ( 401 ) ;
173+ } ) ;
174+
175+ it ( "rejects POST /api/settings/test-connection with 401" , async ( ) => {
176+ const res = await POST_TEST (
177+ new Request ( "http://localhost/api/settings/test-connection" , {
178+ method : "POST" ,
179+ headers : { "Content-Type" : "application/json" } ,
180+ body : JSON . stringify ( { provider : "hermes" } ) ,
181+ } )
182+ ) ;
183+ expect ( res . status ) . toBe ( 401 ) ;
184+ } ) ;
185+
186+ it ( "rejects GET /api/settings/system-info with 401" , async ( ) => {
187+ const res = await GET_SYSTEM_INFO (
188+ new Request ( "http://localhost/api/settings/system-info" )
189+ ) ;
190+ expect ( res . status ) . toBe ( 401 ) ;
191+ } ) ;
192+
193+ it ( "rejects GET /api/settings/openrouter/models with 401" , async ( ) => {
194+ const res = await GET_OPENROUTER_MODELS (
195+ new Request ( "http://localhost/api/settings/openrouter/models" )
196+ ) ;
197+ expect ( res . status ) . toBe ( 401 ) ;
198+ } ) ;
199+
200+ it ( "rejects GET /api/settings/provider-models with 401" , async ( ) => {
201+ const res = await GET_PROVIDER_MODELS (
202+ new Request (
203+ "http://localhost/api/settings/provider-models?provider=opencode-go"
204+ )
205+ ) ;
206+ expect ( res . status ) . toBe ( 401 ) ;
207+ } ) ;
208+
209+ it ( "rejects GET /api/export with 401" , async ( ) => {
210+ const res = await GET_EXPORT (
211+ new Request ( "http://localhost/api/export?format=json" )
212+ ) ;
213+ expect ( res . status ) . toBe ( 401 ) ;
214+ } ) ;
215+ } ) ;
143216} ) ;
0 commit comments