extend tests, update readme

This commit is contained in:
diPhantxm
2023-03-15 02:00:16 +03:00
parent a082200b4f
commit 396f370174
11 changed files with 268 additions and 37 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.out

View File

@@ -1,5 +1,8 @@
# Ozon API Client # Ozon Seller API Client
A Ozon API client written in Golang A Ozon Seller API client written in Golang
[![Coverage Status](https://coveralls.io/repos/github/diPhantxm/ozon-api-client/badge.svg?branch=master)](https://coveralls.io/github/diPhantxm/ozon-api-client?branch=master)
![example workflow](https://github.com/diPhantxm/ozon-api-client/actions/workflows/tests.yml/badge.svg)
[Ozon](https://ozon.ru) is a marketplace for small and medium enterprises to launch and grow their businesses in Russia. [Ozon](https://ozon.ru) is a marketplace for small and medium enterprises to launch and grow their businesses in Russia.
@@ -14,7 +17,7 @@ go get github.com/diphantxm/ozon-api-client
``` ```
A simple example on how to use this library: A simple example on how to use this library:
```Golang ```Golang
package integrations package main
import ( import (
"fmt" "fmt"
@@ -24,7 +27,7 @@ import (
"github.com/diphantxm/ozon-api-client/ozon" "github.com/diphantxm/ozon-api-client/ozon"
) )
func t() { func main() {
// Create a client with your Client-Id and Api-Key // Create a client with your Client-Id and Api-Key
// [Documentation]: https://docs.ozon.ru/api/seller/en/#tag/Auth // [Documentation]: https://docs.ozon.ru/api/seller/en/#tag/Auth
client := ozon.NewClient("my-client-id", "my-api-key") client := ozon.NewClient("my-client-id", "my-api-key")
@@ -42,5 +45,9 @@ func t() {
fmt.Printf("Barcode %s\n", d) fmt.Printf("Barcode %s\n", d)
} }
} }
```
``` ## Contribution
If you need some endpoints ASAP, create an issue and list all the endpoints. I will add them to library soon.
Or you can implement them and contribute to the project. Contribution to the project is welcome.

68
client_test.go Normal file
View File

@@ -0,0 +1,68 @@
package core
import (
"net/http"
"testing"
)
type TestRequestRequest struct {
FirstField string `json:"first_field"`
SecondField int32 `json:"second_field"`
}
type TestRequestResponse struct {
FirstField string `json:"first_header"`
SecondField struct {
Key int32 `json:"key"`
} `json:"second_header"`
ThirdField []struct {
FirstElement string `json:"first_element"`
} `json:"third_header"`
}
func TestRequest(t *testing.T) {
tests := []struct {
statusCode int
headers map[string]string
params *TestRequestRequest
response string
}{
{
http.StatusOK,
map[string]string{
"first_header": "first-value",
"second_header": "second-value",
},
&TestRequestRequest{
FirstField: "test",
SecondField: 123,
},
`{
"first_field": "first-value",
"second_field": {
"key": 12
},
"third_field": [
{
"first_element": "first-element-value"
}
]
}`,
},
}
for _, test := range tests {
c := NewMockClient(NewMockHttpHandler(test.statusCode, test.response, test.headers))
respStruct := &TestRequestResponse{}
resp, err := c.Request(http.MethodPost, "/", test.params, respStruct)
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)
}
}
}

View File

@@ -14,6 +14,7 @@ func TestGetAnalyticsData(t *testing.T) {
params *GetAnalyticsDataParams params *GetAnalyticsDataParams
response string response string
}{ }{
// Test ok
{ {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
@@ -41,6 +42,16 @@ func TestGetAnalyticsData(t *testing.T) {
"timestamp": "2021-11-25 15:19:21" "timestamp": "2021-11-25 15:19:21"
}`, }`,
}, },
{
// Test No Client-Id or Api-Key
http.StatusUnauthorized,
map[string]string{},
&GetAnalyticsDataParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
} }
for _, test := range tests { for _, test := range tests {
@@ -64,6 +75,7 @@ func TestGetStocksOnWarehouses(t *testing.T) {
params *GetStocksOnWarehousesParams params *GetStocksOnWarehousesParams
response string response string
}{ }{
// Test Ok
{ {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
@@ -87,6 +99,16 @@ func TestGetStocksOnWarehouses(t *testing.T) {
] ]
} }
}`, }`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&GetStocksOnWarehousesParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
}, },
} }

