add methods for brands

This commit is contained in:
diPhantxm
2023-03-23 21:55:02 +03:00
parent 6b921ad101
commit 3f1f0711c8
4 changed files with 133 additions and 1 deletions

70
ozon/brands_test.go Normal file
View File

@@ -0,0 +1,70 @@
package ozon
import (
"net/http"
"testing"
core "github.com/diphantxm/ozon-api-client"
)
func TestListCertifiedBrands(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *ListCertifiedBrandsParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&ListCertifiedBrandsParams{
Page: 0,
PageSize: 0,
},
`{
"result": {
"brand_certification": [
{
"brand_id": 135476863,
"brand_name": "Sea of Spa",
"has_certificate": false
}
],
"total": 1
}
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&ListCertifiedBrandsParams{},
`{
"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))
resp, err := c.Brands().List(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 int64(len(resp.Result.BrandCertification)) != resp.Result.Total {
t.Errorf("Length of brands in response is not equal to total field in response")
}
}
}
}