blob: 5527c31ec2bcc89ac64cca69ea1e7485747cbe9e [file] [log] [blame]
Akrone2161562022-12-19 17:05:39 +01001package main
2
3import (
4 "net/http"
5 "net/http/httptest"
6 "testing"
7
8 "github.com/stretchr/testify/assert"
9)
10
Akron5e1252e2022-12-19 17:57:56 +010011func TestMappingRoute(t *testing.T) {
Akrone2161562022-12-19 17:05:39 +010012
13 dir := t.TempDir()
14
15 initDB(dir)
16 defer closeDB()
17 router := setupRouter()
18
19 w := httptest.NewRecorder()
20 req, _ := http.NewRequest(http.MethodGet, "/s10/s10/s10", nil)
21
22 router.ServeHTTP(w, req)
23
24 assert.Equal(t, http.StatusNotFound, w.Code)
25 assert.Equal(t, "No entry found", w.Body.String())
26
27 assert.Nil(t, add("s11", "s12", "s13", "http://example.org"))
28
29 w = httptest.NewRecorder()
30 req, _ = http.NewRequest(http.MethodGet, "/s11/s12/s13", nil)
31
32 router.ServeHTTP(w, req)
33 assert.Equal(t, http.StatusOK, w.Code)
34 assert.Equal(t, "http://example.org", w.Body.String())
35}
Akron5e1252e2022-12-19 17:57:56 +010036
37func TestAssetRoute(t *testing.T) {
38
39 router := setupRouter()
40
41 w := httptest.NewRecorder()
42 req, _ := http.NewRequest(http.MethodGet, "/index", nil)
43
44 router.ServeHTTP(w, req)
45
46 assert.Equal(t, http.StatusOK, w.Code)
47 assert.Contains(t, w.Body.String(), "data-server=\"https://korap.ids-mannheim.de/\"")
48 assert.Contains(t, w.Body.String(), "<title>External Sale Plugin</title>")
49}