Skip to content

Commit

Permalink
Merge pull request #274 from ctreminiom/fk_servicedesk_id_fix
Browse files Browse the repository at this point in the history
Replace service desk id with string instead of int
  • Loading branch information
ctreminiom authored Jun 30, 2024
2 parents c69afc3 + becd753 commit 5f6b832
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
19 changes: 10 additions & 9 deletions jira/sm/internal/service_desk_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"bytes"
"context"
"fmt"
model "github.com/ctreminiom/go-atlassian/pkg/infra/models"
"github.com/ctreminiom/go-atlassian/service"
"github.com/ctreminiom/go-atlassian/service/sm"
"io"
"mime/multipart"
"net/http"
"net/url"
"strconv"

model "github.com/ctreminiom/go-atlassian/pkg/infra/models"
"github.com/ctreminiom/go-atlassian/service"
"github.com/ctreminiom/go-atlassian/service/sm"
)

func NewServiceDeskService(client service.Connector, version string, queue *QueueService) (*ServiceDeskService, error) {
Expand Down Expand Up @@ -49,7 +50,7 @@ func (s *ServiceDeskService) Gets(ctx context.Context, start, limit int) (*model
// GET /rest/servicedeskapi/servicedesk/{serviceDeskId}
//
// https://docs.go-atlassian.io/jira-service-management-cloud/request/service-desk#get-service-desk-by-id
func (s *ServiceDeskService) Get(ctx context.Context, serviceDeskID int) (*model.ServiceDeskScheme, *model.ResponseScheme, error) {
func (s *ServiceDeskService) Get(ctx context.Context, serviceDeskID string) (*model.ServiceDeskScheme, *model.ResponseScheme, error) {
return s.internalClient.Get(ctx, serviceDeskID)
}

Expand All @@ -58,7 +59,7 @@ func (s *ServiceDeskService) Get(ctx context.Context, serviceDeskID int) (*model
// POST /rest/servicedeskapi/servicedesk/{serviceDeskId}/attachTemporaryFile
//
// https://docs.go-atlassian.io/jira-service-management-cloud/request/service-desk#attach-temporary-file
func (s *ServiceDeskService) Attach(ctx context.Context, serviceDeskID int, fileName string, file io.Reader) (*model.ServiceDeskTemporaryFileScheme, *model.ResponseScheme, error) {
func (s *ServiceDeskService) Attach(ctx context.Context, serviceDeskID string, fileName string, file io.Reader) (*model.ServiceDeskTemporaryFileScheme, *model.ResponseScheme, error) {
return s.internalClient.Attach(ctx, serviceDeskID, fileName, file)
}

Expand Down Expand Up @@ -89,9 +90,9 @@ func (i *internalServiceDeskImpl) Gets(ctx context.Context, start, limit int) (*
return page, res, nil
}

func (i *internalServiceDeskImpl) Get(ctx context.Context, serviceDeskID int) (*model.ServiceDeskScheme, *model.ResponseScheme, error) {
func (i *internalServiceDeskImpl) Get(ctx context.Context, serviceDeskID string) (*model.ServiceDeskScheme, *model.ResponseScheme, error) {

if serviceDeskID == 0 {
if serviceDeskID == "" {
return nil, nil, model.ErrNoServiceDeskIDError
}

Expand All @@ -111,9 +112,9 @@ func (i *internalServiceDeskImpl) Get(ctx context.Context, serviceDeskID int) (*
return serviceDesk, res, nil
}

func (i *internalServiceDeskImpl) Attach(ctx context.Context, serviceDeskID int, fileName string, file io.Reader) (*model.ServiceDeskTemporaryFileScheme, *model.ResponseScheme, error) {
func (i *internalServiceDeskImpl) Attach(ctx context.Context, serviceDeskID string, fileName string, file io.Reader) (*model.ServiceDeskTemporaryFileScheme, *model.ResponseScheme, error) {

if serviceDeskID == 0 {
if serviceDeskID == "" {
return nil, nil, model.ErrNoServiceDeskIDError
}

Expand Down
32 changes: 17 additions & 15 deletions jira/sm/internal/service_desk_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ package internal
import (
"context"
"errors"
model "github.com/ctreminiom/go-atlassian/pkg/infra/models"
"github.com/ctreminiom/go-atlassian/service"
"github.com/ctreminiom/go-atlassian/service/mocks"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"io"
"net/http"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

model "github.com/ctreminiom/go-atlassian/pkg/infra/models"
"github.com/ctreminiom/go-atlassian/service"
"github.com/ctreminiom/go-atlassian/service/mocks"
)

func Test_internalServiceDeskImpl_Gets(t *testing.T) {
Expand Down Expand Up @@ -156,7 +158,7 @@ func Test_internalServiceDeskImpl_Get(t *testing.T) {

type args struct {
ctx context.Context
serviceDeskID int
serviceDeskID string
}

testCases := []struct {
Expand All @@ -171,7 +173,7 @@ func Test_internalServiceDeskImpl_Get(t *testing.T) {
name: "when the parameters are correct",
args: args{
ctx: context.Background(),
serviceDeskID: 10001,
serviceDeskID: "10001",
},
on: func(fields *fields) {

Expand All @@ -198,7 +200,7 @@ func Test_internalServiceDeskImpl_Get(t *testing.T) {
name: "when the http call cannot be executed",
args: args{
ctx: context.Background(),
serviceDeskID: 10001,
serviceDeskID: "10001",
},
on: func(fields *fields) {

Expand Down Expand Up @@ -227,7 +229,7 @@ func Test_internalServiceDeskImpl_Get(t *testing.T) {
name: "when the request cannot be created",
args: args{
ctx: context.Background(),
serviceDeskID: 10001,
serviceDeskID: "10001",
},
on: func(fields *fields) {

Expand Down Expand Up @@ -305,7 +307,7 @@ func Test_internalServiceDeskImpl_Attach(t *testing.T) {

type args struct {
ctx context.Context
serviceDeskID int
serviceDeskID string
fileName string
file io.Reader
}
Expand All @@ -322,7 +324,7 @@ func Test_internalServiceDeskImpl_Attach(t *testing.T) {
name: "when the parameters are correct",
args: args{
ctx: context.Background(),
serviceDeskID: 10001,
serviceDeskID: "10001",
fileName: "LICENSE",
file: fileMocked,
},
Expand Down Expand Up @@ -351,7 +353,7 @@ func Test_internalServiceDeskImpl_Attach(t *testing.T) {
name: "when the http call cannot be executed",
args: args{
ctx: context.Background(),
serviceDeskID: 10001,
serviceDeskID: "10001",
fileName: "LICENSE",
file: fileMocked,
},
Expand Down Expand Up @@ -382,7 +384,7 @@ func Test_internalServiceDeskImpl_Attach(t *testing.T) {
name: "when the request cannot be created",
args: args{
ctx: context.Background(),
serviceDeskID: 10001,
serviceDeskID: "10001",
fileName: "LICENSE",
file: fileMocked,
},
Expand Down Expand Up @@ -417,7 +419,7 @@ func Test_internalServiceDeskImpl_Attach(t *testing.T) {
name: "when the file name is not provided",
args: args{
ctx: context.Background(),
serviceDeskID: 10001,
serviceDeskID: "10001",
},
Err: model.ErrNoFileNameError,
wantErr: true,
Expand All @@ -427,7 +429,7 @@ func Test_internalServiceDeskImpl_Attach(t *testing.T) {
name: "when the file reader is not provided",
args: args{
ctx: context.Background(),
serviceDeskID: 10001,
serviceDeskID: "10001",
fileName: "LICENSE",
},
Err: model.ErrNoFileReaderError,
Expand Down
7 changes: 4 additions & 3 deletions service/sm/service_desk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package sm

import (
"context"
model "github.com/ctreminiom/go-atlassian/pkg/infra/models"
"io"

model "github.com/ctreminiom/go-atlassian/pkg/infra/models"
)

type ServiceDeskConnector interface {
Expand All @@ -24,12 +25,12 @@ type ServiceDeskConnector interface {
// GET /rest/servicedeskapi/servicedesk/{serviceDeskId}
//
// https://docs.go-atlassian.io/jira-service-management-cloud/request/service-desk#get-service-desk-by-id
Get(ctx context.Context, serviceDeskID int) (*model.ServiceDeskScheme, *model.ResponseScheme, error)
Get(ctx context.Context, serviceDeskID string) (*model.ServiceDeskScheme, *model.ResponseScheme, error)

// Attach one temporary attachments to a service desk
//
// POST /rest/servicedeskapi/servicedesk/{serviceDeskId}/attachTemporaryFile
//
// https://docs.go-atlassian.io/jira-service-management-cloud/request/service-desk#attach-temporary-file
Attach(ctx context.Context, serviceDeskID int, fileName string, file io.Reader) (*model.ServiceDeskTemporaryFileScheme, *model.ResponseScheme, error)
Attach(ctx context.Context, serviceDeskID string, fileName string, file io.Reader) (*model.ServiceDeskTemporaryFileScheme, *model.ResponseScheme, error)
}

0 comments on commit 5f6b832

Please sign in to comment.