@@ -14,9 +14,11 @@ describe("addToDoPage", () => {
1414 } ) ;
1515 const app = new Hono < { Variables : AppVariables } > ( )
1616 . use ( "*" , createAppConfigMiddleware ( appConfig ) )
17- . route ( "/" , addToDoPage ) ;
17+ . route ( pageRoutes . ADD_TODO , addToDoPage ) ;
1818
19- const response = await app . fetch ( new Request ( "http://localhost/" ) ) ;
19+ const response = await app . fetch (
20+ new Request ( `http://localhost${ pageRoutes . ADD_TODO } ` ) ,
21+ ) ;
2022
2123 expect ( response . status ) . toBe ( 302 ) ;
2224 expect ( response . headers . get ( "Location" ) ) . toBe ( pageRoutes . LOGIN ) ;
@@ -26,13 +28,17 @@ describe("addToDoPage", () => {
2628 const appConfig = createAppConfig ( {
2729 JWT_SECRET : "12345678901234567890123456789012" ,
2830 } ) ;
29- const token = await sign ( { sub : "admin" } , appConfig . jwt . secret , "HS256" ) ;
31+ const token = await sign (
32+ { sub : "1234" , preferred_username : "admin" } ,
33+ appConfig . jwt . secret ,
34+ "HS256" ,
35+ ) ;
3036 const app = new Hono < { Variables : AppVariables } > ( )
3137 . use ( "*" , createAppConfigMiddleware ( appConfig ) )
32- . route ( "/" , addToDoPage ) ;
38+ . route ( pageRoutes . ADD_TODO , addToDoPage ) ;
3339
3440 const response = await app . fetch (
35- new Request ( " http://localhost/" , {
41+ new Request ( ` http://localhost${ pageRoutes . ADD_TODO } ` , {
3642 headers : {
3743 Cookie : `${ appConfig . jwt . cookieName } =${ token } ` ,
3844 } ,
@@ -41,6 +47,12 @@ describe("addToDoPage", () => {
4147 const html = await response . text ( ) ;
4248
4349 expect ( response . status ) . toBe ( 200 ) ;
44- expect ( html ) . toContain ( "Add ToDo" ) ;
50+ expect ( html ) . toContain ( "<title>ToDo</title>" ) ;
51+ expect ( html ) . toContain ( "<h1>Add ToDo</h1>" ) ;
52+ expect ( html ) . toContain ( '<a href="/">Home</a>' ) ;
53+ expect ( html ) . not . toContain ( '<a href="/add-todo">Add</a>' ) ;
54+ expect ( html ) . toContain ( '<a href="/about">About</a>' ) ;
55+ expect ( html ) . toContain ( "<li>admin</li>" ) ;
56+ expect ( html ) . toContain ( '<form action="/api/logout" method="post">' ) ;
4557 } ) ;
4658} ) ;
0 commit comments