review, next deleteResultRequest
This commit is contained in:
parent
d31069233b
commit
1bfea7d6ab
@ -7568,6 +7568,7 @@ func TestGetResults_InputValidation(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// отсмотрено
|
||||
func TestGetResults_Pagination(t *testing.T) {
|
||||
testData := createTestDataForResults(t, validToken, "Квиз для тестирования пагинации результатов")
|
||||
|
||||
@ -7601,7 +7602,6 @@ func TestGetResults_Pagination(t *testing.T) {
|
||||
err = json.NewDecoder(resp.Body).Decode(&result)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Проверяем структуру ответа
|
||||
assert.IsType(t, uint64(0), result.TotalCount)
|
||||
assert.IsType(t, []model.AnswerExport{}, result.Results)
|
||||
})
|
||||
@ -7619,9 +7619,7 @@ func TestGetResults_Pagination(t *testing.T) {
|
||||
err = json.NewDecoder(resp.Body).Decode(&result)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Проверяем, что на несуществующей странице нет результатов
|
||||
assert.Empty(t, result.Results)
|
||||
assert.Equal(t, uint64(0), result.TotalCount)
|
||||
})
|
||||
|
||||
t.Run("ZeroLimit", func(t *testing.T) {
|
||||
@ -7637,49 +7635,19 @@ func TestGetResults_Pagination(t *testing.T) {
|
||||
err = json.NewDecoder(resp.Body).Decode(&result)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Проверяем, что при лимите 0 возвращается пустой результат
|
||||
assert.Empty(t, result.Results)
|
||||
})
|
||||
}
|
||||
|
||||
// todo для этих тестов нужно заранее заполнять бдшку ответами на вопросы
|
||||
// отсмотрено
|
||||
func TestGetResults_Filtering(t *testing.T) {
|
||||
// Создаем квиз для тестирования фильтрации
|
||||
quizResp, err := createQuizRequest(validToken, map[string]interface{}{
|
||||
"name": "Квиз для тестирования фильтрации результатов",
|
||||
"status": "start",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
defer quizResp.Body.Close()
|
||||
|
||||
var quizResult model.Quiz
|
||||
err = json.NewDecoder(quizResp.Body).Decode(&quizResult)
|
||||
assert.NoError(t, err)
|
||||
quizID := quizResult.Id
|
||||
|
||||
// Создаем вопрос для квиза
|
||||
questionResp, err := createQuestionRequest(validToken, map[string]interface{}{
|
||||
"quiz_id": quizID,
|
||||
"title": "Тестовый вопрос для фильтрации",
|
||||
"type": "text",
|
||||
"description": "Введите ответ.",
|
||||
"required": true,
|
||||
"page": 1,
|
||||
"content": `{"placeholder": "Введите ответ"}`,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
defer questionResp.Body.Close()
|
||||
|
||||
var questionResult model.Question
|
||||
err = json.NewDecoder(questionResp.Body).Decode(&questionResult)
|
||||
assert.NoError(t, err)
|
||||
testData := createTestDataForResults(t, validToken, "Квиз для тестирования фильтрации результатов")
|
||||
|
||||
t.Run("WithDateRange", func(t *testing.T) {
|
||||
// Тестируем фильтрацию по диапазону дат
|
||||
fromDate := time.Now().AddDate(0, -1, 0).Format("2006-01-02T15:04:05Z")
|
||||
toDate := time.Now().AddDate(0, 1, 0).Format("2006-01-02T15:04:05Z")
|
||||
|
||||
resp, err := getResultsRequest(validToken, fmt.Sprintf("%v", quizID), map[string]interface{}{
|
||||
resp, err := getResultsRequest(validToken, fmt.Sprintf("%v", testData.Quiz.Id), map[string]interface{}{
|
||||
"From": fromDate,
|
||||
"To": toDate,
|
||||
"Page": 0,
|
||||
@ -7693,14 +7661,12 @@ func TestGetResults_Filtering(t *testing.T) {
|
||||
err = json.NewDecoder(resp.Body).Decode(&result)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Проверяем структуру ответа
|
||||
assert.IsType(t, uint64(0), result.TotalCount)
|
||||
assert.IsType(t, []model.AnswerExport{}, result.Results)
|
||||
})
|
||||
|
||||
t.Run("NewResultsOnly", func(t *testing.T) {
|
||||
// Тестируем фильтрацию только новых результатов
|
||||
resp, err := getResultsRequest(validToken, fmt.Sprintf("%v", quizID), map[string]interface{}{
|
||||
resp, err := getResultsRequest(validToken, fmt.Sprintf("%v", testData.Quiz.Id), map[string]interface{}{
|
||||
"New": true,
|
||||
"Page": 0,
|
||||
"Limit": 10,
|
||||
@ -7713,18 +7679,16 @@ func TestGetResults_Filtering(t *testing.T) {
|
||||
err = json.NewDecoder(resp.Body).Decode(&result)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Проверяем, что все возвращенные результаты помечены как новые
|
||||
for _, answer := range result.Results {
|
||||
assert.True(t, answer.New)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("CombinedFilters", func(t *testing.T) {
|
||||
// Тестируем комбинированную фильтрацию
|
||||
fromDate := time.Now().AddDate(0, -1, 0).Format("2006-01-02T15:04:05Z")
|
||||
toDate := time.Now().AddDate(0, 1, 0).Format("2006-01-02T15:04:05Z")
|
||||
|
||||
resp, err := getResultsRequest(validToken, fmt.Sprintf("%v", quizID), map[string]interface{}{
|
||||
resp, err := getResultsRequest(validToken, fmt.Sprintf("%v", testData.Quiz.Id), map[string]interface{}{
|
||||
"From": fromDate,
|
||||
"To": toDate,
|
||||
"New": true,
|
||||
@ -7739,17 +7703,15 @@ func TestGetResults_Filtering(t *testing.T) {
|
||||
err = json.NewDecoder(resp.Body).Decode(&result)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Проверяем структуру ответа
|
||||
assert.IsType(t, uint64(0), result.TotalCount)
|
||||
assert.IsType(t, []model.AnswerExport{}, result.Results)
|
||||
})
|
||||
|
||||
t.Run("InvalidDateRange", func(t *testing.T) {
|
||||
// Тестируем некорректный диапазон дат (From > To)
|
||||
fromDate := time.Now().AddDate(0, 1, 0).Format("2006-01-02T15:04:05Z")
|
||||
toDate := time.Now().AddDate(0, -1, 0).Format("2006-01-02T15:04:05Z")
|
||||
|
||||
resp, err := getResultsRequest(validToken, fmt.Sprintf("%v", quizID), map[string]interface{}{
|
||||
resp, err := getResultsRequest(validToken, fmt.Sprintf("%v", testData.Quiz.Id), map[string]interface{}{
|
||||
"From": fromDate,
|
||||
"To": toDate,
|
||||
"Page": 0,
|
||||
@ -7763,49 +7725,18 @@ func TestGetResults_Filtering(t *testing.T) {
|
||||
err = json.NewDecoder(resp.Body).Decode(&result)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// При некорректном диапазоне дат должен возвращаться пустой результат
|
||||
assert.Empty(t, result.Results)
|
||||
assert.Equal(t, uint64(0), result.TotalCount)
|
||||
})
|
||||
}
|
||||
|
||||
// todo для этих тестов нужно заранее заполнять бдшку ответами на вопросы
|
||||
// отсмотрено
|
||||
func TestGetResults_Performance(t *testing.T) {
|
||||
// Создаем квиз для тестирования производительности
|
||||
quizResp, err := createQuizRequest(validToken, map[string]interface{}{
|
||||
"name": "Квиз для тестирования производительности результатов",
|
||||
"status": "start",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
defer quizResp.Body.Close()
|
||||
|
||||
var quizResult model.Quiz
|
||||
err = json.NewDecoder(quizResp.Body).Decode(&quizResult)
|
||||
assert.NoError(t, err)
|
||||
quizID := quizResult.Id
|
||||
|
||||
// Создаем несколько вопросов для квиза
|
||||
for i := 1; i <= 5; i++ {
|
||||
questionResp, err := createQuestionRequest(validToken, map[string]interface{}{
|
||||
"quiz_id": quizID,
|
||||
"title": fmt.Sprintf("Вопрос %d для производительности", i),
|
||||
"type": "text",
|
||||
"description": fmt.Sprintf("Описание вопроса %d", i),
|
||||
"required": true,
|
||||
"page": i,
|
||||
"content": `{"placeholder": "Введите ответ"}`,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
defer questionResp.Body.Close()
|
||||
|
||||
var questionResult model.Question
|
||||
err = json.NewDecoder(questionResp.Body).Decode(&questionResult)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
testData := createTestDataForResults(t, validToken, "Квиз для тестирования производительности результатов")
|
||||
|
||||
t.Run("ResponseTime", func(t *testing.T) {
|
||||
start := time.Now()
|
||||
resp, err := getResultsRequest(validToken, fmt.Sprintf("%v", quizID), map[string]interface{}{
|
||||
resp, err := getResultsRequest(validToken, fmt.Sprintf("%v", testData.Quiz.Id), map[string]interface{}{
|
||||
"Page": 0,
|
||||
"Limit": 10,
|
||||
})
|
||||
@ -7814,16 +7745,14 @@ func TestGetResults_Performance(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Проверяем время ответа
|
||||
assert.Less(t, duration.Milliseconds(), int64(500))
|
||||
|
||||
// Проверяем статус ответа
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
|
||||
// Проверяем структуру ответа
|
||||
var result result2.ReqExportResponse
|
||||
err = json.NewDecoder(resp.Body).Decode(&result)
|
||||
assert.NoError(t, err)
|
||||
fmt.Println(result)
|
||||
assert.IsType(t, uint64(0), result.TotalCount)
|
||||
assert.IsType(t, []model.AnswerExport{}, result.Results)
|
||||
})
|
||||
@ -7836,7 +7765,7 @@ func TestGetResults_Performance(t *testing.T) {
|
||||
wg.Add(1)
|
||||
go func(requestID int) {
|
||||
defer wg.Done()
|
||||
resp, err := getResultsRequest(validToken, fmt.Sprintf("%v", quizID), map[string]interface{}{
|
||||
resp, err := getResultsRequest(validToken, fmt.Sprintf("%v", testData.Quiz.Id), map[string]interface{}{
|
||||
"Page": 0,
|
||||
"Limit": 5,
|
||||
})
|
||||
@ -7847,7 +7776,6 @@ func TestGetResults_Performance(t *testing.T) {
|
||||
if resp != nil {
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Проверяем, что ответ корректен
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
var result result2.ReqExportResponse
|
||||
if decodeErr := json.NewDecoder(resp.Body).Decode(&result); decodeErr != nil {
|
||||
@ -7860,7 +7788,6 @@ func TestGetResults_Performance(t *testing.T) {
|
||||
wg.Wait()
|
||||
close(errors)
|
||||
|
||||
// Проверяем, что не было ошибок
|
||||
for err := range errors {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@ -7868,64 +7795,34 @@ func TestGetResults_Performance(t *testing.T) {
|
||||
|
||||
t.Run("LargeLimit", func(t *testing.T) {
|
||||
start := time.Now()
|
||||
resp, err := getResultsRequest(validToken, fmt.Sprintf("%v", quizID), map[string]interface{}{
|
||||
resp, err := getResultsRequest(validToken, fmt.Sprintf("%v", testData.Quiz.Id), map[string]interface{}{
|
||||
"Page": 0,
|
||||
"Limit": 1000, // Большой лимит
|
||||
"Limit": 1000,
|
||||
})
|
||||
duration := time.Since(start)
|
||||
|
||||
assert.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Проверяем время ответа даже для большого лимита
|
||||
assert.Less(t, duration.Milliseconds(), int64(1000))
|
||||
|
||||
// Проверяем статус ответа
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
|
||||
// Проверяем структуру ответа
|
||||
var result result2.ReqExportResponse
|
||||
err = json.NewDecoder(resp.Body).Decode(&result)
|
||||
assert.NoError(t, err)
|
||||
fmt.Println(result)
|
||||
assert.IsType(t, uint64(0), result.TotalCount)
|
||||
assert.IsType(t, []model.AnswerExport{}, result.Results)
|
||||
})
|
||||
}
|
||||
|
||||
// todo для этих тестов нужно заранее заполнять бдшку ответами на вопросы
|
||||
// отсмотрено
|
||||
func TestGetResults_ErrorHandling(t *testing.T) {
|
||||
// Создаем квиз для тестирования обработки ошибок
|
||||
quizResp, err := createQuizRequest(validToken, map[string]interface{}{
|
||||
"name": "Квиз для тестирования обработки ошибок",
|
||||
"status": "start",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
defer quizResp.Body.Close()
|
||||
|
||||
var quizResult model.Quiz
|
||||
err = json.NewDecoder(quizResp.Body).Decode(&quizResult)
|
||||
assert.NoError(t, err)
|
||||
quizID := quizResult.Id
|
||||
|
||||
// Создаем вопрос для квиза
|
||||
questionResp, err := createQuestionRequest(validToken, map[string]interface{}{
|
||||
"quiz_id": quizID,
|
||||
"title": "Тестовый вопрос для обработки ошибок",
|
||||
"type": "text",
|
||||
"description": "Введите ответ.",
|
||||
"required": true,
|
||||
"page": 1,
|
||||
"content": `{"placeholder": "Введите ответ"}`,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
defer questionResp.Body.Close()
|
||||
|
||||
var questionResult model.Question
|
||||
err = json.NewDecoder(questionResp.Body).Decode(&questionResult)
|
||||
assert.NoError(t, err)
|
||||
testData := createTestDataForResults(t, validToken, "Квиз для тестирования обработки ошибок")
|
||||
|
||||
t.Run("MalformedJSON", func(t *testing.T) {
|
||||
req, err := http.NewRequest("POST", baseURL+fmt.Sprintf("/results/getResults/%v", quizID), bytes.NewReader([]byte("{invalid_json}")))
|
||||
req, err := http.NewRequest("POST", baseURL+fmt.Sprintf("/results/getResults/%v", testData.Quiz.Id), bytes.NewReader([]byte("{invalid_json}")))
|
||||
assert.NoError(t, err)
|
||||
req.Header.Set("Authorization", "Bearer "+validToken)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
@ -7936,7 +7833,6 @@ func TestGetResults_ErrorHandling(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("InvalidQuizID", func(t *testing.T) {
|
||||
// Тестируем некорректный ID квиза
|
||||
resp, err := getResultsRequest(validToken, "invalid-quiz-id", map[string]interface{}{
|
||||
"Page": 0,
|
||||
"Limit": 10,
|
||||
@ -7947,7 +7843,6 @@ func TestGetResults_ErrorHandling(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("NonExistentQuizID", func(t *testing.T) {
|
||||
// Тестируем несуществующий ID квиза
|
||||
resp, err := getResultsRequest(validToken, "999999", map[string]interface{}{
|
||||
"Page": 0,
|
||||
"Limit": 10,
|
||||
@ -7960,14 +7855,12 @@ func TestGetResults_ErrorHandling(t *testing.T) {
|
||||
err = json.NewDecoder(resp.Body).Decode(&result)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Проверяем, что для несуществующего квиза возвращается пустой результат
|
||||
assert.Equal(t, uint64(0), result.TotalCount)
|
||||
assert.Empty(t, result.Results)
|
||||
})
|
||||
|
||||
t.Run("InvalidPagination", func(t *testing.T) {
|
||||
// Тестируем некорректные параметры пагинации
|
||||
resp, err := getResultsRequest(validToken, fmt.Sprintf("%v", quizID), map[string]interface{}{
|
||||
resp, err := getResultsRequest(validToken, fmt.Sprintf("%v", testData.Quiz.Id), map[string]interface{}{
|
||||
"Page": "invalid-page",
|
||||
"Limit": "invalid-limit",
|
||||
})
|
||||
@ -7977,8 +7870,7 @@ func TestGetResults_ErrorHandling(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("InvalidDateFormat", func(t *testing.T) {
|
||||
// Тестируем некорректный формат даты
|
||||
resp, err := getResultsRequest(validToken, fmt.Sprintf("%v", quizID), map[string]interface{}{
|
||||
resp, err := getResultsRequest(validToken, fmt.Sprintf("%v", testData.Quiz.Id), map[string]interface{}{
|
||||
"From": "invalid-date",
|
||||
"To": "invalid-date",
|
||||
"Page": 0,
|
||||
@ -7986,20 +7878,11 @@ func TestGetResults_ErrorHandling(t *testing.T) {
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
|
||||
var result result2.ReqExportResponse
|
||||
err = json.NewDecoder(resp.Body).Decode(&result)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Проверяем структуру ответа
|
||||
assert.IsType(t, uint64(0), result.TotalCount)
|
||||
assert.IsType(t, []model.AnswerExport{}, result.Results)
|
||||
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("EmptyBody", func(t *testing.T) {
|
||||
// Тестируем пустое тело запроса
|
||||
req, err := http.NewRequest("POST", baseURL+fmt.Sprintf("/results/getResults/%v", quizID), bytes.NewReader([]byte("{}")))
|
||||
req, err := http.NewRequest("POST", baseURL+fmt.Sprintf("/results/getResults/%v", testData.Quiz.Id), bytes.NewReader([]byte("{}")))
|
||||
assert.NoError(t, err)
|
||||
req.Header.Set("Authorization", "Bearer "+validToken)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
@ -8012,7 +7895,6 @@ func TestGetResults_ErrorHandling(t *testing.T) {
|
||||
err = json.NewDecoder(resp.Body).Decode(&result)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Проверяем структуру ответа
|
||||
assert.IsType(t, uint64(0), result.TotalCount)
|
||||
assert.IsType(t, []model.AnswerExport{}, result.Results)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user