review, next copyQuizRequest
This commit is contained in:
parent
10a83013e0
commit
77eb56a807
@ -5484,6 +5484,7 @@ func editQuizRequest(token string, body map[string]interface{}) (*http.Response,
|
||||
return http.DefaultClient.Do(req)
|
||||
}
|
||||
|
||||
// отсмотрено
|
||||
func TestEditQuiz_Success(t *testing.T) {
|
||||
createResp, err := createQuizRequest(validToken, map[string]interface{}{
|
||||
"name": "Квиз для редактирования",
|
||||
@ -5491,13 +5492,12 @@ func TestEditQuiz_Success(t *testing.T) {
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
defer createResp.Body.Close()
|
||||
var createResult map[string]interface{}
|
||||
var createResult model.Quiz
|
||||
err = json.NewDecoder(createResp.Body).Decode(&createResult)
|
||||
assert.NoError(t, err)
|
||||
quizID := createResult["id"]
|
||||
|
||||
resp, err := editQuizRequest(validToken, map[string]interface{}{
|
||||
"id": quizID,
|
||||
"id": createResult.Id,
|
||||
"name": "Обновленное название квиза",
|
||||
"desc": "Новое описание",
|
||||
"status": "start",
|
||||
@ -5511,12 +5511,13 @@ func TestEditQuiz_Success(t *testing.T) {
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
assert.Equal(t, "application/json", resp.Header.Get("Content-Type"))
|
||||
|
||||
var result map[string]interface{}
|
||||
var result quiz.UpdateResp
|
||||
err = json.NewDecoder(resp.Body).Decode(&result)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, quizID, result["updated"])
|
||||
assert.Equal(t, createResult.Id, result.Updated)
|
||||
}
|
||||
|
||||
// отсмотрено
|
||||
func TestEditQuiz_OneField(t *testing.T) {
|
||||
createResp, err := createQuizRequest(validToken, map[string]interface{}{
|
||||
"name": "Квиз для смены статуса",
|
||||
@ -5524,25 +5525,25 @@ func TestEditQuiz_OneField(t *testing.T) {
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
defer createResp.Body.Close()
|
||||
var createResult map[string]interface{}
|
||||
var createResult model.Quiz
|
||||
err = json.NewDecoder(createResp.Body).Decode(&createResult)
|
||||
assert.NoError(t, err)
|
||||
quizID := createResult["id"]
|
||||
|
||||
resp, err := editQuizRequest(validToken, map[string]interface{}{
|
||||
"id": quizID,
|
||||
"id": createResult.Id,
|
||||
"status": "stop",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
|
||||
var result map[string]interface{}
|
||||
var result quiz.UpdateResp
|
||||
err = json.NewDecoder(resp.Body).Decode(&result)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, quizID, result["updated"])
|
||||
assert.Equal(t, createResult.Id, result.Updated)
|
||||
}
|
||||
|
||||
// отсмотрено
|
||||
func TestEditQuiz_Auth(t *testing.T) {
|
||||
t.Run("NoToken", func(t *testing.T) {
|
||||
payload, err := json.Marshal(map[string]interface{}{
|
||||
@ -5579,6 +5580,7 @@ func TestEditQuiz_Auth(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// отсмотрено
|
||||
func TestEditQuiz_InputValidation(t *testing.T) {
|
||||
t.Run("MissingID", func(t *testing.T) {
|
||||
resp, err := editQuizRequest(validToken, map[string]interface{}{
|
||||
@ -5586,7 +5588,7 @@ func TestEditQuiz_InputValidation(t *testing.T) {
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
assert.Contains(t, []int{http.StatusBadRequest, 422}, resp.StatusCode)
|
||||
assert.Equal(t, http.StatusFailedDependency, resp.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("InvalidID", func(t *testing.T) {
|
||||
@ -5596,9 +5598,9 @@ func TestEditQuiz_InputValidation(t *testing.T) {
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
assert.Contains(t, []int{http.StatusBadRequest, 422}, resp.StatusCode)
|
||||
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
||||
})
|
||||
|
||||
// todo нужен ответ 404
|
||||
t.Run("NonExistentID", func(t *testing.T) {
|
||||
resp, err := editQuizRequest(validToken, map[string]interface{}{
|
||||
"id": 99999,
|
||||
@ -5606,7 +5608,7 @@ func TestEditQuiz_InputValidation(t *testing.T) {
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
assert.Contains(t, []int{http.StatusBadRequest, 422}, resp.StatusCode)
|
||||
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("NameTooLong", func(t *testing.T) {
|
||||
@ -5617,7 +5619,7 @@ func TestEditQuiz_InputValidation(t *testing.T) {
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
assert.Contains(t, []int{http.StatusBadRequest, 422}, resp.StatusCode)
|
||||
assert.Equal(t, http.StatusUnprocessableEntity, resp.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("InvalidStatus", func(t *testing.T) {
|
||||
@ -5627,7 +5629,7 @@ func TestEditQuiz_InputValidation(t *testing.T) {
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
assert.Contains(t, []int{http.StatusBadRequest, 422}, resp.StatusCode)
|
||||
assert.Equal(t, http.StatusNotAcceptable, resp.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("InvalidFP", func(t *testing.T) {
|
||||
@ -5637,7 +5639,7 @@ func TestEditQuiz_InputValidation(t *testing.T) {
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
assert.Contains(t, []int{http.StatusBadRequest, 422}, resp.StatusCode)
|
||||
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("InvalidLimit", func(t *testing.T) {
|
||||
@ -5647,10 +5649,11 @@ func TestEditQuiz_InputValidation(t *testing.T) {
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
assert.Contains(t, []int{http.StatusBadRequest, 422}, resp.StatusCode)
|
||||
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
||||
})
|
||||
}
|
||||
|
||||
// todo
|
||||
func TestEditQuiz_Security(t *testing.T) {
|
||||
t.Run("SQLInjection", func(t *testing.T) {
|
||||
resp, err := editQuizRequest(validToken, map[string]interface{}{
|
||||
@ -5677,6 +5680,7 @@ func TestEditQuiz_Security(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// отсмотрено
|
||||
func TestEditQuiz_Performance(t *testing.T) {
|
||||
createResp, err := createQuizRequest(validToken, map[string]interface{}{
|
||||
"name": "Квиз для теста производительности",
|
||||
@ -5684,20 +5688,20 @@ func TestEditQuiz_Performance(t *testing.T) {
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
defer createResp.Body.Close()
|
||||
var createResult map[string]interface{}
|
||||
var createResult model.Quiz
|
||||
err = json.NewDecoder(createResp.Body).Decode(&createResult)
|
||||
assert.NoError(t, err)
|
||||
quizID := createResult["id"]
|
||||
|
||||
t.Run("ResponseTime", func(t *testing.T) {
|
||||
start := time.Now()
|
||||
resp, err := editQuizRequest(validToken, map[string]interface{}{
|
||||
"id": quizID,
|
||||
"id": createResult.Id,
|
||||
"name": "Быстрое обновление",
|
||||
})
|
||||
duration := time.Since(start)
|
||||
assert.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
assert.Less(t, duration.Milliseconds(), int64(500))
|
||||
})
|
||||
|
||||
@ -5708,12 +5712,13 @@ func TestEditQuiz_Performance(t *testing.T) {
|
||||
go func(index int) {
|
||||
defer wg.Done()
|
||||
resp, err := editQuizRequest(validToken, map[string]interface{}{
|
||||
"id": quizID,
|
||||
"id": createResult.Id,
|
||||
"name": fmt.Sprintf("Load Test Quiz %d", index),
|
||||
})
|
||||
if err == nil && resp != nil {
|
||||
resp.Body.Close()
|
||||
}
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
}(i)
|
||||
}
|
||||
wg.Wait()
|
||||
|
Loading…
Reference in New Issue
Block a user