Update November 30, 2023 (#50)

Method for RFBS returns operations
This commit is contained in:
Kirill
2023-11-30 18:16:34 +03:00
committed by GitHub
parent ba8f4ca1b2
commit af7c167edf
3 changed files with 847 additions and 0 deletions

View File

@@ -189,3 +189,417 @@ func TestGetFBSReturns(t *testing.T) {
}
}
}
func TestGetRFBSReturns(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *GetRFBSReturnsParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GetRFBSReturnsParams{
LastId: 999,
Limit: 555,
Filter: GetRFBSReturnsFilter{
OfferId: "123",
PostingNumber: "111",
GroupState: []RFBSReturnsGroupState{RFBSReturnsGroupStateAll},
CreatedAt: GetRFBSReturnsFilterCreatedAt{
From: core.TimeFromString(t, "2006-01-02T15:04:05Z", "2019-08-24T14:15:22Z"),
To: core.TimeFromString(t, "2006-01-02T15:04:05Z", "2019-08-24T14:15:22Z"),
},
},
},
`{
"returns": {
"client_name": "string",
"created_at": "2019-08-24T14:15:22Z",
"order_number": "string",
"posting_number": "111",
"product": {
"name": "string",
"offer_id": "123",
"currency_code": "string",
"price": "string",
"sku": 123
},
"return_id": 0,
"return_number": "string",
"state": {
"group_state": "All",
"money_return_state_name": "string",
"state": "string",
"state_name": "string"
}
}
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&GetRFBSReturnsParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
resp, err := c.Returns().GetRFBSReturns(ctx, test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
if resp.StatusCode == http.StatusOK {
if resp.Returns.Product.OfferId != test.params.Filter.OfferId {
t.Errorf("expected offer ID %s, but got: %s", test.params.Filter.OfferId, resp.Returns.Product.OfferId)
}
if resp.Returns.PostingNumber != test.params.Filter.PostingNumber {
t.Errorf("expected posting number %s, but got: %s", test.params.Filter.PostingNumber, resp.Returns.PostingNumber)
}
if resp.Returns.State.GroupState != test.params.Filter.GroupState[0] {
t.Errorf("expected group state %s, but got: %s", test.params.Filter.GroupState[0], resp.Returns.State.GroupState)
}
}
}
}
func TestGetRFBSReturn(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *GetRFBSReturnParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GetRFBSReturnParams{
ReturnId: 123,
},
`{
"returns": {
"available_actions": [
{
"id": 0,
"name": "string"
}
],
"client_name": "string",
"client_photo": [
"string"
],
"client_return_method_type": {
"id": 0,
"name": "string"
},
"comment": "string",
"created_at": "2019-08-24T14:15:22Z",
"order_number": "string",
"posting_number": "string",
"product": {
"name": "string",
"offer_id": "string",
"currency_code": "string",
"price": "string",
"sku": 0
},
"rejection_comment": "string",
"rejection_reason": [
{
"hint": "string",
"id": 0,
"is_comment_required": true,
"name": "string"
}
],
"return_method_description": "string",
"return_number": "string",
"return_reason": {
"id": 0,
"is_defect": true,
"name": "string"
},
"ru_post_tracking_number": "string",
"state": {
"state": "string",
"state_name": "string"
},
"warehouse_id": 0
}
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&GetRFBSReturnParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
resp, err := c.Returns().GetRFBSReturn(ctx, test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}
func TestRejectRFBSReturn(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *RejectRFBSReturnParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&RejectRFBSReturnParams{
ReturnId: 123,
Comment: "No comment",
RejectionReasonId: 111,
},
`{}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&RejectRFBSReturnParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
resp, err := c.Returns().RejectRFBSReturn(ctx, test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}
func TestCompensateRFBSreturn(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *CompensateRFBSReturnParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&CompensateRFBSReturnParams{
ReturnId: 123,
CompensationAmount: "11",
},
`{}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&CompensateRFBSReturnParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
resp, err := c.Returns().CompensateRFBSReturn(ctx, test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}
func TestApproveRFBSReturn(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *ApproveRFBSReturnParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&ApproveRFBSReturnParams{
ReturnId: 123,
ReturnMethodDescription: "some description",
},
`{}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&ApproveRFBSReturnParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
resp, err := c.Returns().ApproveRFBSReturn(ctx, test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}
func TestReceiveRFBSReturn(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *ReceiveRFBSReturnParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&ReceiveRFBSReturnParams{
ReturnId: 123,
},
`{}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&ReceiveRFBSReturnParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
resp, err := c.Returns().ReceiveRFBSReturn(ctx, test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}
func TestRefundRFBS(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *RefundRFBSParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&RefundRFBSParams{
ReturnId: 123,
ReturnForBackWay: 111,
},
`{}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&RefundRFBSParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
resp, err := c.Returns().RefundRFBS(ctx, test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}