forgejo-sdk/gitea/issue_subscription_test.go
6543 688ee1978e All Function return http responce (#416)
Add Docs on how to deal with this breaking change

doResponse should return responce in all cases, to prosses things manualy if wanted

helper func return http response

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/416
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
2020-09-14 02:37:09 +00:00

52 lines
1.6 KiB
Go

// 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.
package gitea
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) {
log.Println("== TestIssueSubscription ==")
c := newTestClient()
repo, _ := createTestRepo(t, "IssueWatch", c)
createTestIssue(t, c, repo.Name, "First Issue", "", nil, nil, 0, nil, false, false)
wi, _, err := c.CheckIssueSubscription(repo.Owner.UserName, repo.Name, 1)
assert.NoError(t, err)
assert.True(t, wi.Subscribed)
_, err = c.UnWatchRepo(repo.Owner.UserName, repo.Name)
assert.NoError(t, err)
wi, _, err = c.CheckIssueSubscription(repo.Owner.UserName, repo.Name, 1)
assert.NoError(t, err)
assert.True(t, wi.Subscribed)
_, err = c.IssueSubscribe(repo.Owner.UserName, repo.Name, 1)
if assert.Error(t, err) {
assert.EqualValues(t, "already subscribed", err.Error())
}
wi, _, err = c.CheckIssueSubscription(repo.Owner.UserName, repo.Name, 1)
assert.NoError(t, err)
assert.True(t, wi.Subscribed)
_, err = c.IssueUnSubscribe(repo.Owner.UserName, repo.Name, 1)
assert.NoError(t, err)
wi, _, err = c.CheckIssueSubscription(repo.Owner.UserName, repo.Name, 1)
assert.NoError(t, err)
assert.False(t, wi.Subscribed)
_, err = c.WatchRepo(repo.Owner.UserName, repo.Name)
assert.NoError(t, err)
wi, _, err = c.CheckIssueSubscription(repo.Owner.UserName, repo.Name, 1)
assert.NoError(t, err)
assert.False(t, wi.Subscribed)
}