View File

@@ -14,6 +14,7 @@ func TestGetFBOShipmentsList(t *testing.T) {
params *GetFBOShipmentsListParams params *GetFBOShipmentsListParams
response string response string
}{ }{
// Test Ok
{ {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
@@ -115,6 +116,16 @@ func TestGetFBOShipmentsList(t *testing.T) {
] ]
}`, }`,
}, },
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&GetFBOShipmentsListParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
} }
for _, test := range tests { for _, test := range tests {

View File

@@ -14,6 +14,7 @@ func TestListUnprocessedShipments(t *testing.T) {
params *ListUnprocessedShipmentsParams params *ListUnprocessedShipmentsParams
response string response string
}{ }{
// Test Ok
{ {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
@@ -149,6 +150,16 @@ func TestListUnprocessedShipments(t *testing.T) {
} }
}`, }`,
}, },
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&ListUnprocessedShipmentsParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
} }
for _, test := range tests { for _, test := range tests {
@@ -172,6 +183,7 @@ func TestGetFBSShipmentsList(t *testing.T) {
params *GetFBSShipmentsListParams params *GetFBSShipmentsListParams
response string response string
}{ }{
// Test Ok
{ {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
@@ -247,6 +259,16 @@ func TestGetFBSShipmentsList(t *testing.T) {
} }
}`, }`,
}, },
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&GetFBSShipmentsListParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
} }
for _, test := range tests { for _, test := range tests {
@@ -270,6 +292,7 @@ func TestPackOrder(t *testing.T) {
params *PackOrderParams params *PackOrderParams
response string response string
}{ }{
// Test Ok
{ {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
@@ -295,6 +318,16 @@ func TestPackOrder(t *testing.T) {
] ]
}`, }`,
}, },
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&PackOrderParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
} }
for _, test := range tests { for _, test := range tests {

View File

@@ -14,6 +14,7 @@ func TestGetStocksInfo(t *testing.T) {
params *GetStocksInfoParams params *GetStocksInfoParams
response string response string
}{ }{
// Test Ok
{ {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
@@ -51,27 +52,14 @@ func TestGetStocksInfo(t *testing.T) {
} }
}`, }`,
}, },
// Test No Client-Id or Api-Key
{ {
http.StatusBadRequest, http.StatusUnauthorized,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{},
&GetStocksInfoParams{ &GetStocksInfoParams{},
Limit: 100,
LastId: "",
Filter: GetStocksInfoFilter{
OfferId: "136834",
ProductId: 214887921,
Visibility: "ALL",
},
},
`{ `{
"code": 0, "code": 16,
"details": [ "message": "Client-Id and Api-Key headers are required"
{
"typeUrl": "string",
"value": "string"
}
],
"message": "string"
}`, }`,
}, },
} }
@@ -97,6 +85,7 @@ func TestGetProductDetails(t *testing.T) {
params *GetProductDetailsParams params *GetProductDetailsParams
response string response string
}{ }{
// Test Ok
{ {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
@@ -227,21 +216,14 @@ func TestGetProductDetails(t *testing.T) {
} }
}`, }`,
}, },
// Test No Client-Id or Api-Key
{ {
http.StatusBadRequest, http.StatusUnauthorized,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{},
&GetProductDetailsParams{ &GetProductDetailsParams{},
ProductId: 137208233,
},
`{ `{
"code": 0, "code": 16,
"details": [ "message": "Client-Id and Api-Key headers are required"
{
"typeUrl": "string",
"value": "string"
}
],
"message": "string"
}`, }`,
}, },
} }
@@ -267,6 +249,7 @@ func TestUpdateStocks(t *testing.T) {
params *UpdateStocksParams params *UpdateStocksParams
response string response string
}{ }{
// Test Ok
{ {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
@@ -290,6 +273,16 @@ func TestUpdateStocks(t *testing.T) {
] ]
}`, }`,
}, },
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&UpdateStocksParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
} }
for _, test := range tests { for _, test := range tests {
@@ -313,6 +306,7 @@ func TestStocksInSellersWarehouse(t *testing.T) {
params *StocksInSellersWarehouseParams params *StocksInSellersWarehouseParams
response string response string
}{ }{
// Test Ok
{ {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
@@ -332,6 +326,16 @@ func TestStocksInSellersWarehouse(t *testing.T) {
] ]
}`, }`,
}, },
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&StocksInSellersWarehouseParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
} }
for _, test := range tests { for _, test := range tests {
@@ -355,6 +359,7 @@ func TestUpdatePrices(t *testing.T) {
params *UpdatePricesParams params *UpdatePricesParams
response string response string
}{ }{
// Test Ok
{ {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
@@ -381,6 +386,16 @@ func TestUpdatePrices(t *testing.T) {
] ]
}`, }`,
}, },
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&UpdatePricesParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
} }
for _, test := range tests { for _, test := range tests {
@@ -404,6 +419,7 @@ func TestUpdateQuantityStockProducts(t *testing.T) {
params *UpdateQuantityStockProductsParams params *UpdateQuantityStockProductsParams
response string response string
}{ }{
// Test Ok
{ {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
@@ -429,6 +445,16 @@ func TestUpdateQuantityStockProducts(t *testing.T) {
] ]
}`, }`,
}, },
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&UpdateQuantityStockProductsParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
} }
for _, test := range tests { for _, test := range tests {
@@ -452,6 +478,7 @@ func TestCreateOrUpdateProduct(t *testing.T) {
params *CreateOrUpdateProductParams params *CreateOrUpdateProductParams
response string response string
}{ }{
// Test Ok
{ {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
@@ -533,6 +560,16 @@ func TestCreateOrUpdateProduct(t *testing.T) {
} }
}`, }`,
}, },
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&CreateOrUpdateProductParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
} }
for _, test := range tests { for _, test := range tests {
@@ -556,6 +593,7 @@ func TestGetListOfProducts(t *testing.T) {
params *GetListOfProductsParams params *GetListOfProductsParams
response string response string
}{ }{
// Test Ok
{ {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
@@ -581,6 +619,16 @@ func TestGetListOfProducts(t *testing.T) {
} }
}`, }`,
}, },
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&GetListOfProductsParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
} }
for _, test := range tests { for _, test := range tests {

View File

@@ -13,6 +13,7 @@ func TestGetAvailablePromotions(t *testing.T) {
headers map[string]string headers map[string]string
response string response string
}{ }{
// Test Ok
{ {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
@@ -39,6 +40,15 @@ func TestGetAvailablePromotions(t *testing.T) {
] ]
}`, }`,
}, },
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
} }
for _, test := range tests { for _, test := range tests {

View File

@@ -13,6 +13,7 @@ func TestGetCurrentRatingInfo(t *testing.T) {
headers map[string]string headers map[string]string
response string response string
}{ }{
// Test Ok
{ {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
@@ -41,6 +42,15 @@ func TestGetCurrentRatingInfo(t *testing.T) {
"premium": true "premium": true
}`, }`,
}, },
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
} }
for _, test := range tests { for _, test := range tests {
@@ -64,6 +74,7 @@ func TestGetRatingInfoForPeriod(t *testing.T) {
params *GetSellerRatingInfoForPeriodParams params *GetSellerRatingInfoForPeriodParams
response string response string
}{ }{
// Test Ok
{ {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
@@ -108,6 +119,16 @@ func TestGetRatingInfoForPeriod(t *testing.T) {
] ]
}`, }`,
}, },
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&GetSellerRatingInfoForPeriodParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
} }
for _, test := range tests { for _, test := range tests {

View File

@@ -13,6 +13,7 @@ func TestGetListOfWarehouses(t *testing.T) {
headers map[string]string headers map[string]string
response string response string
}{ }{
// Test Ok
{ {
http.StatusOK, http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
@@ -41,6 +42,15 @@ func TestGetListOfWarehouses(t *testing.T) {
] ]
}`, }`,
}, },
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
} }
for _, test := range tests { for _, test := range tests {