Skip to content

Commit

Permalink
Merge pull request #224 from ctreminiom/feature/jira-module-http-impr…
Browse files Browse the repository at this point in the history
…ovements

Feature/jira module http improvements
  • Loading branch information
ctreminiom authored Jul 24, 2023
2 parents 98af35b + 5d47859 commit 9db20ff
Show file tree
Hide file tree
Showing 153 changed files with 5,145 additions and 7,501 deletions.
13 changes: 4 additions & 9 deletions jira/internal/announcement_banner_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/http"
)

func NewAnnouncementBannerService(client service.Client, version string) *AnnouncementBannerService {
func NewAnnouncementBannerService(client service.Connector, version string) *AnnouncementBannerService {

return &AnnouncementBannerService{
internalClient: &internalAnnouncementBannerImpl{c: client, version: version},
Expand Down Expand Up @@ -39,15 +39,15 @@ func (a *AnnouncementBannerService) Update(ctx context.Context, payload *model.A
}

type internalAnnouncementBannerImpl struct {
c service.Client
c service.Connector
version string
}

func (i *internalAnnouncementBannerImpl) Get(ctx context.Context) (*model.AnnouncementBannerScheme, *model.ResponseScheme, error) {

endpoint := fmt.Sprintf("rest/api/%v/announcementBanner", i.version)

request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint, nil)
request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint, "", nil)
if err != nil {
return nil, nil, err
}
Expand All @@ -63,14 +63,9 @@ func (i *internalAnnouncementBannerImpl) Get(ctx context.Context) (*model.Announ

func (i *internalAnnouncementBannerImpl) Update(ctx context.Context, payload *model.AnnouncementBannerPayloadScheme) (*model.ResponseScheme, error) {

reader, err := i.c.TransformStructToReader(payload)
if err != nil {
return nil, err
}

endpoint := fmt.Sprintf("rest/api/%v/announcementBanner", i.version)

request, err := i.c.NewRequest(ctx, http.MethodPut, endpoint, reader)
request, err := i.c.NewRequest(ctx, http.MethodPut, endpoint, "", payload)
if err != nil {
return nil, err
}
Expand Down
53 changes: 22 additions & 31 deletions jira/internal/announcement_banner_impl_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package internal

import (
"bytes"
"context"
"errors"
model "github.com/ctreminiom/go-atlassian/pkg/infra/models"
Expand All @@ -15,7 +14,7 @@ import (
func Test_internalAnnouncementBannerImpl_Get(t *testing.T) {

type fields struct {
c service.Client
c service.Connector
version string
}

Expand All @@ -38,12 +37,13 @@ func Test_internalAnnouncementBannerImpl_Get(t *testing.T) {
},
fields: fields{version: "2"},
on: func(fields *fields) {
client := mocks.NewClient(t)
client := mocks.NewConnector(t)

client.On("NewRequest",
context.Background(),
http.MethodGet,
"rest/api/2/announcementBanner",
"",
nil).
Return(&http.Request{}, nil)

Expand All @@ -63,12 +63,13 @@ func Test_internalAnnouncementBannerImpl_Get(t *testing.T) {
},
fields: fields{version: "3"},
on: func(fields *fields) {
client := mocks.NewClient(t)
client := mocks.NewConnector(t)

client.On("NewRequest",
context.Background(),
http.MethodGet,
"rest/api/3/announcementBanner",
"",
nil).
Return(&http.Request{}, nil)

Expand All @@ -88,12 +89,13 @@ func Test_internalAnnouncementBannerImpl_Get(t *testing.T) {
ctx: context.Background(),
},
on: func(fields *fields) {
client := mocks.NewClient(t)
client := mocks.NewConnector(t)

client.On("NewRequest",
context.Background(),
http.MethodGet,
"rest/api/2/announcementBanner",
"",
nil).
Return(&http.Request{}, errors.New("unable to create the http request"))

Expand All @@ -110,12 +112,13 @@ func Test_internalAnnouncementBannerImpl_Get(t *testing.T) {
ctx: context.Background(),
},
on: func(fields *fields) {
client := mocks.NewClient(t)
client := mocks.NewConnector(t)

client.On("NewRequest",
context.Background(),
http.MethodGet,
"rest/api/2/announcementBanner",
"",
nil).
Return(&http.Request{}, nil)

Expand Down Expand Up @@ -170,7 +173,7 @@ func Test_internalAnnouncementBannerImpl_Update(t *testing.T) {
}

type fields struct {
c service.Client
c service.Connector
version string
}

Expand All @@ -195,17 +198,14 @@ func Test_internalAnnouncementBannerImpl_Update(t *testing.T) {
},
fields: fields{version: "2"},
on: func(fields *fields) {
client := mocks.NewClient(t)

client.On("TransformStructToReader",
payloadMocked).
Return(bytes.NewReader([]byte{}), nil)
client := mocks.NewConnector(t)

client.On("NewRequest",
context.Background(),
http.MethodPut,
"rest/api/2/announcementBanner",
bytes.NewReader([]byte{})).
"",
payloadMocked).
Return(&http.Request{}, nil)

client.On("Call",
Expand All @@ -225,17 +225,14 @@ func Test_internalAnnouncementBannerImpl_Update(t *testing.T) {
},
fields: fields{version: "3"},
on: func(fields *fields) {
client := mocks.NewClient(t)

client.On("TransformStructToReader",
payloadMocked).
Return(bytes.NewReader([]byte{}), nil)
client := mocks.NewConnector(t)

client.On("NewRequest",
context.Background(),
http.MethodPut,
"rest/api/3/announcementBanner",
bytes.NewReader([]byte{})).
"",
payloadMocked).
Return(&http.Request{}, nil)

client.On("Call",
Expand All @@ -255,17 +252,14 @@ func Test_internalAnnouncementBannerImpl_Update(t *testing.T) {
payload: payloadMocked,
},
on: func(fields *fields) {
client := mocks.NewClient(t)

client.On("TransformStructToReader",
payloadMocked).
Return(bytes.NewReader([]byte{}), nil)
client := mocks.NewConnector(t)

client.On("NewRequest",
context.Background(),
http.MethodPut,
"rest/api/2/announcementBanner",
bytes.NewReader([]byte{})).
"",
payloadMocked).
Return(&http.Request{}, errors.New("unable to create the http request"))

fields.c = client
Expand All @@ -282,17 +276,14 @@ func Test_internalAnnouncementBannerImpl_Update(t *testing.T) {
payload: payloadMocked,
},
on: func(fields *fields) {
client := mocks.NewClient(t)

client.On("TransformStructToReader",
payloadMocked).
Return(bytes.NewReader([]byte{}), nil)
client := mocks.NewConnector(t)

client.On("NewRequest",
context.Background(),
http.MethodPut,
"rest/api/2/announcementBanner",
bytes.NewReader([]byte{})).
"",
payloadMocked).
Return(&http.Request{}, nil)

client.On("Call",
Expand Down
8 changes: 4 additions & 4 deletions jira/internal/application_role_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/http"
)

func NewApplicationRoleService(client service.Client, version string) (*ApplicationRoleService, error) {
func NewApplicationRoleService(client service.Connector, version string) (*ApplicationRoleService, error) {

if version == "" {
return nil, model.ErrNoVersionProvided
Expand Down Expand Up @@ -45,15 +45,15 @@ func (a *ApplicationRoleService) Get(ctx context.Context, key string) (*model.Ap
}

type internalApplicationRoleImpl struct {
c service.Client
c service.Connector
version string
}

func (i *internalApplicationRoleImpl) Gets(ctx context.Context) ([]*model.ApplicationRoleScheme, *model.ResponseScheme, error) {

endpoint := fmt.Sprintf("rest/api/%v/applicationrole", i.version)

request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint, nil)
request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint, "", nil)
if err != nil {
return nil, nil, err
}
Expand All @@ -75,7 +75,7 @@ func (i *internalApplicationRoleImpl) Get(ctx context.Context, key string) (*mod

endpoint := fmt.Sprintf("rest/api/%v/applicationrole/%v", i.version, key)

request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint, nil)
request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint, "", nil)
if err != nil {
return nil, nil, err
}
Expand Down
Loading

0 comments on commit 9db20ff

Please sign in to comment.