@@ -18,13 +18,71 @@ package server_test
18
18
19
19
import (
20
20
"net/http"
21
+ "os"
21
22
"testing"
22
23
23
24
"github.com/orca-group/spirit/internal/database"
24
25
"github.com/orca-group/spirit/internal/server"
25
26
"github.com/stretchr/testify/require"
26
27
)
27
28
29
+ func TestMountStatic (t * testing.T ) {
30
+ // Create server and mount expected static files
31
+ s := server .NewServer (& mockConfig , & database.MockDatabase {})
32
+
33
+ s .MountStatic ()
34
+
35
+ // Check robots.txt
36
+ req , _ := http .NewRequest (http .MethodGet , "/robots.txt" , nil )
37
+ res := executeRequest (req , s )
38
+
39
+ checkResponseCode (t , http .StatusOK , res .Result ().StatusCode )
40
+
41
+ file , _ := os .ReadFile ("web/static/robots.txt" )
42
+ require .Equal (t , res .Body .String (), string (file ))
43
+
44
+ // Check presence of CSS files
45
+ globalCssRequest , _ := http .NewRequest (http .MethodGet , "/static/global.css" , nil )
46
+ globalCssResponse := executeRequest (globalCssRequest , s )
47
+ checkResponseCode (t , http .StatusOK , globalCssResponse .Result ().StatusCode )
48
+
49
+ monokaiCssRequest , _ := http .NewRequest (http .MethodGet , "/static/monokai.min.css" , nil )
50
+ monokaiCssResponse := executeRequest (monokaiCssRequest , s )
51
+ checkResponseCode (t , http .StatusOK , monokaiCssResponse .Result ().StatusCode )
52
+
53
+ normalizeCssRequest , _ := http .NewRequest (http .MethodGet , "/static/normalize.css" , nil )
54
+ normalizeCssResponse := executeRequest (normalizeCssRequest , s )
55
+ checkResponseCode (t , http .StatusOK , normalizeCssResponse .Result ().StatusCode )
56
+
57
+ // Check presence of JS files
58
+ appJsRequest , _ := http .NewRequest (http .MethodGet , "/static/app.js" , nil )
59
+ appJsResponse := executeRequest (appJsRequest , s )
60
+ checkResponseCode (t , http .StatusOK , appJsResponse .Result ().StatusCode )
61
+
62
+ highlightJsRequest , _ := http .NewRequest (http .MethodGet , "/static/highlight.min.js" , nil )
63
+ highlightJsResponse := executeRequest (highlightJsRequest , s )
64
+ checkResponseCode (t , http .StatusOK , highlightJsResponse .Result ().StatusCode )
65
+
66
+ // Check presence of image files (logo.svg, favicon.ico)
67
+ faviconRequest , _ := http .NewRequest (http .MethodGet , "/static/favicon.ico" , nil )
68
+ faviconResponse := executeRequest (faviconRequest , s )
69
+ checkResponseCode (t , http .StatusOK , faviconResponse .Result ().StatusCode )
70
+
71
+ logoRequest , _ := http .NewRequest (http .MethodGet , "/static/logo.svg" , nil )
72
+ logoResponse := executeRequest (logoRequest , s )
73
+ checkResponseCode (t , http .StatusOK , logoResponse .Result ().StatusCode )
74
+
75
+ // Check index file exists and returns the correct content
76
+ indexRequest , _ := http .NewRequest (http .MethodGet , "/" , nil )
77
+ indexResponse := executeRequest (indexRequest , s )
78
+
79
+ checkResponseCode (t , http .StatusOK , indexResponse .Result ().StatusCode )
80
+
81
+ indexFile , _ := os .ReadFile ("./web/index.html" )
82
+
83
+ require .Equal (t , string (indexFile ), indexResponse .Body .String ())
84
+ }
85
+
28
86
func TestRegisterHeaders (t * testing.T ) {
29
87
s := server .NewServer (& mockConfig , & database.MockDatabase {})
30
88
0 commit comments