-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from RyaWcksn/DEV-0001
Dev 0001
- Loading branch information
Showing
17 changed files
with
437 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/RyaWcksn/ecommerce/dto" | ||
"github.com/RyaWcksn/ecommerce/pkgs/datetime" | ||
) | ||
|
||
// GetSellerOrdersHandler implements IHandler | ||
func (h *HandlerImpl) GetSellerOrdersHandler(w http.ResponseWriter, r *http.Request) error { | ||
ctx := r.Context() | ||
|
||
orders, err := h.serviceImpl.GetSellerOrderList(ctx) | ||
if err != nil { | ||
h.log.Errorf("[ERR] Error from service layer := %v", err) | ||
return err | ||
} | ||
|
||
resp := dto.OrdersResponse{ | ||
Code: http.StatusOK, | ||
Message: "ok", | ||
ResponseTime: datetime.GetDateString(), | ||
Orders: *orders, | ||
} | ||
|
||
return ResponseJson(w, resp) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package handlers | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/RyaWcksn/ecommerce/apis/v1/services" | ||
"github.com/RyaWcksn/ecommerce/constants" | ||
"github.com/RyaWcksn/ecommerce/entities" | ||
"github.com/RyaWcksn/ecommerce/pkgs/logger" | ||
"github.com/golang/mock/gomock" | ||
) | ||
|
||
func TestHandlerImpl_GetSellerOrdersHandler(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
s := services.NewMockIService(ctrl) | ||
l := logger.New("", "", "") | ||
r := httptest.NewRecorder() | ||
type args struct { | ||
w http.ResponseWriter | ||
r *http.Request | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantMock func() | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "Success", | ||
args: args{ | ||
w: r, | ||
r: func() *http.Request { | ||
req := httptest.NewRequest( | ||
http.MethodGet, constants.ListOrderSellerEndpoint, nil, | ||
) | ||
ctx := context.Background() | ||
req.Header.Add("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRob3JpemVkIjp0cnVlLCJlbWFpbCI6InVzZXJAbWFpbC5jb20iLCJleHAiOjE2ODA4NDA2MTAsImlkIjoxLCJyb2xlIjoic2VsbGVyIn0.BqlpOmIFBGlWZYKvoRqPhD8_q4Smwob0QV47vIVz0QU") | ||
ctx = context.WithValue(ctx, "id", "1") | ||
return req.WithContext(ctx) | ||
}(), | ||
}, | ||
wantMock: func() { | ||
s.EXPECT().GetSellerOrderList(gomock.Any()).Return( | ||
&[]entities.Order{ | ||
{ | ||
Id: 1, | ||
Buyer: 2, | ||
Seller: 1, | ||
DeliverySource: "Source", | ||
DeliveryDestination: "Destination", | ||
Items: "Items", | ||
Quantity: 4, | ||
Price: "180000", | ||
TotalPrice: "180000", | ||
Status: entities.OrderStatus{ | ||
Message: constants.PendingMessage, | ||
Status: constants.Pending, | ||
}, | ||
}, | ||
}, nil, | ||
) | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt.wantMock() | ||
t.Run(tt.name, func(t *testing.T) { | ||
h := NewHandlerImpl(s, l) | ||
if err := h.GetSellerOrdersHandler(tt.args.w, tt.args.r); (err != nil) != tt.wantErr { | ||
t.Errorf("HandlerImpl.GetSellerOrdersHandler() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.