Skip to content

Commit

Permalink
Changed project id from in to string
Browse files Browse the repository at this point in the history
  • Loading branch information
borisershov committed Oct 9, 2021
1 parent 7292f56 commit ddabcc9
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 27 deletions.
2 changes: 1 addition & 1 deletion attachments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestAttachmentsCRUD(t *testing.T) {

// Preparing auxiliary data
pCreated := testProjectCreate(t, r, []int{testIssueTrackerID})
defer testProjectDetele(t, r, pCreated.ID)
defer testProjectDetele(t, r, pCreated.Identifier)

// Get multi

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/nixys/nxs-go-redmine/v3
module github.com/nixys/nxs-go-redmine/v4

go 1.14

Expand Down
4 changes: 2 additions & 2 deletions issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ func TestIssuesCRUD(t *testing.T) {

// Preparing auxiliary data
pCreated := testProjectCreate(t, r, []int{testIssueTrackerID})
defer testProjectDetele(t, r, pCreated.ID)
defer testProjectDetele(t, r, pCreated.Identifier)

uCreated := testUserCreate(t, r)
defer testUserDetele(t, r, uCreated.ID)

testMembershipAdd(t, r, pCreated.ID, uCreated.ID, testMembershipRoleID)
testMembershipAdd(t, r, pCreated.Identifier, uCreated.ID, testMembershipRoleID)

// Add and delete
iCreated := testIssueCreate(t, r, pCreated.ID, uCreated.ID, nil)
Expand Down
10 changes: 5 additions & 5 deletions memberships.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type membershipUpdate struct {
// MembershipAllGet gets info for all memberships for project with specified ID
//
// see: http://www.redmine.org/projects/redmine/wiki/Rest_Memberships#GET
func (r *Context) MembershipAllGet(projectID int) (MembershipResult, int, error) {
func (r *Context) MembershipAllGet(projectID string) (MembershipResult, int, error) {

var (
membership MembershipResult
Expand Down Expand Up @@ -114,7 +114,7 @@ func (r *Context) MembershipAllGet(projectID int) (MembershipResult, int, error)
// MembershipMultiGet gets info for multiple memberships for project with specified ID
//
// see: http://www.redmine.org/projects/redmine/wiki/Rest_Memberships#GET
func (r *Context) MembershipMultiGet(projectID int, request MembershipMultiGetRequest) (MembershipResult, int, error) {
func (r *Context) MembershipMultiGet(projectID string, request MembershipMultiGetRequest) (MembershipResult, int, error) {

var m MembershipResult

Expand All @@ -123,7 +123,7 @@ func (r *Context) MembershipMultiGet(projectID int, request MembershipMultiGetRe
urlParams.Add("limit", strconv.Itoa(request.Limit))

ur := url.URL{
Path: "/projects/" + strconv.Itoa(projectID) + "/memberships.json",
Path: "/projects/" + projectID + "/memberships.json",
RawQuery: urlParams.Encode(),
}

Expand Down Expand Up @@ -151,12 +151,12 @@ func (r *Context) MembershipSingleGet(membershipID int) (MembershipObject, int,
// MembershipAdd adds new member to project with specified ID
//
// see: http://www.redmine.org/projects/redmine/wiki/Rest_Memberships#POST
func (r *Context) MembershipAdd(projectID int, membership MembershipAddObject) (MembershipObject, int, error) {
func (r *Context) MembershipAdd(projectID string, membership MembershipAddObject) (MembershipObject, int, error) {

var m membershipSingleResult

ur := url.URL{
Path: "/projects/" + strconv.Itoa(projectID) + "/memberships.json",
Path: "/projects/" + projectID + "/memberships.json",
}

status, err := r.post(membershipAdd{Membership: membership}, &m, ur, http.StatusCreated)
Expand Down
10 changes: 5 additions & 5 deletions memberships_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ func TestMembershipCRUD(t *testing.T) {
defer testUserDetele(t, r, uCreated.ID)

pCreated := testProjectCreate(t, r, []int{})
defer testProjectDetele(t, r, pCreated.ID)
defer testProjectDetele(t, r, pCreated.Identifier)

// Add and delete
mCreated := testMembershipAdd(t, r, pCreated.ID, uCreated.ID, testMembershipRoleID1)
mCreated := testMembershipAdd(t, r, pCreated.Identifier, uCreated.ID, testMembershipRoleID1)
defer testMembershipDetele(t, r, mCreated.ID)

// Get all
testMembershipAllGet(t, r, mCreated.ID, pCreated.ID, testMembershipRoleID1)
testMembershipAllGet(t, r, mCreated.ID, pCreated.Identifier, testMembershipRoleID1)

// Update
testMembershipUpdate(t, r, mCreated.ID, testMembershipRoleID1, testMembershipRoleID2)
Expand All @@ -42,7 +42,7 @@ func TestMembershipCRUD(t *testing.T) {
testMembershipSingleGet(t, r, mCreated.ID, testMembershipRoleID2)
}

func testMembershipAdd(t *testing.T, r Context, projectID, userID, roleID int) MembershipObject {
func testMembershipAdd(t *testing.T, r Context, projectID string, userID, roleID int) MembershipObject {

m, _, err := r.MembershipAdd(projectID, MembershipAddObject{
UserID: userID,
Expand Down Expand Up @@ -79,7 +79,7 @@ func testMembershipDetele(t *testing.T, r Context, id int) {
t.Logf("Membership delete: success")
}

func testMembershipAllGet(t *testing.T, r Context, id, projectID, roleID int) {
func testMembershipAllGet(t *testing.T, r Context, id int, projectID string, roleID int) {

m, _, err := r.MembershipAllGet(projectID)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (r *Context) ProjectMultiGet(request ProjectMultiGetRequest) (ProjectResult
// * issue_categories
// * enabled_modules
// * time_entry_activities (since 3.4.0)
func (r *Context) ProjectSingleGet(id int, request ProjectSingleGetRequest) (ProjectObject, int, error) {
func (r *Context) ProjectSingleGet(id string, request ProjectSingleGetRequest) (ProjectObject, int, error) {

var p projectSingleResult

Expand All @@ -235,7 +235,7 @@ func (r *Context) ProjectSingleGet(id int, request ProjectSingleGetRequest) (Pro
urlIncludes(&urlParams, request.Includes)

ur := url.URL{
Path: "/projects/" + strconv.Itoa(id) + ".json",
Path: "/projects/" + id + ".json",
RawQuery: urlParams.Encode(),
}

Expand Down Expand Up @@ -263,10 +263,10 @@ func (r *Context) ProjectCreate(project ProjectCreateObject) (ProjectObject, int
// ProjectUpdate updates project with specified ID
//
// see: http://www.redmine.org/projects/redmine/wiki/Rest_Projects#Updating-a-project
func (r *Context) ProjectUpdate(id int, project ProjectUpdateObject) (int, error) {
func (r *Context) ProjectUpdate(id string, project ProjectUpdateObject) (int, error) {

ur := url.URL{
Path: "/projects/" + strconv.Itoa(id) + ".json",
Path: "/projects/" + id + ".json",
}

status, err := r.put(projectUpdate{Project: project}, nil, ur, http.StatusNoContent)
Expand All @@ -277,10 +277,10 @@ func (r *Context) ProjectUpdate(id int, project ProjectUpdateObject) (int, error
// ProjectDelete deletes project with specified ID
//
// see: http://www.redmine.org/projects/redmine/wiki/Rest_Projects#Deleting-a-project
func (r *Context) ProjectDelete(id int) (int, error) {
func (r *Context) ProjectDelete(id string) (int, error) {

ur := url.URL{
Path: "/projects/" + strconv.Itoa(id) + ".json",
Path: "/projects/" + id + ".json",
}

status, err := r.del(nil, nil, ur, http.StatusNoContent)
Expand Down
39 changes: 32 additions & 7 deletions projects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
testProjectIdentifier = "test_project"
)

func TestProjectsCRUD(t *testing.T) {
func TestProjectsCRUDIdentifier(t *testing.T) {

var r Context

Expand All @@ -27,14 +27,39 @@ func TestProjectsCRUD(t *testing.T) {

// Create and delete
pCreated := testProjectCreate(t, r, []int{testProjectTrackerID})
defer testProjectDetele(t, r, pCreated.ID)
defer testProjectDetele(t, r, pCreated.Identifier)

// Get
testProjectAllGet(t, r)
testProjectSingleGet(t, r, pCreated.ID)
testProjectSingleGet(t, r, pCreated.Identifier)

// Update
testProjectUpdate(t, r, pCreated.ID)
testProjectUpdate(t, r, pCreated.Identifier)
}

func TestProjectsCRUDID(t *testing.T) {

var r Context

// Get env variables
testProjectTrackerID, _ := strconv.Atoi(os.Getenv("REDMINE_TRACKER_ID"))
if testProjectTrackerID == 0 {
t.Fatal("Project test error: env variables `REDMINE_TRACKER_ID` does not set")
}

// Init Redmine context
initTest(&r, t)

// Create and delete
pCreated := testProjectCreate(t, r, []int{testProjectTrackerID})
defer testProjectDetele(t, r, strconv.Itoa(pCreated.ID))

// Get
testProjectAllGet(t, r)
testProjectSingleGet(t, r, strconv.Itoa(pCreated.ID))

// Update
testProjectUpdate(t, r, strconv.Itoa(pCreated.ID))
}

func testProjectCreate(t *testing.T, r Context, trackerIDs []int) ProjectObject {
Expand All @@ -55,7 +80,7 @@ func testProjectCreate(t *testing.T, r Context, trackerIDs []int) ProjectObject
return p
}

func testProjectUpdate(t *testing.T, r Context, id int) {
func testProjectUpdate(t *testing.T, r Context, id string) {

_, err := r.ProjectUpdate(id, ProjectUpdateObject{
Name: testProjectName2,
Expand All @@ -67,7 +92,7 @@ func testProjectUpdate(t *testing.T, r Context, id int) {
t.Logf("Project update: success")
}

func testProjectDetele(t *testing.T, r Context, id int) {
func testProjectDetele(t *testing.T, r Context, id string) {

_, err := r.ProjectDelete(id)
if err != nil {
Expand Down Expand Up @@ -99,7 +124,7 @@ func testProjectAllGet(t *testing.T, r Context) {
t.Fatal("Projects get error: can't find created project")
}

func testProjectSingleGet(t *testing.T, r Context, id int) {
func testProjectSingleGet(t *testing.T, r Context, id string) {

_, _, err := r.ProjectSingleGet(id, ProjectSingleGetRequest{
Includes: []string{"trackers", "issue_categories", "enabled_modules"},
Expand Down

0 comments on commit ddabcc9

Please sign in to comment.