diff --git a/api/chat_session_handler.go b/api/chat_session_handler.go index 46786f7d..28c8de91 100644 --- a/api/chat_session_handler.go +++ b/api/chat_session_handler.go @@ -1,6 +1,7 @@ package main import ( + "database/sql" "encoding/json" "fmt" "net/http" @@ -132,17 +133,22 @@ func (h *ChatSessionHandler) GetChatSessionsByUserID(w http.ResponseWriter, r *h func (h *ChatSessionHandler) GetChatSessionByUUID(w http.ResponseWriter, r *http.Request) { uuid := mux.Vars(r)["uuid"] session, err := h.service.GetChatSessionByUUID(r.Context(), uuid) - if err != nil { - http.Error(w, err.Error(), http.StatusNotFound) - return - } - session_resp := &ChatSessionResponse{ - Uuid: session.Uuid, - Topic: session.Topic, - MaxLength: session.MaxLength, - CreatedAt: session.CreatedAt, - UpdatedAt: session.UpdatedAt, - } + session_resp := &ChatSessionResponse{} + if err != nil { + if err == sql.ErrNoRows { + session_resp.Uuid = session.Uuid + session_resp.MaxLength = 10 + json.NewEncoder(w).Encode(session_resp) + } else { + http.Error(w, err.Error(), http.StatusNotFound) + return + } + } + session_resp.Uuid = session.Uuid + session_resp.Topic = session.Topic + session_resp.MaxLength = session.MaxLength + session_resp.CreatedAt = session.CreatedAt + session_resp.UpdatedAt = session.UpdatedAt json.NewEncoder(w).Encode(session_resp) } diff --git a/e2e/tests/01_register.spec.ts b/e2e/tests/01_register.spec.ts index ae7631bb..c66a9504 100644 --- a/e2e/tests/01_register.spec.ts +++ b/e2e/tests/01_register.spec.ts @@ -14,5 +14,6 @@ test('test', async ({ page }) => { await page.getByTestId('password').locator('input').click(); await page.getByTestId('password').locator('input').fill('@WuHao5'); await page.getByTestId('signup').click(); + }); diff --git a/e2e/tests/07_set_session_max_len.spec.ts b/e2e/tests/07_set_session_max_len.spec.ts new file mode 100644 index 00000000..a564d5a2 --- /dev/null +++ b/e2e/tests/07_set_session_max_len.spec.ts @@ -0,0 +1,38 @@ +import { test, expect } from '@playwright/test'; + +//generate a random email address +function randomEmail() { + const random = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); + return `${random}@test.com`; +} +const test_email = randomEmail(); + +test('test', async ({ page }) => { + await page.goto('/'); + await page.getByTestId('email').click(); + await page.getByTestId('email').locator('input').fill(test_email); + await page.getByTestId('password').locator('input').click(); + await page.getByTestId('password').locator('input').fill('@WuHao5'); + await page.getByTestId('signup').click(); + + await page.waitForTimeout(1000); + + await page.getByRole('contentinfo').getByRole('button').nth(2).click(); + // change the value of the slider + // Find the slider element and adjust its value + const sliderRailFill = await page.$('.n-slider-rail__fill') + expect(sliderRailFill).toBeTruthy() + await sliderRailFill?.evaluate((element) => { + element.setAttribute('style', 'width: 25%;') + } + ) + // sliderRailFill?.setAttribute('style', 'width: 25%;') + await page.waitForTimeout(1000); + await page.locator('.n-slider-handles').click(); + await page.locator('.n-slider').click(); + await page.locator('.n-slider').click(); + await page.locator('.n-slider-handles').click(); + await page.locator('.n-slider-handles').click(); + await page.locator('.n-slider').click(); + +}); diff --git a/web/src/api/index.ts b/web/src/api/index.ts index b20ebe2c..1e93d663 100644 --- a/web/src/api/index.ts +++ b/web/src/api/index.ts @@ -169,13 +169,8 @@ export const clearSessionChatMessages = async (sessionUuid: string) => { } export const getChatSessionMaxContextLength = async (sessionUuid: string) => { - try { - const response = await request.get(`/uuid/chat_sessions/${sessionUuid}`) - return response.data.maxLength - } - catch (error) { - console.error(error) - } + const response = await request.get(`/uuid/chat_sessions/${sessionUuid}`) + return response.data.maxLength } export const setChatSessionMaxContextLength = async (uuid: string, maxLength: number) => {