mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
3.6 KiB
93 lines
3.6 KiB
5 years ago
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
2 years ago
|
package integration
|
||
5 years ago
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"testing"
|
||
|
|
||
3 years ago
|
"code.gitea.io/gitea/models/db"
|
||
2 years ago
|
issues_model "code.gitea.io/gitea/models/issues"
|
||
3 years ago
|
repo_model "code.gitea.io/gitea/models/repo"
|
||
3 years ago
|
"code.gitea.io/gitea/models/unittest"
|
||
3 years ago
|
user_model "code.gitea.io/gitea/models/user"
|
||
5 years ago
|
api "code.gitea.io/gitea/modules/structs"
|
||
2 years ago
|
"code.gitea.io/gitea/tests"
|
||
5 years ago
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestAPIListStopWatches(t *testing.T) {
|
||
2 years ago
|
defer tests.PrepareTestEnv(t)()
|
||
5 years ago
|
|
||
2 years ago
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
||
5 years ago
|
|
||
|
session := loginUser(t, owner.Name)
|
||
|
token := getTokenForLoggedInUser(t, session)
|
||
|
req := NewRequestf(t, "GET", "/api/v1/user/stopwatches?token=%s", token)
|
||
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||
|
var apiWatches []*api.StopWatch
|
||
|
DecodeJSON(t, resp, &apiWatches)
|
||
2 years ago
|
stopwatch := unittest.AssertExistsAndLoadBean(t, &issues_model.Stopwatch{UserID: owner.ID})
|
||
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: stopwatch.IssueID})
|
||
4 years ago
|
if assert.Len(t, apiWatches, 1) {
|
||
|
assert.EqualValues(t, stopwatch.CreatedUnix.AsTime().Unix(), apiWatches[0].Created.Unix())
|
||
4 years ago
|
assert.EqualValues(t, issue.Index, apiWatches[0].IssueIndex)
|
||
|
assert.EqualValues(t, issue.Title, apiWatches[0].IssueTitle)
|
||
|
assert.EqualValues(t, repo.Name, apiWatches[0].RepoName)
|
||
|
assert.EqualValues(t, repo.OwnerName, apiWatches[0].RepoOwnerName)
|
||
2 years ago
|
assert.Greater(t, apiWatches[0].Seconds, int64(0))
|
||
4 years ago
|
}
|
||
5 years ago
|
}
|
||
|
|
||
|
func TestAPIStopStopWatches(t *testing.T) {
|
||
2 years ago
|
defer tests.PrepareTestEnv(t)()
|
||
5 years ago
|
|
||
2 years ago
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
|
||
3 years ago
|
_ = issue.LoadRepo(db.DefaultContext)
|
||
2 years ago
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID})
|
||
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||
5 years ago
|
|
||
|
session := loginUser(t, user.Name)
|
||
|
token := getTokenForLoggedInUser(t, session)
|
||
|
|
||
|
req := NewRequestf(t, "POST", "/api/v1/repos/%s/%s/issues/%d/stopwatch/stop?token=%s", owner.Name, issue.Repo.Name, issue.Index, token)
|
||
|
session.MakeRequest(t, req, http.StatusCreated)
|
||
|
session.MakeRequest(t, req, http.StatusConflict)
|
||
|
}
|
||
|
|
||
|
func TestAPICancelStopWatches(t *testing.T) {
|
||
2 years ago
|
defer tests.PrepareTestEnv(t)()
|
||
5 years ago
|
|
||
2 years ago
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1})
|
||
3 years ago
|
_ = issue.LoadRepo(db.DefaultContext)
|
||
2 years ago
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID})
|
||
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||
5 years ago
|
|
||
|
session := loginUser(t, user.Name)
|
||
|
token := getTokenForLoggedInUser(t, session)
|
||
|
|
||
|
req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/%d/stopwatch/delete?token=%s", owner.Name, issue.Repo.Name, issue.Index, token)
|
||
|
session.MakeRequest(t, req, http.StatusNoContent)
|
||
|
session.MakeRequest(t, req, http.StatusConflict)
|
||
|
}
|
||
|
|
||
|
func TestAPIStartStopWatches(t *testing.T) {
|
||
2 years ago
|
defer tests.PrepareTestEnv(t)()
|
||
5 years ago
|
|
||
2 years ago
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 3})
|
||
3 years ago
|
_ = issue.LoadRepo(db.DefaultContext)
|
||
2 years ago
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID})
|
||
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||
5 years ago
|
|
||
|
session := loginUser(t, user.Name)
|
||
|
token := getTokenForLoggedInUser(t, session)
|
||
|
|
||
|
req := NewRequestf(t, "POST", "/api/v1/repos/%s/%s/issues/%d/stopwatch/start?token=%s", owner.Name, issue.Repo.Name, issue.Index, token)
|
||
|
session.MakeRequest(t, req, http.StatusCreated)
|
||
|
session.MakeRequest(t, req, http.StatusConflict)
|
||
|
}
|