Serve compiled front from the same application

also add embedded build for production
This commit is contained in:
2026-02-11 01:12:53 +01:00
parent 8fc5ff84c2
commit e127088195
28 changed files with 200 additions and 130 deletions

View File

@@ -36,7 +36,7 @@ func testGetAuthor(t *testing.T, authorId string, status int) fetchedAuthor {
router := testutils.TestSetup()
token := testutils.ConnectDemoUser(router)
req, _ := http.NewRequest("GET", "/author/"+authorId, nil)
req, _ := http.NewRequest("GET", "/ws/author/"+authorId, nil)
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
w := httptest.NewRecorder()
router.ServeHTTP(w, req)

View File

@@ -47,7 +47,7 @@ func TestSearchBookPerAuthor_Offset(t *testing.T) {
func testFetchBookAuthor(t *testing.T, authorId uint, limit string, offset string) bookAuthorGetResult {
router := testutils.TestSetup()
u, err := url.Parse(fmt.Sprintf("/author/%d/books", authorId))
u, err := url.Parse(fmt.Sprintf("/ws/author/%d/books", authorId))
if err != nil {
t.Error(err)
}

View File

@@ -21,7 +21,7 @@ func TestGetBook_Ok(t *testing.T) {
AuthorID: 2,
Rating: 10,
Read: true,
CoverPath: "/bookcover/dunchateaulautre.jpg",
CoverPath: "/static/bookcover/dunchateaulautre.jpg",
}, book)
}
@@ -33,7 +33,7 @@ func TestGetBook_NoUserBook(t *testing.T) {
Author: "Truman Capote",
AuthorID: 14,
Read: false,
CoverPath: "/bookcover/desangfroid.jpg",
CoverPath: "/static/bookcover/desangfroid.jpg",
}, book)
}
@@ -48,7 +48,7 @@ func TestGetBook_Description(t *testing.T) {
Summary: "Lorsque le célèbre aviateur Charles Lindbergh battit le président Roosevelt aux élections présidentielles de 1940, la peur s'empara des Juifs américains. Non seulement Lindbergh avait, dans son discours radiophonique à la nation, reproché aux Juifs de pousser l'Amérique à entreprendre une guerre inutile avec l'Allemagne nazie, mais, en devenant trente-troisième président des États-Unis, il s'empressa de signer un pacte de non-agression avec Hitler. Alors la terreur pénétra dans les foyers juifs, notamment dans celui de la famille Roth. Ce contexte sert de décor historique au Complot contre l'Amérique, un roman où Philip Roth, qui avait sept ans à l'époque, raconte ce que vécut et ressentit sa famille - et des millions de familles semblables dans tout le pays - lors des lourdes années où s'exerça la présidence de Lindbergh, quand les citoyens américains qui étaient aussi des Juifs avaient de bonnes raisons de craindre le pire. Ce faisant, il nous offre un nouveau chef-d'oeuvre.",
Rating: 6,
Read: true,
CoverPath: "/bookcover/lecomplotcontrelamerique.jpg",
CoverPath: "/static/bookcover/lecomplotcontrelamerique.jpg",
}, book)
}
@@ -64,7 +64,7 @@ func testGetBook(t *testing.T, id string, status int) dto.BookGet {
router := testutils.TestSetup()
token := testutils.ConnectDemoUser(router)
req, _ := http.NewRequest("GET", "/book/"+id, nil)
req, _ := http.NewRequest("GET", "/ws/book/"+id, nil)
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
w := httptest.NewRecorder()
router.ServeHTTP(w, req)

View File

@@ -73,12 +73,12 @@ func TestGetReadBooksHandler_CheckOneBook(t *testing.T) {
Author: "Truman Capote",
Rating: 6,
Read: true,
CoverPath: "/bookcover/desangfroid.jpg",
CoverPath: "/static/bookcover/desangfroid.jpg",
}, book)
}
func testGetReadBooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int, limit string, offset string) dto.BookUserGet {
u, err := url.Parse("/mybooks/read")
u, err := url.Parse("/ws/mybooks/read")
if err != nil {
t.Error(err)
}

View File

@@ -29,7 +29,7 @@ func TestGetReadingBooksHandler_Demo2(t *testing.T) {
}
func testGetReadingBooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int, limit string, offset string) dto.BookUserGet {
u, err := url.Parse("/mybooks/reading")
u, err := url.Parse("/ws/mybooks/reading")
if err != nil {
t.Error(err)
}

View File

@@ -28,5 +28,5 @@ func TestGetWantReadBooksHandler_Demo2(t *testing.T) {
}
func testGetWantReadBooksHandler(t *testing.T, router *gin.Engine, userToken string, expectedCode int) dto.BookUserGet {
return testGetbooksHandler(t, router, userToken, expectedCode, "/mybooks/wantread")
return testGetbooksHandler(t, router, userToken, expectedCode, "/ws/mybooks/wantread")
}

View File

@@ -68,7 +68,7 @@ func testPostBookHandler(t *testing.T, bookJson string, expectedCode int) {
w := httptest.NewRecorder()
token := testutils.ConnectDemoUser(router)
req, _ := http.NewRequest("POST", "/book",
req, _ := http.NewRequest("POST", "/ws/book",
strings.NewReader(string(bookJson)))
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
router.ServeHTTP(w, req)

View File

@@ -23,7 +23,7 @@ func TestPostImportBookHandler_Ok(t *testing.T) {
assert.Equal(t, "les Hauts de Hurle-Vent", book.Title)
assert.Equal(t, "Emily Brontë", book.Author)
assert.Equal(t, "isbn:9782253004752", book.InventaireId)
assert.Equal(t, "/bookcover/44abbcbdc1092212c2bae66f5165019dac1e2a7b.webp", book.CoverPath)
assert.Equal(t, "/static/bookcover/44abbcbdc1092212c2bae66f5165019dac1e2a7b.webp", book.CoverPath)
}
func TestPostImportBookHandler_OkAuthorKey(t *testing.T) {
@@ -32,7 +32,7 @@ func TestPostImportBookHandler_OkAuthorKey(t *testing.T) {
assert.Equal(t, "Dr Bloodmoney", book.Title)
assert.Equal(t, "Philip K. Dick", book.Author)
assert.Equal(t, "isbn:9782290033630", book.InventaireId)
assert.Equal(t, "/bookcover/1d1493159d031224a42b37c4417fcbb8c76b00bd.webp", book.CoverPath)
assert.Equal(t, "/static/bookcover/1d1493159d031224a42b37c4417fcbb8c76b00bd.webp", book.CoverPath)
}
func TestPostImportBookHandler_NoOLID(t *testing.T) {
@@ -49,7 +49,7 @@ func testPostImportBookHandler(t *testing.T, openlibraryid string, expectedCode
"lang":"fr"
}`
queryJson = fmt.Sprintf(queryJson, openlibraryid)
req, _ := http.NewRequest("POST", "/importbook",
req, _ := http.NewRequest("POST", "/ws/importbook",
strings.NewReader(string(queryJson)))
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
router.ServeHTTP(w, req)

View File

@@ -59,7 +59,7 @@ func testPostUserHandler(t *testing.T, userJson string, expectedCode int) {
router := testutils.TestSetup()
w := httptest.NewRecorder()
req, _ := http.NewRequest("POST", "/auth/signup",
req, _ := http.NewRequest("POST", "/ws/auth/signup",
strings.NewReader(string(userJson)))
router.ServeHTTP(w, req)

View File

@@ -83,5 +83,5 @@ func TestPutRatingUserBooksHandler_BadBookId(t *testing.T) {
}
func testPutRateUserBooks(t *testing.T, payload string, bookId string, expectedCode int) {
testutils.TestBookPutCallWithDemoPayload(t, payload, bookId, expectedCode, "/book/"+bookId+"/rate")
testutils.TestBookPutCallWithDemoPayload(t, payload, bookId, expectedCode, "/ws/book/"+bookId+"/rate")
}

View File

@@ -59,5 +59,5 @@ func TestPutReadUserBooks_UnsetReadOk(t *testing.T) {
}
func testPutReadUserBooks(t *testing.T, payload string, bookId string, expectedCode int) {
testutils.TestBookPutCallWithDemoPayload(t, payload, bookId, expectedCode, "/book/"+bookId+"/read")
testutils.TestBookPutCallWithDemoPayload(t, payload, bookId, expectedCode, "/ws/book/"+bookId+"/read")
}

View File

@@ -49,5 +49,5 @@ func TestPutStartReadUserBooks_Unset(t *testing.T) {
}
func testPutStartReadUserBooks(t *testing.T, payload string, bookId string, expectedCode int) {
testutils.TestBookPutCallWithDemoPayload(t, payload, bookId, expectedCode, "/book/"+bookId+"/startread")
testutils.TestBookPutCallWithDemoPayload(t, payload, bookId, expectedCode, "/ws/book/"+bookId+"/startread")
}

View File

@@ -31,5 +31,5 @@ func TestPutWantRead_SetFalse(t *testing.T) {
}
func testPutWantReadUserBooks(t *testing.T, payload string, bookId string, expectedCode int) {
testutils.TestBookPutCallWithDemoPayload(t, payload, bookId, expectedCode, "/book/"+bookId+"/wantread")
testutils.TestBookPutCallWithDemoPayload(t, payload, bookId, expectedCode, "/ws/book/"+bookId+"/wantread")
}

View File

@@ -32,7 +32,7 @@ func TestSearchBook_OneBookNotUserBook(t *testing.T) {
Rating: 0,
Read: false,
WantRead: false,
CoverPath: "/bookcover/iliade.jpeg",
CoverPath: "/static/bookcover/iliade.jpeg",
}},
result.Books)
}
@@ -48,7 +48,7 @@ func TestSearchBook_OneBookRead(t *testing.T) {
Rating: 7,
Read: true,
WantRead: false,
CoverPath: "/bookcover/lesdieuxontsoif.jpg",
CoverPath: "/static/bookcover/lesdieuxontsoif.jpg",
}},
result.Books)
}
@@ -64,7 +64,7 @@ func TestSearchBook_ISBN(t *testing.T) {
Rating: 6,
Read: true,
WantRead: false,
CoverPath: "/bookcover/lecomplotcontrelamerique.jpg",
CoverPath: "/static/bookcover/lecomplotcontrelamerique.jpg",
}},
result.Books)
}
@@ -102,7 +102,7 @@ func TestSearchBook_Offset(t *testing.T) {
func testSearchBook(t *testing.T, searchterm string, limit string, offset string) dto.BookSearchGet {
router := testutils.TestSetup()
u, err := url.Parse("/search/" + searchterm)
u, err := url.Parse("/ws/search/" + searchterm)
if err != nil {
t.Error(err)
}