2024-05-03 16:43:42 +01:00
|
|
|
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
2024-02-23 00:26:49 +00:00
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2020-04-24 15:37:28 +01:00
|
|
|
// Copyright 2020 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.
|
|
|
|
|
2024-02-23 00:26:49 +00:00
|
|
|
package forgejo
|
2020-04-24 15:37:28 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestIssue is main func witch call all Tests for Issue API
|
|
|
|
// (to make sure they are on correct order)
|
|
|
|
func TestIssueSubscription(t *testing.T) {
|
2020-05-19 07:33:05 +01:00
|
|
|
log.Println("== TestIssueSubscription ==")
|
2020-04-24 15:37:28 +01:00
|
|
|
|
|
|
|
c := newTestClient()
|
|
|
|
repo, _ := createTestRepo(t, "IssueWatch", c)
|
|
|
|
createTestIssue(t, c, repo.Name, "First Issue", "", nil, nil, 0, nil, false, false)
|
|
|
|
|
2020-09-14 03:37:09 +01:00
|
|
|
wi, _, err := c.CheckIssueSubscription(repo.Owner.UserName, repo.Name, 1)
|
2020-04-24 15:37:28 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, wi.Subscribed)
|
|
|
|
|
2020-09-14 03:37:09 +01:00
|
|
|
_, err = c.UnWatchRepo(repo.Owner.UserName, repo.Name)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
wi, _, err = c.CheckIssueSubscription(repo.Owner.UserName, repo.Name, 1)
|
2020-04-24 15:37:28 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, wi.Subscribed)
|
|
|
|
|
2020-09-14 03:37:09 +01:00
|
|
|
_, err = c.IssueSubscribe(repo.Owner.UserName, repo.Name, 1)
|
2020-05-11 16:28:10 +01:00
|
|
|
if assert.Error(t, err) {
|
|
|
|
assert.EqualValues(t, "already subscribed", err.Error())
|
|
|
|
}
|
2020-09-14 03:37:09 +01:00
|
|
|
wi, _, err = c.CheckIssueSubscription(repo.Owner.UserName, repo.Name, 1)
|
2020-04-24 15:37:28 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, wi.Subscribed)
|
|
|
|
|
2020-09-14 03:37:09 +01:00
|
|
|
_, err = c.IssueUnSubscribe(repo.Owner.UserName, repo.Name, 1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
wi, _, err = c.CheckIssueSubscription(repo.Owner.UserName, repo.Name, 1)
|
2020-04-24 15:37:28 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.False(t, wi.Subscribed)
|
|
|
|
|
2020-09-14 03:37:09 +01:00
|
|
|
_, err = c.WatchRepo(repo.Owner.UserName, repo.Name)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
wi, _, err = c.CheckIssueSubscription(repo.Owner.UserName, repo.Name, 1)
|
2020-04-24 15:37:28 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.False(t, wi.Subscribed)
|
|
|
|
}
|