708 lines
		
	
	
		
			15 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			708 lines
		
	
	
		
			15 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package ozon
 | 
						||
 | 
						||
import (
 | 
						||
	"net/http"
 | 
						||
	"testing"
 | 
						||
	"time"
 | 
						||
 | 
						||
	core "github.com/diphantxm/ozon-api-client"
 | 
						||
)
 | 
						||
 | 
						||
func TestListOfAccordanceTypes(t *testing.T) {
 | 
						||
	t.Parallel()
 | 
						||
 | 
						||
	tests := []struct {
 | 
						||
		statusCode int
 | 
						||
		headers    map[string]string
 | 
						||
		response   string
 | 
						||
	}{
 | 
						||
		// Test Ok
 | 
						||
		{
 | 
						||
			http.StatusOK,
 | 
						||
			map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
						||
			`{
 | 
						||
				"result": {
 | 
						||
				  "base": [
 | 
						||
					{
 | 
						||
					  "code": "string",
 | 
						||
					  "title": "string"
 | 
						||
					}
 | 
						||
				  ],
 | 
						||
				  "hazard": [
 | 
						||
					{
 | 
						||
					  "code": "string",
 | 
						||
					  "title": "string"
 | 
						||
					}
 | 
						||
				  ]
 | 
						||
				}
 | 
						||
			}`,
 | 
						||
		},
 | 
						||
		// 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 {
 | 
						||
		c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
 | 
						||
 | 
						||
		resp, err := c.Certificates().ListOfAccordanceTypes()
 | 
						||
		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 TestDirectoryOfDocumentTypes(t *testing.T) {
 | 
						||
	t.Parallel()
 | 
						||
 | 
						||
	tests := []struct {
 | 
						||
		statusCode int
 | 
						||
		headers    map[string]string
 | 
						||
		response   string
 | 
						||
	}{
 | 
						||
		// Test Ok
 | 
						||
		{
 | 
						||
			http.StatusOK,
 | 
						||
			map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
						||
			`{
 | 
						||
				"result": [
 | 
						||
				  {
 | 
						||
					"name": "Сертификат соответствия",
 | 
						||
					"value": "certificate_of_conformity"
 | 
						||
				  },
 | 
						||
				  {
 | 
						||
					"name": "Декларация",
 | 
						||
					"value": "declaration"
 | 
						||
				  },
 | 
						||
				  {
 | 
						||
					"name": "Свидетельство о гос регистрации",
 | 
						||
					"value": "certificate_of_registration"
 | 
						||
				  },
 | 
						||
				  {
 | 
						||
					"name": "Регистрационное удостоверение",
 | 
						||
					"value": "registration_certificate"
 | 
						||
				  },
 | 
						||
				  {
 | 
						||
					"name": "Отказное письмо",
 | 
						||
					"value": "refused_letter"
 | 
						||
				  }
 | 
						||
				]
 | 
						||
			}`,
 | 
						||
		},
 | 
						||
		// 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 {
 | 
						||
		c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
 | 
						||
 | 
						||
		resp, err := c.Certificates().DirectoryOfDocumentTypes()
 | 
						||
		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 TestListOfCertifiedCategories(t *testing.T) {
 | 
						||
	t.Parallel()
 | 
						||
 | 
						||
	tests := []struct {
 | 
						||
		statusCode int
 | 
						||
		headers    map[string]string
 | 
						||
		params     *ListOfCertifiedCategoriesParams
 | 
						||
		response   string
 | 
						||
	}{
 | 
						||
		// Test Ok
 | 
						||
		{
 | 
						||
			http.StatusOK,
 | 
						||
			map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
						||
			&ListOfCertifiedCategoriesParams{
 | 
						||
				Page:     1,
 | 
						||
				PageSize: 100,
 | 
						||
			},
 | 
						||
			`{
 | 
						||
				"result": {
 | 
						||
				  "certification": [
 | 
						||
					{
 | 
						||
					  "is_required": true,
 | 
						||
					  "category_name": "Витаминно-минеральные комплексы для взрослых"
 | 
						||
					}
 | 
						||
				  ],
 | 
						||
				  "total": 1
 | 
						||
				}
 | 
						||
			}`,
 | 
						||
		},
 | 
						||
		// Test No Client-Id or Api-Key
 | 
						||
		{
 | 
						||
			http.StatusUnauthorized,
 | 
						||
			map[string]string{},
 | 
						||
			&ListOfCertifiedCategoriesParams{},
 | 
						||
			`{
 | 
						||
				"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.Certificates().ListOfCertifiedCategories(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 TestLinkCertificateToProduct(t *testing.T) {
 | 
						||
	t.Parallel()
 | 
						||
 | 
						||
	tests := []struct {
 | 
						||
		statusCode int
 | 
						||
		headers    map[string]string
 | 
						||
		params     *LinkCertificateToProductParams
 | 
						||
		response   string
 | 
						||
	}{
 | 
						||
		// Test Ok
 | 
						||
		{
 | 
						||
			http.StatusOK,
 | 
						||
			map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
						||
			&LinkCertificateToProductParams{
 | 
						||
				CertificateId: 50058,
 | 
						||
				ProductId:     []int64{290},
 | 
						||
			},
 | 
						||
			`{
 | 
						||
				"result": true
 | 
						||
			}`,
 | 
						||
		},
 | 
						||
		// Test No Client-Id or Api-Key
 | 
						||
		{
 | 
						||
			http.StatusUnauthorized,
 | 
						||
			map[string]string{},
 | 
						||
			&LinkCertificateToProductParams{},
 | 
						||
			`{
 | 
						||
				"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.Certificates().LinkToProduct(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 TestDeleteCertificate(t *testing.T) {
 | 
						||
	t.Parallel()
 | 
						||
 | 
						||
	tests := []struct {
 | 
						||
		statusCode int
 | 
						||
		headers    map[string]string
 | 
						||
		params     *DeleteCertificateParams
 | 
						||
		response   string
 | 
						||
	}{
 | 
						||
		// Test Ok
 | 
						||
		{
 | 
						||
			http.StatusOK,
 | 
						||
			map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
						||
			&DeleteCertificateParams{
 | 
						||
				CertificateId: 0,
 | 
						||
			},
 | 
						||
			`{
 | 
						||
				"result": {
 | 
						||
				  "is_delete": true,
 | 
						||
				  "error_message": "string"
 | 
						||
				}
 | 
						||
			}`,
 | 
						||
		},
 | 
						||
		// Test No Client-Id or Api-Key
 | 
						||
		{
 | 
						||
			http.StatusUnauthorized,
 | 
						||
			map[string]string{},
 | 
						||
			&DeleteCertificateParams{},
 | 
						||
			`{
 | 
						||
				"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.Certificates().Delete(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 TestGetCertificateInfo(t *testing.T) {
 | 
						||
	t.Parallel()
 | 
						||
 | 
						||
	tests := []struct {
 | 
						||
		statusCode int
 | 
						||
		headers    map[string]string
 | 
						||
		params     *GetCertificateInfoParams
 | 
						||
		response   string
 | 
						||
	}{
 | 
						||
		// Test Ok
 | 
						||
		{
 | 
						||
			http.StatusOK,
 | 
						||
			map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
						||
			&GetCertificateInfoParams{
 | 
						||
				CertificateNumber: "certificate number",
 | 
						||
			},
 | 
						||
			`{
 | 
						||
				"result": {
 | 
						||
				  "certificate_id": 0,
 | 
						||
				  "certificate_number": "certificate number",
 | 
						||
				  "certificate_name": "string",
 | 
						||
				  "type_code": "string",
 | 
						||
				  "status_code": "string",
 | 
						||
				  "accordance_type_code": "string",
 | 
						||
				  "rejection_reason_code": "string",
 | 
						||
				  "verification_comment": "string",
 | 
						||
				  "issue_date": "2019-08-24T14:15:22Z",
 | 
						||
				  "expire_date": "2019-08-24T14:15:22Z",
 | 
						||
				  "products_count": 0
 | 
						||
				}
 | 
						||
			}`,
 | 
						||
		},
 | 
						||
		// Test No Client-Id or Api-Key
 | 
						||
		{
 | 
						||
			http.StatusUnauthorized,
 | 
						||
			map[string]string{},
 | 
						||
			&GetCertificateInfoParams{},
 | 
						||
			`{
 | 
						||
				"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.Certificates().GetInfo(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.Result.CertificateNumber != test.params.CertificateNumber {
 | 
						||
				t.Errorf("Certificate numbers in request and response are not equal")
 | 
						||
			}
 | 
						||
		}
 | 
						||
	}
 | 
						||
}
 | 
						||
 | 
						||
func TestListCertificates(t *testing.T) {
 | 
						||
	t.Parallel()
 | 
						||
 | 
						||
	tests := []struct {
 | 
						||
		statusCode int
 | 
						||
		headers    map[string]string
 | 
						||
		params     *ListCertificatesParams
 | 
						||
		response   string
 | 
						||
	}{
 | 
						||
		// Test Ok
 | 
						||
		{
 | 
						||
			http.StatusOK,
 | 
						||
			map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
						||
			&ListCertificatesParams{
 | 
						||
				OfferId:  "id",
 | 
						||
				Status:   "some status",
 | 
						||
				Type:     "some type",
 | 
						||
				Page:     1,
 | 
						||
				PageSize: 1,
 | 
						||
			},
 | 
						||
			`{
 | 
						||
				"result": {
 | 
						||
				  "certificates": [
 | 
						||
					{
 | 
						||
					  "certificate_id": 0,
 | 
						||
					  "certificate_number": "string",
 | 
						||
					  "certificate_name": "string",
 | 
						||
					  "type_code": "string",
 | 
						||
					  "status_code": "string",
 | 
						||
					  "accordance_type_code": "string",
 | 
						||
					  "rejection_reason_code": "string",
 | 
						||
					  "verification_comment": "string",
 | 
						||
					  "issue_date": "2019-08-24T14:15:22Z",
 | 
						||
					  "expire_date": "2019-08-24T14:15:22Z",
 | 
						||
					  "products_count": 0
 | 
						||
					}
 | 
						||
				  ],
 | 
						||
				  "page_count": 0
 | 
						||
				}
 | 
						||
			}`,
 | 
						||
		},
 | 
						||
		// Test No Client-Id or Api-Key
 | 
						||
		{
 | 
						||
			http.StatusUnauthorized,
 | 
						||
			map[string]string{},
 | 
						||
			&ListCertificatesParams{},
 | 
						||
			`{
 | 
						||
				"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.Certificates().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)
 | 
						||
		}
 | 
						||
	}
 | 
						||
}
 | 
						||
 | 
						||
func TestProductStatuses(t *testing.T) {
 | 
						||
	t.Parallel()
 | 
						||
 | 
						||
	tests := []struct {
 | 
						||
		statusCode int
 | 
						||
		headers    map[string]string
 | 
						||
		response   string
 | 
						||
	}{
 | 
						||
		// Test Ok
 | 
						||
		{
 | 
						||
			http.StatusOK,
 | 
						||
			map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
						||
			`{
 | 
						||
				"result": [
 | 
						||
				  {
 | 
						||
					"code": "string",
 | 
						||
					"name": "string"
 | 
						||
				  }
 | 
						||
				]
 | 
						||
			}`,
 | 
						||
		},
 | 
						||
		// 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 {
 | 
						||
		c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
 | 
						||
 | 
						||
		resp, err := c.Certificates().ProductStatuses()
 | 
						||
		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 TestListProductsForCertificate(t *testing.T) {
 | 
						||
	t.Parallel()
 | 
						||
 | 
						||
	tests := []struct {
 | 
						||
		statusCode int
 | 
						||
		headers    map[string]string
 | 
						||
		params     *ListProductsForCertificateParams
 | 
						||
		response   string
 | 
						||
	}{
 | 
						||
		// Test Ok
 | 
						||
		{
 | 
						||
			http.StatusOK,
 | 
						||
			map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
						||
			&ListProductsForCertificateParams{
 | 
						||
				CertificateId:     0,
 | 
						||
				ProductStatusCode: "status code",
 | 
						||
				Page:              0,
 | 
						||
				PageSize:          0,
 | 
						||
			},
 | 
						||
			`{
 | 
						||
				"result": {
 | 
						||
				  "items": [
 | 
						||
					{
 | 
						||
					  "product_id": 0,
 | 
						||
					  "product_status_code": "string"
 | 
						||
					}
 | 
						||
				  ],
 | 
						||
				  "count": 0
 | 
						||
				}
 | 
						||
			}`,
 | 
						||
		},
 | 
						||
		// Test No Client-Id or Api-Key
 | 
						||
		{
 | 
						||
			http.StatusUnauthorized,
 | 
						||
			map[string]string{},
 | 
						||
			&ListProductsForCertificateParams{},
 | 
						||
			`{
 | 
						||
				"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.Certificates().ListProductsForCertificate(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 TestUnlinkFromProduct(t *testing.T) {
 | 
						||
	t.Parallel()
 | 
						||
 | 
						||
	tests := []struct {
 | 
						||
		statusCode int
 | 
						||
		headers    map[string]string
 | 
						||
		params     *UnlinkFromProductParams
 | 
						||
		response   string
 | 
						||
	}{
 | 
						||
		// Test Ok
 | 
						||
		{
 | 
						||
			http.StatusOK,
 | 
						||
			map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
						||
			&UnlinkFromProductParams{
 | 
						||
				CertificateId: 0,
 | 
						||
				ProductId:     []int64{0},
 | 
						||
			},
 | 
						||
			`{
 | 
						||
				"result": [
 | 
						||
				  {
 | 
						||
					"error": "string",
 | 
						||
					"product_id": 0,
 | 
						||
					"updated": true
 | 
						||
				  }
 | 
						||
				]
 | 
						||
			}`,
 | 
						||
		},
 | 
						||
		// Test No Client-Id or Api-Key
 | 
						||
		{
 | 
						||
			http.StatusUnauthorized,
 | 
						||
			map[string]string{},
 | 
						||
			&UnlinkFromProductParams{},
 | 
						||
			`{
 | 
						||
				"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.Certificates().UnlinkFromProduct(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 TestPossibleRejectReasons(t *testing.T) {
 | 
						||
	t.Parallel()
 | 
						||
 | 
						||
	tests := []struct {
 | 
						||
		statusCode int
 | 
						||
		headers    map[string]string
 | 
						||
		response   string
 | 
						||
	}{
 | 
						||
		// Test Ok
 | 
						||
		{
 | 
						||
			http.StatusOK,
 | 
						||
			map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
						||
			`{
 | 
						||
				"result": [
 | 
						||
				  {
 | 
						||
					"code": "string",
 | 
						||
					"name": "string"
 | 
						||
				  }
 | 
						||
				]
 | 
						||
			}`,
 | 
						||
		},
 | 
						||
		// 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 {
 | 
						||
		c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
 | 
						||
 | 
						||
		resp, err := c.Certificates().PossibleRejectReasons()
 | 
						||
		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 TestPossibleStatuses(t *testing.T) {
 | 
						||
	t.Parallel()
 | 
						||
 | 
						||
	tests := []struct {
 | 
						||
		statusCode int
 | 
						||
		headers    map[string]string
 | 
						||
		response   string
 | 
						||
	}{
 | 
						||
		// Test Ok
 | 
						||
		{
 | 
						||
			http.StatusOK,
 | 
						||
			map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
						||
			`{
 | 
						||
				"result": [
 | 
						||
				  {
 | 
						||
					"code": "string",
 | 
						||
					"name": "string"
 | 
						||
				  }
 | 
						||
				]
 | 
						||
			}`,
 | 
						||
		},
 | 
						||
		// 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 {
 | 
						||
		c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
 | 
						||
 | 
						||
		resp, err := c.Certificates().PossibleStatuses()
 | 
						||
		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 TestAddCertificatesForProducts(t *testing.T) {
 | 
						||
	t.Parallel()
 | 
						||
 | 
						||
	tests := []struct {
 | 
						||
		statusCode int
 | 
						||
		headers    map[string]string
 | 
						||
		params     *AddCertificatesForProductsParams
 | 
						||
		response   string
 | 
						||
	}{
 | 
						||
		// Test Ok
 | 
						||
		{
 | 
						||
			http.StatusOK,
 | 
						||
			map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
						||
			&AddCertificatesForProductsParams{
 | 
						||
				Files:              []byte{10, 15, 2, 0},
 | 
						||
				Name:               "Certificate name",
 | 
						||
				Number:             "10a-d5s9-4asdf2",
 | 
						||
				TypeCode:           "declaration",
 | 
						||
				AccordanceTypeCode: "gost",
 | 
						||
				IssueDate:          time.Now(),
 | 
						||
				ExpireDate:         time.Now(),
 | 
						||
			},
 | 
						||
			`{
 | 
						||
				"id": 50058
 | 
						||
			}`,
 | 
						||
		},
 | 
						||
		// Test No Client-Id or Api-Key
 | 
						||
		{
 | 
						||
			http.StatusUnauthorized,
 | 
						||
			map[string]string{},
 | 
						||
			&AddCertificatesForProductsParams{},
 | 
						||
			`{
 | 
						||
				"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.Certificates().AddForProducts(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)
 | 
						||
		}
 | 
						||
	}
 | 
						||
}
 |