diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..84e0192
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,10 @@
+vendor
+.idea/
+
+# binary
+cdek
+
+# go test -coverprofile cover.out
+cover.out
+# go tool cover -html=cover.out -o cover.html
+cover.html
diff --git a/.golangci.yml b/.golangci.yml
new file mode 100644
index 0000000..c4cd61b
--- /dev/null
+++ b/.golangci.yml
@@ -0,0 +1,24 @@
+run:
+ # timeout for analysis, e.g. 30s, 5m, default is 1m
+ deadline: 2m
+linters:
+ enable-all: true
+ disable:
+ - scopelint
+ - dupl
+linters-settings:
+ misspell:
+ locale: US
+issues:
+ max-same: 0
+ max-per-linter: 0
+ exclude-use-default: false
+ exclude:
+ # gosec: Duplicated errcheck checks
+ - G104
+ # gosec: Variable url
+ - G107
+ # gosec: md5 needed by CDEK
+ - G501
+ # gosec: md5 needed by CDEK
+ - G401
\ No newline at end of file
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..761d090
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,11 @@
+# Contributing
+
+Feel free to browse the open issues and file new ones, all feedback welcome!
+
+We follow the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).
+
+We generally follow the standard [github pull request](https://help.github.com/articles/about-pull-requests/) process
+
+All changes must be code reviewed.
+Expect reviewers to request that you avoid [common go style
+mistakes](https://github.com/golang/go/wiki/CodeReviewComments) in your pull requests.
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..b242a53
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2019 vseinstrumenti.ru
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..c7f47fd
--- /dev/null
+++ b/README.md
@@ -0,0 +1,36 @@
+# GO SDK for CDEK API
+[![GoDoc reference](https://godoc.org/github.com/vseinstrumentiru/CDEK?status.svg)](https://godoc.org/github.com/vseinstrumentiru/CDEK)
+[![Go Report Card](https://goreportcard.com/badge/github.com/vseinstrumentiru/CDEK)](https://goreportcard.com/report/github.com/vseinstrumentiru/CDEK)
+[![GitHub release](https://img.shields.io/github/release/vseinstrumentiru/cdek.svg)](https://github.com/vseinstrumentiru/CDEK/releases)
+
+The Go language implementation of SDK for [integration with CDEK](https://www.cdek.ru/clients/integrator.html)
+
+----
+Installation
+------------
+
+To install this package, you need to install Go and setup your Go workspace on
+your computer. The simplest way to install the library is to run:
+
+```
+$ go get github.com/vseinstrumentiru/cdek
+```
+With Go module support (Go 1.11+), simply `import "github.com/vseinstrumentiru/cdek"` in
+your source code and `go [build|run|test]` will automatically download the
+necessary dependencies ([Go modules
+ref](https://github.com/golang/go/wiki/Modules)).
+
+Documentation
+-------------
+- See [godoc](https://godoc.org/github.com/vseinstrumentiru/CDEK) for package and API
+ descriptions and examples.
+
+Example
+-------------
+You cat get test `clientAccount` and `clientSecurePassword` from [the official CDEK documentation](https://confluence.cdek.ru/pages/viewpage.action?pageId=20264477#DataExchangeProtocol(v1.5)-TestAccount)
+```
+clientConf := NewClientConf("https://integration.edu.cdek.ru/")
+clientConf.SetAuth(clientAccount, clientSecurePassword)
+
+client := cdek.NewClient(clientConf)
+```
diff --git a/ROADMAP.md b/ROADMAP.md
new file mode 100644
index 0000000..2250b27
--- /dev/null
+++ b/ROADMAP.md
@@ -0,0 +1,19 @@
+- [ ] расчёт тарифов и обращения к справочникам
+ - [X] расчёт стоимости доставки по тарифам с приоритетом
+ - [ ] расчёт стоимости по тарифам без приоритета
+ - [X] получение списка пунктов выдачи заказов (ПВЗ) с фильтрацией
+ - [X] получение списка регионов-субъектов РФ
+ - [X] получение списка городов
+- [ ] управление заказами
+ - [X] формирование новых заказов от ИМ
+ - [ ] оформление заказов на доставку
+ - [ ] получение квитанции в PDF
+ - [ ] получение почтовых этикеток в PDF
+ - [X] удаление заказов
+ - [X] изменение заказов
+ - [ ] получение информации по заказам (отчёт «Информация по заказам»)
+ - [ ] трекинг заказов (отчёт «Статусы заказов»)
+ - [ ] прозвон получателя
+ - [ ] вызов курьера
+ - [ ] создание преалерта
+ - [X] выбор базового URL интерфейса
diff --git a/calculator-models.go b/calculator-models.go
new file mode 100644
index 0000000..b381cbb
--- /dev/null
+++ b/calculator-models.go
@@ -0,0 +1,55 @@
+package cdek
+
+//Good Location's dimension
+type Good struct {
+ Weight float64 `json:"weight"`
+ Length int `json:"length"`
+ Width int `json:"width"`
+ Height int `json:"height"`
+ Volume float64 `json:"volume"`
+}
+
+//ServiceReq List of additional service
+type ServiceReq struct {
+ ID int `json:"id"`
+ Param int `json:"param,omitempty"`
+}
+
+//ServiceResp List of transmitted additional services
+type ServiceResp struct {
+ ID int `json:"id"`
+ Title string `json:"title"`
+ Price float64 `json:"price"`
+ Rate float64 `json:"rate,omitempty"`
+}
+
+//GetCostReq Cost calculation on tariffs with priority request
+type GetCostReq struct {
+ securableJSON
+ Version *string `json:"version"`
+ SenderCityID *int `json:"senderCityId"`
+ ReceiverCityID *int `json:"receiverCityId"`
+ TariffID *int `json:"tariffId"`
+ Goods []*Good `json:"goods"`
+ Services []*ServiceReq `json:"services,omitempty"`
+}
+
+type getCostResp struct {
+ ErrorResp []Error `json:"error,omitempty"`
+ Result GetCostRespResult `json:"result"`
+}
+
+//GetCostRespResult Cost calculation on tariffs with priority result response
+type GetCostRespResult struct {
+ Price float64 `json:"price,string"`
+ DeliveryPeriodMin int `json:"deliveryPeriodMin"`
+ DeliveryPeriodMax int `json:"deliveryPeriodMax"`
+ DeliveryDateMin string `json:"deliveryDateMin"`
+ DeliveryDateMax string `json:"deliveryDateMax"`
+ TariffID int `json:"tariffId"`
+ CashOnDelivery float64 `json:"cashOnDelivery"`
+ PriceByCurrency float64 `json:"priceByCurrency"`
+ Currency string `json:"currency"`
+ PercentVAT int `json:"percentVAT"`
+ Services []ServiceResp `json:"services"`
+}
diff --git a/calculator-req-builder.go b/calculator-req-builder.go
new file mode 100644
index 0000000..eaa60fd
--- /dev/null
+++ b/calculator-req-builder.go
@@ -0,0 +1,37 @@
+package cdek
+
+const apiVersion = "1.0"
+
+//NewGetCostReq create new instance of GetCostReq
+func NewGetCostReq(senderCityID int, receiverCityID int, tariffID int) *GetCostReq {
+ apiVersion := apiVersion
+
+ return &GetCostReq{
+ Version: &apiVersion,
+ SenderCityID: &senderCityID,
+ ReceiverCityID: &receiverCityID,
+ TariffID: &tariffID,
+ }
+}
+
+//AddService add service to request
+func (getCostReq *GetCostReq) AddService(service ServiceReq) *GetCostReq {
+ if getCostReq.Services == nil {
+ getCostReq.Services = []*ServiceReq{}
+ }
+
+ getCostReq.Services = append(getCostReq.Services, &service)
+
+ return getCostReq
+}
+
+//AddGood add good to request
+func (getCostReq *GetCostReq) AddGood(good Good) *GetCostReq {
+ if getCostReq.Goods == nil {
+ getCostReq.Goods = []*Good{}
+ }
+
+ getCostReq.Goods = append(getCostReq.Goods, &good)
+
+ return getCostReq
+}
diff --git a/calculator-req-builder_test.go b/calculator-req-builder_test.go
new file mode 100644
index 0000000..34e857b
--- /dev/null
+++ b/calculator-req-builder_test.go
@@ -0,0 +1,199 @@
+package cdek
+
+import (
+ "reflect"
+ "testing"
+)
+
+func TestNewGetCostReq(t *testing.T) {
+ apiVersion := apiVersion
+ senderCityID := 1
+ receiverCityID := 2
+ tariffID := 3
+
+ type args struct {
+ senderCityID int
+ receiverCityID int
+ tariffID int
+ }
+ tests := []struct {
+ name string
+ args args
+ want *GetCostReq
+ }{
+ {
+ "constructor is ok",
+ args{
+ senderCityID: 1,
+ receiverCityID: 2,
+ tariffID: 3,
+ },
+ &GetCostReq{
+ Version: &apiVersion,
+ SenderCityID: &senderCityID,
+ ReceiverCityID: &receiverCityID,
+ TariffID: &tariffID,
+ Goods: nil,
+ Services: nil,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := NewGetCostReq(tt.args.senderCityID, tt.args.receiverCityID, tt.args.tariffID)
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewGetCostReq() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestGetCostReq_AddService(t *testing.T) {
+ type fields struct {
+ Version *string
+ AuthLogin *string
+ Secure *string
+ DateExecute *string
+ SenderCityID *int
+ ReceiverCityID *int
+ TariffID *int
+ Goods []*Good
+ Services []*ServiceReq
+ }
+ type args struct {
+ service ServiceReq
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *GetCostReq
+ }{
+ {
+ "constructor is ok",
+ fields{
+ Version: nil,
+ AuthLogin: nil,
+ Secure: nil,
+ DateExecute: nil,
+ SenderCityID: nil,
+ ReceiverCityID: nil,
+ TariffID: nil,
+ Goods: nil,
+ Services: nil,
+ },
+ args{
+ service: ServiceReq{
+ ID: 1,
+ Param: 2,
+ },
+ },
+ &GetCostReq{
+ Version: nil,
+ SenderCityID: nil,
+ ReceiverCityID: nil,
+ TariffID: nil,
+ Goods: nil,
+ Services: []*ServiceReq{
+ {
+ ID: 1,
+ Param: 2,
+ },
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ getCostReq := &GetCostReq{
+ Version: tt.fields.Version,
+ SenderCityID: tt.fields.SenderCityID,
+ ReceiverCityID: tt.fields.ReceiverCityID,
+ TariffID: tt.fields.TariffID,
+ Goods: tt.fields.Goods,
+ Services: tt.fields.Services,
+ }
+ if got := getCostReq.AddService(tt.args.service); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("AddService() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestGetCostReq_AddGood(t *testing.T) {
+ type fields struct {
+ Version *string
+ AuthLogin *string
+ Secure *string
+ DateExecute *string
+ SenderCityID *int
+ ReceiverCityID *int
+ TariffID *int
+ Goods []*Good
+ Services []*ServiceReq
+ }
+ type args struct {
+ good Good
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *GetCostReq
+ }{
+ {
+ "constructor is ok",
+ fields{
+ Version: nil,
+ AuthLogin: nil,
+ Secure: nil,
+ DateExecute: nil,
+ SenderCityID: nil,
+ ReceiverCityID: nil,
+ TariffID: nil,
+ Goods: nil,
+ Services: nil,
+ },
+ args{
+ good: Good{
+ Weight: 1.11,
+ Length: 2,
+ Width: 3,
+ Height: 4,
+ Volume: 5.55,
+ },
+ },
+ &GetCostReq{
+ Version: nil,
+ SenderCityID: nil,
+ ReceiverCityID: nil,
+ TariffID: nil,
+ Goods: []*Good{
+ {
+ Weight: 1.11,
+ Length: 2,
+ Width: 3,
+ Height: 4,
+ Volume: 5.55,
+ },
+ },
+ Services: nil,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ getCostReq := &GetCostReq{
+ Version: tt.fields.Version,
+ SenderCityID: tt.fields.SenderCityID,
+ ReceiverCityID: tt.fields.ReceiverCityID,
+ TariffID: tt.fields.TariffID,
+ Goods: tt.fields.Goods,
+ Services: tt.fields.Services,
+ }
+ if got := getCostReq.AddGood(tt.args.good); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("AddGood() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
diff --git a/calculator-service.go b/calculator-service.go
new file mode 100644
index 0000000..48b5eca
--- /dev/null
+++ b/calculator-service.go
@@ -0,0 +1,47 @@
+package cdek
+
+import (
+ "bytes"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+)
+
+//CalculateDelivery Cost calculation on tariffs with priority.
+func (c Client) CalculateDelivery(req GetCostReq) (*GetCostRespResult, error) {
+ req.setAuth(c.auth)
+ reqByte, err := json.Marshal(req)
+ if err != nil {
+ return nil, err
+ }
+
+ resp, err := http.Post(c.calculatorURL, jsonContentType, bytes.NewReader(reqByte))
+ if err != nil {
+ return nil, err
+ }
+
+ defer func() {
+ _ = resp.Body.Close()
+ }()
+
+ body, _ := ioutil.ReadAll(resp.Body)
+
+ var getCostResp getCostResp
+ err = json.Unmarshal(body, &getCostResp)
+ if err != nil {
+ return nil, err
+ }
+
+ if getCostResp.ErrorResp != nil {
+ var errorMsg string
+ for _, err := range getCostResp.ErrorResp {
+ errorMsg += fmt.Sprintf("Error code: %s, error text: %s \n", *err.ErrorCode, *err.Msg)
+ }
+
+ return nil, errors.New(errorMsg)
+ }
+
+ return &getCostResp.Result, nil
+}
diff --git a/calculator-service_test.go b/calculator-service_test.go
new file mode 100644
index 0000000..76052c0
--- /dev/null
+++ b/calculator-service_test.go
@@ -0,0 +1,216 @@
+package cdek
+
+import (
+ "encoding/json"
+ "io/ioutil"
+ "net/http"
+ "net/http/httptest"
+ "reflect"
+ "testing"
+)
+
+func calculateDeliveryGetMockServer() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ body, _ := ioutil.ReadAll(req.Body)
+ _, _ = req.Body.Read(body)
+ var getCostReq GetCostReq
+ _ = json.Unmarshal(body, &getCostReq)
+
+ var errorsResp []Error
+ if *getCostReq.Version != apiVersion {
+ errorsResp = append(errorsResp, Error{
+ ErrorCode: strLink("1"),
+ Msg: strLink("Указанная вами версия API не поддерживается"),
+ })
+ }
+ if *getCostReq.Secure == "" || *getCostReq.AuthLogin == "" || *getCostReq.DateExecute == "" {
+ errorsResp = append(errorsResp, Error{
+ ErrorCode: strLink("2"),
+ Msg: strLink("Ошибка авторизации"),
+ })
+ }
+ if *getCostReq.SenderCityID == 0 {
+ errorsResp = append(errorsResp, Error{
+ ErrorCode: strLink("7"),
+ Msg: strLink("Не задан город-отправитель"),
+ })
+ }
+ if *getCostReq.ReceiverCityID == 0 {
+ errorsResp = append(errorsResp, Error{
+ ErrorCode: strLink("8"),
+ Msg: strLink("Не задан город-получатель"),
+ })
+ }
+ if getCostReq.Goods == nil {
+ errorsResp = append(errorsResp, Error{
+ ErrorCode: strLink("8"),
+ Msg: strLink("Не задано ни одного места для отправления"),
+ })
+ }
+
+ if *getCostReq.TariffID == 0 {
+ errorsResp = append(errorsResp, Error{
+ ErrorCode: strLink("6"),
+ Msg: strLink("Не задан тариф или список тарифов"),
+ })
+ }
+
+ result, _ := json.Marshal(&getCostResp{
+ ErrorResp: errorsResp,
+ Result: GetCostRespResult{
+ Price: 100,
+ DeliveryPeriodMin: 1,
+ DeliveryPeriodMax: 2,
+ TariffID: 3,
+ },
+ })
+
+ _, _ = res.Write(result)
+ }))
+}
+
+func calculateDeliveryGetMockServerWithError() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _, _ = res.Write([]byte("err"))
+ }))
+}
+
+func TestClient_CalculateDelivery(t *testing.T) {
+ testServer := calculateDeliveryGetMockServer()
+ defer testServer.Close()
+
+ testServerWithError := calculateDeliveryGetMockServerWithError()
+ defer testServerWithError.Close()
+
+ apiVersion := apiVersion
+ senderCityID := 1
+ receiverCityID := 2
+ tariffID := 3
+
+ type args struct {
+ client Client
+ req GetCostReq
+ }
+ tests := []struct {
+ name string
+ args args
+ want *GetCostRespResult
+ wantErr bool
+ }{
+ {
+ "success deliveries calculated",
+ args{
+ client: Client{
+ auth: &auth{
+ account: "123",
+ secure: "123",
+ },
+ apiURL: "",
+ calculatorURL: testServer.URL,
+ },
+ req: GetCostReq{
+ Version: &apiVersion,
+ SenderCityID: &senderCityID,
+ ReceiverCityID: &receiverCityID,
+ TariffID: &tariffID,
+ Goods: []*Good{
+ {
+ Weight: 1.1,
+ Length: 2,
+ Width: 3,
+ Height: 4,
+ Volume: 5.5,
+ },
+ },
+ Services: nil,
+ },
+ },
+ &GetCostRespResult{
+ Price: 100,
+ DeliveryPeriodMin: 1,
+ DeliveryPeriodMax: 2,
+ TariffID: 3,
+ },
+ false,
+ },
+ {
+ "wrong goods",
+ args{
+ client: Client{
+ auth: &auth{
+ account: "123",
+ secure: "123",
+ },
+ apiURL: "",
+ calculatorURL: testServer.URL,
+ },
+ req: GetCostReq{
+ Version: &apiVersion,
+ SenderCityID: &senderCityID,
+ ReceiverCityID: &receiverCityID,
+ TariffID: &tariffID,
+ Goods: nil,
+ Services: nil,
+ },
+ },
+ nil,
+ true,
+ },
+ {
+ "server error",
+ args{
+ client: Client{
+ auth: &auth{
+ account: "123",
+ secure: "123",
+ },
+ apiURL: "",
+ calculatorURL: testServerWithError.URL,
+ },
+ req: GetCostReq{
+ Version: &apiVersion,
+ SenderCityID: &senderCityID,
+ ReceiverCityID: &receiverCityID,
+ TariffID: &tariffID,
+ Goods: nil,
+ Services: nil,
+ },
+ },
+ nil,
+ true,
+ },
+ {
+ "wrong url",
+ args{
+ client: Client{
+ calculatorURL: "wrong url",
+ },
+ req: GetCostReq{},
+ },
+ nil,
+ true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ cl := tt.args.client
+ got, err := cl.CalculateDelivery(tt.args.req)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("CalculateDelivery() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("CalculateDelivery() got = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func ExampleClient_CalculateDelivery() {
+ client := NewClient("https://integration.edu.cdek.ru/")
+ client.SetAuth("z9GRRu7FxmO53CQ9cFfI6qiy32wpfTkd", "w24JTCv4MnAcuRTx0oHjHLDtyt3I6IBq")
+
+ result, err := client.CalculateDelivery(*NewGetCostReq(61208, 2108, 10))
+
+ _, _ = result, err
+}
diff --git a/city-filter.go b/city-filter.go
new file mode 100755
index 0000000..86c4d68
--- /dev/null
+++ b/city-filter.go
@@ -0,0 +1,51 @@
+package cdek
+
+//CityFilter filter key for "List of Cities" request
+type CityFilter string
+
+const (
+ //CityFilterRegionCodeExt Код региона
+ CityFilterRegionCodeExt CityFilter = "regionCodeExt"
+
+ //CityFilterRegionCode Код региона в ИС СДЭК
+ CityFilterRegionCode CityFilter = "regionCode"
+
+ //CityFilterRegionFiasGUID Код региона из ФИАС
+ CityFilterRegionFiasGUID CityFilter = "regionFiasGuid"
+
+ //CityFilterPage Номер страницы выборки результата.По умолчанию 0
+ CityFilterPage CityFilter = "page"
+
+ //CityFilterSize Ограничение выборки результата.По умолчанию 1000
+ CityFilterSize CityFilter = "size"
+
+ //CityFilterCountryCode Код страны в формате ISO 3166-1 alpha-2
+ CityFilterCountryCode CityFilter = "countryCode"
+
+ //CityFilterCityName Название города
+ CityFilterCityName CityFilter = "cityName"
+
+ //CityFilterPostcode Почтовый индекс
+ CityFilterPostcode CityFilter = "postcode"
+)
+
+//CityFilterBuilder builder for filer for "List of Cities" request
+type CityFilterBuilder struct {
+ filter map[CityFilter]string
+}
+
+//AddFilter add filter to set of filters for "List of Cities" request
+func (filterBuilder *CityFilterBuilder) AddFilter(filter CityFilter, value string) *CityFilterBuilder {
+ if filterBuilder.filter == nil {
+ filterBuilder.filter = make(map[CityFilter]string)
+ }
+
+ filterBuilder.filter[filter] = value
+
+ return filterBuilder
+}
+
+//Filter returns complete CityFilter for "List of Cities" request
+func (filterBuilder *CityFilterBuilder) Filter() map[CityFilter]string {
+ return filterBuilder.filter
+}
diff --git a/city-filter_test.go b/city-filter_test.go
new file mode 100644
index 0000000..5e74cea
--- /dev/null
+++ b/city-filter_test.go
@@ -0,0 +1,118 @@
+package cdek
+
+import (
+ "reflect"
+ "testing"
+)
+
+func TestCityFilterBuilder_AddFilter(t *testing.T) {
+ type fields struct {
+ filter map[CityFilter]string
+ }
+ type args struct {
+ filter CityFilter
+ value string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *CityFilterBuilder
+ }{
+ {
+ name: "add single filter",
+ fields: fields{
+ filter: nil,
+ },
+ args: args{
+ filter: CityFilterPage,
+ value: "33",
+ },
+ want: &CityFilterBuilder{
+ filter: map[CityFilter]string{
+ CityFilterPage: "33",
+ },
+ },
+ },
+ {
+ name: "rewrite filter",
+ fields: fields{
+ filter: map[CityFilter]string{
+ CityFilterPage: "55",
+ },
+ },
+ args: args{
+ filter: CityFilterPage,
+ value: "66",
+ },
+ want: &CityFilterBuilder{
+ filter: map[CityFilter]string{
+ CityFilterPage: "66",
+ },
+ },
+ },
+ {
+ name: "add filter",
+ fields: fields{
+ filter: map[CityFilter]string{
+ CityFilterPage: "77",
+ },
+ },
+ args: args{
+ filter: CityFilterCityName,
+ value: "Moscow",
+ },
+ want: &CityFilterBuilder{
+ filter: map[CityFilter]string{
+ CityFilterPage: "77",
+ CityFilterCityName: "Moscow",
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ filterBuilder := &CityFilterBuilder{
+ filter: tt.fields.filter,
+ }
+ if got := filterBuilder.AddFilter(tt.args.filter, tt.args.value); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("AddFilter() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestCityFilterBuilder_Filter(t *testing.T) {
+ type fields struct {
+ filter map[CityFilter]string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ want map[CityFilter]string
+ }{
+ {
+ name: "multiple filters",
+ fields: fields{
+ filter: map[CityFilter]string{
+ CityFilterPage: "22",
+ CityFilterCityName: "Moscow",
+ },
+ },
+ want: map[CityFilter]string{
+ CityFilterPage: "22",
+ CityFilterCityName: "Moscow",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ filterBuilder := &CityFilterBuilder{
+ filter: tt.fields.filter,
+ }
+ if got := filterBuilder.Filter(); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Filter() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
diff --git a/city-models.go b/city-models.go
new file mode 100644
index 0000000..c64ff69
--- /dev/null
+++ b/city-models.go
@@ -0,0 +1,23 @@
+package cdek
+
+//GetCitiesResp response struct for CDEK cities getter
+type GetCitiesResp []*City
+
+//City CDEK city model
+type City struct {
+ CityUUID *string `json:"cityUuid"`
+ CityName *string `json:"cityName"`
+ CityCode *int `json:"cityCode,string"`
+ Region *string `json:"region"`
+ RegionCodeExt *int `json:"regionCodeExt,string"`
+ RegionCode *int `json:"regionCode,string"`
+ SubRegion *string `json:"subRegion"`
+ Country *string `json:"country"`
+ CountryCode *string `json:"countryCode"`
+ Latitude *float64 `json:"latitude"`
+ Longitude *float64 `json:"longitude"`
+ Kladr *string `json:"kladr"`
+ FiasGUID *string `json:"fiasGuid"`
+ RegionFiasGUID *string `json:"regionFiasGuid"`
+ PaymentLimit *float64 `json:"paymentLimit"`
+}
diff --git a/city-service.go b/city-service.go
new file mode 100755
index 0000000..b528cf0
--- /dev/null
+++ b/city-service.go
@@ -0,0 +1,61 @@
+package cdek
+
+import (
+ "encoding/json"
+ "io/ioutil"
+ "net/http"
+ "net/url"
+ "path"
+
+ "github.com/hashicorp/go-multierror"
+)
+
+const citiesURL = "v1/location/cities/json"
+
+//GetCities This method is used to load detailed information on cities.
+func (c Client) GetCities(filter map[CityFilter]string) (*GetCitiesResp, error) {
+ serverURL, err := url.Parse(c.apiURL)
+ if err != nil {
+ return nil, err
+ }
+
+ serverURL.Path = path.Join(serverURL.Path, citiesURL)
+
+ queryString := serverURL.Query()
+ for filterKey, value := range filter {
+ queryString.Set(string(filterKey), value)
+ }
+ serverURL.RawQuery = queryString.Encode()
+
+ reqURL := serverURL.String()
+
+ resp, err := http.Get(reqURL)
+ if err != nil {
+ return nil, err
+ }
+
+ defer func() {
+ _ = resp.Body.Close()
+ }()
+
+ body, _ := ioutil.ReadAll(resp.Body)
+
+ var cities GetCitiesResp
+ err = json.Unmarshal(body, &cities)
+ if err != nil {
+ var alertResponse AlertResponse
+ err = json.Unmarshal(body, &alertResponse)
+ if err != nil {
+ return nil, err
+ }
+
+ multiError := &multierror.Error{}
+ for _, alert := range alertResponse.Alerts {
+ multiError = multierror.Append(alert)
+ }
+
+ return nil, multiError.ErrorOrNil()
+ }
+
+ return &cities, nil
+}
diff --git a/city-service_test.go b/city-service_test.go
new file mode 100644
index 0000000..a7bd22c
--- /dev/null
+++ b/city-service_test.go
@@ -0,0 +1,205 @@
+package cdek
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "reflect"
+ "testing"
+)
+
+func getCitiesGetMockServer() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _, _ = res.Write([]byte(`[{
+ "cityUuid":"dece8676-077e-4793-9d67-96112fe96b03",
+ "cityName":"Москва",
+ "cityCode":"61627",
+ "region":"Кировская",
+ "regionCodeExt":"43",
+ "regionCode":"44",
+ "subRegion":"Верхошижемский",
+ "country":"Russia",
+ "countryCode":"RU",
+ "latitude":57.9664,
+ "longitude":49.1074,
+ "kladr":"4300700005400",
+ "fiasGuid":"f1c72b9d-a2d7-45b7-b9f5-2222c12d5164",
+ "regionFiasGuid":null,"paymentLimit":0
+ },{
+ "cityUuid":"18bd1ad1-0ed5-4908-9069-db07b805aa53",
+ "cityName":"Москва",
+ "cityCode":"44",
+ "region":"Москва",
+ "regionCodeExt":"77",
+ "regionCode":"81",
+ "subRegion":"Москва",
+ "country":"Russia",
+ "countryCode":"RU",
+ "latitude":55.754,
+ "longitude":37.6204,
+ "kladr":"7700000000000",
+ "fiasGuid":"0c5b2444-70a0-4932-980c-b4dc0d3f02b5",
+ "regionFiasGuid":null,
+ "paymentLimit":-1
+ }]`))
+ }))
+}
+
+func getCitiesGetMockServerWithError() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _, _ = res.Write([]byte("err"))
+ }))
+}
+func getCitiesGetMockServerWithValidError() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _, _ = res.Write([]byte(`
+ {
+ "alerts":[
+ {"type":"danger","msg":"API location not available","errorCode":"connector.location.error.send"}
+ ]
+ }
+ `))
+ }))
+}
+
+func TestClient_GetCities(t *testing.T) {
+ testServer := getCitiesGetMockServer()
+ defer testServer.Close()
+
+ testServerWithError := getCitiesGetMockServerWithError()
+ defer testServerWithError.Close()
+
+ testServerWithValidError := getCitiesGetMockServerWithValidError()
+ defer testServerWithError.Close()
+
+ var citiesFilterBuilder CityFilterBuilder
+ citiesFilterBuilder.AddFilter(CityFilterCityName, "Москва")
+
+ var filterCausesServerError CityFilterBuilder
+ filterCausesServerError.AddFilter(CityFilterPage, "2000")
+
+ type args struct {
+ client Client
+ filter map[CityFilter]string
+ }
+ tests := []struct {
+ name string
+ args args
+ want *GetCitiesResp
+ wantErr bool
+ }{
+ {
+ name: "got cities",
+ args: args{
+ client: Client{
+ apiURL: testServer.URL,
+ },
+ filter: citiesFilterBuilder.Filter(),
+ },
+ want: &GetCitiesResp{
+ &City{
+ strLink("dece8676-077e-4793-9d67-96112fe96b03"),
+ strLink("Москва"),
+ intLink(61627),
+ strLink("Кировская"),
+ intLink(43),
+ intLink(44),
+ strLink("Верхошижемский"),
+ strLink("Russia"),
+ strLink("RU"),
+ float64Link(57.9664),
+ float64Link(49.1074),
+ strLink("4300700005400"),
+ strLink("f1c72b9d-a2d7-45b7-b9f5-2222c12d5164"),
+ nil,
+ float64Link(0),
+ },
+ &City{
+ strLink("18bd1ad1-0ed5-4908-9069-db07b805aa53"),
+ strLink("Москва"),
+ intLink(44),
+ strLink("Москва"),
+ intLink(77),
+ intLink(81),
+ strLink("Москва"),
+ strLink("Russia"),
+ strLink("RU"),
+ float64Link(55.754),
+ float64Link(37.6204),
+ strLink("7700000000000"),
+ strLink("0c5b2444-70a0-4932-980c-b4dc0d3f02b5"),
+ nil,
+ float64Link(-1),
+ },
+ },
+ wantErr: false,
+ },
+ {
+ name: "server error",
+ args: args{
+ client: Client{
+ apiURL: testServerWithError.URL,
+ },
+ filter: nil,
+ },
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "uncompilable url",
+ args: args{
+ client: Client{
+ apiURL: " wrong://url ",
+ },
+ filter: nil,
+ },
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "wrong url",
+ args: args{
+ client: Client{
+ apiURL: "wrong://url",
+ },
+ filter: nil,
+ },
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "valid error on service",
+ args: args{
+ client: Client{
+ apiURL: testServerWithValidError.URL,
+ },
+ filter: filterCausesServerError.Filter(),
+ },
+ want: nil,
+ wantErr: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ cl := tt.args.client
+ got, err := cl.GetCities(tt.args.filter)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("GetCities() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("GetCities() got = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func ExampleClient_GetCities() {
+ client := NewClient("https://integration.edu.cdek.ru/")
+ client.SetAuth("z9GRRu7FxmO53CQ9cFfI6qiy32wpfTkd", "w24JTCv4MnAcuRTx0oHjHLDtyt3I6IBq")
+
+ result, err := client.GetCities(map[CityFilter]string{
+ CityFilterPage: "3",
+ })
+
+ _, _ = result, err
+}
diff --git a/client.go b/client.go
new file mode 100755
index 0000000..b172369
--- /dev/null
+++ b/client.go
@@ -0,0 +1,58 @@
+package cdek
+
+import (
+ "crypto/md5"
+ "encoding/hex"
+ "time"
+)
+
+const jsonContentType = "application/json"
+const xmlContentType = "application/xml"
+const urlFormEncoded = "application/x-www-form-urlencoded"
+
+const calculatorURLDefault = "http://api.cdek.ru/calculator/calculate_price_by_json.php"
+
+//Client SDK Client configuration
+type Client struct {
+ auth *auth
+ apiURL string
+ calculatorURL string
+}
+
+//NewClient Client constructor with defaults
+func NewClient(apiURL string) *Client {
+ return &Client{
+ apiURL: apiURL,
+ calculatorURL: calculatorURLDefault,
+ }
+}
+
+//SetAuth set auth data
+func (c *Client) SetAuth(account, secure string) *Client {
+ c.auth = &auth{
+ account: account,
+ secure: secure,
+ }
+
+ return c
+}
+
+//SetCalculatorURL url for delivery calculation
+func (c *Client) SetCalculatorURL(calculatorURL string) *Client {
+ c.calculatorURL = calculatorURL
+
+ return c
+}
+
+type auth struct {
+ account string
+ secure string
+}
+
+func (a auth) encodedSecure() (date string, encodedSecure string) {
+ date = time.Now().Format("2006-01-02")
+ encoder := md5.New()
+ _, _ = encoder.Write([]byte(date + "&" + a.secure))
+
+ return date, hex.EncodeToString(encoder.Sum(nil))
+}
diff --git a/client_test.go b/client_test.go
new file mode 100644
index 0000000..e1e3e08
--- /dev/null
+++ b/client_test.go
@@ -0,0 +1,187 @@
+package cdek
+
+import (
+ "crypto/md5"
+ "encoding/hex"
+ "reflect"
+ "testing"
+ "time"
+)
+
+func TestNewClient(t *testing.T) {
+ type args struct {
+ apiURL string
+ }
+ tests := []struct {
+ name string
+ args args
+ want *Client
+ }{
+ {
+ "Client created",
+ args{
+ apiURL: "apiURL",
+ },
+ &Client{
+ apiURL: "apiURL",
+ calculatorURL: calculatorURLDefault,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewClient(tt.args.apiURL); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewClient() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestAuth_EncodedSecure(t *testing.T) {
+ now := time.Now().Format("2006-01-02")
+ encoder := md5.New()
+ _, _ = encoder.Write([]byte(now + "&" + "testSecure"))
+ testSecureEncoded := hex.EncodeToString(encoder.Sum(nil))
+
+ type fields struct {
+ Account string
+ Secure string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ wantDate string
+ wantEncodedSecure string
+ }{
+ {
+ name: "successful encoding",
+ fields: fields{
+ Account: "testAccount",
+ Secure: "testSecure",
+ },
+ wantDate: now,
+ wantEncodedSecure: testSecureEncoded,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ a := auth{
+ account: tt.fields.Account,
+ secure: tt.fields.Secure,
+ }
+ gotDate, gotEncodedSecure := a.encodedSecure()
+ if gotDate != tt.wantDate {
+ t.Errorf("encodedSecure() gotDate = %v, want %v", gotDate, tt.wantDate)
+ }
+ if gotEncodedSecure != tt.wantEncodedSecure {
+ t.Errorf("encodedSecure() gotEncodedSecure = %v, want %v", gotEncodedSecure, tt.wantEncodedSecure)
+ }
+ })
+ }
+}
+
+func TestClient_SetAuth(t *testing.T) {
+ type fields struct {
+ Auth *auth
+ CdekAPIURL string
+ CalculatorURL string
+ }
+ type args struct {
+ account string
+ secure string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Client
+ }{
+ {
+ name: "auth set",
+ fields: fields{
+ Auth: nil,
+ },
+ args: args{
+ account: "testAccount",
+ secure: "testSecure",
+ },
+ want: &Client{
+ auth: &auth{
+ account: "testAccount",
+ secure: "testSecure",
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ clientConf := &Client{
+ auth: tt.fields.Auth,
+ apiURL: tt.fields.CdekAPIURL,
+ calculatorURL: tt.fields.CalculatorURL,
+ }
+ if got := clientConf.SetAuth(tt.args.account, tt.args.secure); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("SetAuth() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestClient_SetCalculatorURL(t *testing.T) {
+ type fields struct {
+ Auth *auth
+ CdekAPIURL string
+ CalculatorURL string
+ }
+ type args struct {
+ calculatorURL string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Client
+ }{
+ {
+ name: "set url",
+ fields: fields{
+ CalculatorURL: "",
+ },
+ args: args{
+ calculatorURL: "testCalcUrl",
+ },
+ want: &Client{
+ calculatorURL: "testCalcUrl",
+ },
+ },
+ {
+ name: "rewrite url",
+ fields: fields{
+ CalculatorURL: "",
+ },
+ args: args{
+ calculatorURL: "testCalcUrl_rewritten",
+ },
+ want: &Client{
+ calculatorURL: "testCalcUrl_rewritten",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ clientConf := &Client{
+ auth: tt.fields.Auth,
+ apiURL: tt.fields.CdekAPIURL,
+ calculatorURL: tt.fields.CalculatorURL,
+ }
+ if got := clientConf.SetCalculatorURL(tt.args.calculatorURL); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("SetCalculatorURL() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func ExampleNewClient() {
+ client := NewClient("https://integration.edu.cdek.ru/")
+ client.SetAuth("z9GRRu7FxmO53CQ9cFfI6qiy32wpfTkd", "w24JTCv4MnAcuRTx0oHjHLDtyt3I6IBq")
+}
diff --git a/delete-order-models.go b/delete-order-models.go
new file mode 100644
index 0000000..2b45b7f
--- /dev/null
+++ b/delete-order-models.go
@@ -0,0 +1,23 @@
+package cdek
+
+import "encoding/xml"
+
+//DeleteOrderReq request structure for deleting order from CDEK
+type DeleteOrderReq struct {
+ securableXML
+ XMLName xml.Name `xml:"DeleteRequest"`
+ Number *string `xml:"Number,attr"`
+ OrderCount *int `xml:"OrderCount,attr"`
+ Order *DeleteOrder `xml:"Order"`
+}
+
+//DeleteOrder order model for deleting request
+type DeleteOrder struct {
+ Number *string `xml:"Number,attr"`
+ DispatchNumber *int `xml:"DispatchNumber,attr"`
+}
+
+//DeleteOrderResp response structure of deleting order from CDEK
+type DeleteOrderResp struct {
+ Order []*OrderResp `xml:"Order"`
+}
diff --git a/delete-order-req-builder.go b/delete-order-req-builder.go
new file mode 100644
index 0000000..c7f2e3d
--- /dev/null
+++ b/delete-order-req-builder.go
@@ -0,0 +1,29 @@
+package cdek
+
+//NewDeleteOrderReq DeleteOrderReq constructor
+func NewDeleteOrderReq(number string, orderCount int, order DeleteOrder) *DeleteOrderReq {
+ return &DeleteOrderReq{
+ Number: &number,
+ OrderCount: &orderCount,
+ Order: &order,
+ }
+}
+
+//NewDeleteOrder DeleteOrder constructor
+func NewDeleteOrder() *DeleteOrder {
+ return new(DeleteOrder)
+}
+
+//SetNumber Client's shipment number. Order identifier in the IS of the CDEK client.
+func (o *DeleteOrder) SetNumber(number string) *DeleteOrder {
+ o.Number = &number
+
+ return o
+}
+
+//SetDispatchNumber CDEK order number
+func (o *DeleteOrder) SetDispatchNumber(dispatchNumber int) *DeleteOrder {
+ o.DispatchNumber = &dispatchNumber
+
+ return o
+}
diff --git a/delete-order-req-builder_test.go b/delete-order-req-builder_test.go
new file mode 100644
index 0000000..82549d2
--- /dev/null
+++ b/delete-order-req-builder_test.go
@@ -0,0 +1,167 @@
+package cdek
+
+import (
+ "reflect"
+ "testing"
+)
+
+func TestNewDeleteOrder(t *testing.T) {
+ tests := []struct {
+ name string
+ want *DeleteOrder
+ }{
+ {
+ name: "constructor",
+ want: &DeleteOrder{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewDeleteOrder(); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewDeleteOrder() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestDeleteOrder_SetNumber(t *testing.T) {
+ type fields struct {
+ Number *string
+ DispatchNumber *int
+ }
+ type args struct {
+ number string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *DeleteOrder
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: nil,
+ },
+ args: args{
+ number: "number-soOEl0",
+ },
+ want: &DeleteOrder{
+ Number: strLink("number-soOEl0"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("number-previous"),
+ },
+ args: args{
+ number: "number-soOEl0",
+ },
+ want: &DeleteOrder{
+ Number: strLink("number-soOEl0"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ o := &DeleteOrder{
+ Number: tt.fields.Number,
+ DispatchNumber: tt.fields.DispatchNumber,
+ }
+ if got := o.SetNumber(tt.args.number); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("DeleteOrder.SetNumber() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestDeleteOrder_SetDispatchNumber(t *testing.T) {
+ type fields struct {
+ Number *string
+ DispatchNumber *int
+ }
+ type args struct {
+ dispatchNumber int
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *DeleteOrder
+ }{
+ {
+ name: "set",
+ fields: fields{
+ DispatchNumber: nil,
+ },
+ args: args{
+ dispatchNumber: 1105048590,
+ },
+ want: &DeleteOrder{
+ DispatchNumber: intLink(1105048590),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ DispatchNumber: intLink(73472387282),
+ },
+ args: args{
+ dispatchNumber: 1105048590,
+ },
+ want: &DeleteOrder{
+ DispatchNumber: intLink(1105048590),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ o := &DeleteOrder{
+ Number: tt.fields.Number,
+ DispatchNumber: tt.fields.DispatchNumber,
+ }
+ if got := o.SetDispatchNumber(tt.args.dispatchNumber); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("DeleteOrder.SetDispatchNumber() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNewDeleteOrderReq(t *testing.T) {
+ type args struct {
+ number string
+ orderCount int
+ order DeleteOrder
+ }
+ tests := []struct {
+ name string
+ args args
+ want *DeleteOrderReq
+ }{
+ {
+ name: "constructor is ok",
+ args: args{
+ number: "test number",
+ orderCount: 1,
+ order: DeleteOrder{
+ Number: strLink("test order number"),
+ },
+ },
+ want: &DeleteOrderReq{
+ Number: strLink("test number"),
+ OrderCount: intLink(1),
+ Order: &DeleteOrder{
+ Number: strLink("test order number"),
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewDeleteOrderReq(tt.args.number, tt.args.orderCount, tt.args.order); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewDeleteOrderReq() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
diff --git a/delete-order-service.go b/delete-order-service.go
new file mode 100755
index 0000000..b8f25f6
--- /dev/null
+++ b/delete-order-service.go
@@ -0,0 +1,64 @@
+package cdek
+
+import (
+ "encoding/xml"
+ "io/ioutil"
+ "net/http"
+ "net/url"
+ "path"
+ "strings"
+
+ "github.com/hashicorp/go-multierror"
+)
+
+const deleteOrderURL = "delete_orders.php"
+
+//DeleteOrder The method is designed to cancel/delete an order at the client's initiative.
+func (c Client) DeleteOrder(req DeleteOrderReq) (*DeleteOrderResp, error) {
+ req.setAuth(c.auth)
+ reqByte, err := xml.Marshal(req)
+
+ if err != nil {
+ return nil, err
+ }
+
+ data := make(url.Values)
+ data.Add("xml_request", string(reqByte))
+
+ serverURL, err := url.Parse(c.apiURL)
+ if err != nil {
+ return nil, err
+ }
+
+ serverURL.Path = path.Join(serverURL.Path, deleteOrderURL)
+ reqURL := serverURL.String()
+
+ resp, err := http.Post(reqURL, urlFormEncoded, strings.NewReader(data.Encode()))
+ if err != nil {
+ return nil, err
+ }
+
+ defer func() {
+ _ = resp.Body.Close()
+ }()
+
+ body, _ := ioutil.ReadAll(resp.Body)
+
+ var deleteOrderResp DeleteOrderResp
+ err = xml.Unmarshal(body, &deleteOrderResp)
+ if err != nil {
+ return nil, err
+ }
+
+ multiError := &multierror.Error{}
+ for _, o := range deleteOrderResp.Order {
+ if o.IsErroneous() {
+ multiError = multierror.Append(o.GetError())
+ }
+ }
+ if multiError.Len() > 0 {
+ return nil, multiError.ErrorOrNil()
+ }
+
+ return &deleteOrderResp, nil
+}
diff --git a/delete-order-service_test.go b/delete-order-service_test.go
new file mode 100644
index 0000000..6da47b6
--- /dev/null
+++ b/delete-order-service_test.go
@@ -0,0 +1,218 @@
+package cdek
+
+import (
+ "encoding/json"
+ "encoding/xml"
+ "net/http"
+ "net/http/httptest"
+ "reflect"
+ "testing"
+)
+
+func deleteOrderGetMockServer() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _ = req.ParseForm()
+ xmlRequest := req.FormValue("xml_request")
+ var deleteOrderReq DeleteOrderReq
+ _ = xml.Unmarshal([]byte(xmlRequest), &deleteOrderReq)
+
+ if *deleteOrderReq.OrderCount > 1 {
+ _, _ = res.Write([]byte(`
+
+
+
+ b64b57647abbd3f7
+
+ `))
+
+ return
+ }
+
+ if *deleteOrderReq.Number != "number-soOEl0" {
+ _, _ = res.Write([]byte(`
+
+
+
+
+ 20f55f887b90d054
+
+ `))
+
+ return
+ }
+
+ _, _ = res.Write([]byte(`
+
+
+
+
+ 2a706c5c926fc49d
+
+ `))
+ }))
+}
+
+func deleteOrderGetMockServerWithError() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _, _ = res.Write([]byte("err"))
+ }))
+}
+
+func TestClient_DeleteOrder(t *testing.T) {
+ mockServer := deleteOrderGetMockServer()
+ defer mockServer.Close()
+
+ mockServerWithError := deleteOrderGetMockServerWithError()
+ defer mockServerWithError.Close()
+
+ type fields struct {
+ client Client
+ }
+ type args struct {
+ req DeleteOrderReq
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *DeleteOrderResp
+ wantErr bool
+ }{
+ {
+ name: "delete",
+ fields: fields{
+ client: Client{
+ apiURL: mockServer.URL,
+ },
+ },
+ args: args{
+ req: DeleteOrderReq{
+ Number: strLink("number-soOEl0"),
+ OrderCount: intLink(1),
+ Order: &DeleteOrder{
+ Number: strLink("number-soOEl0"),
+ },
+ },
+ },
+ want: &DeleteOrderResp{
+ Order: []*OrderResp{
+ {
+ DispatchNumber: intLink(1105048590),
+ Number: strLink("number-soOEl0"),
+ },
+ {
+ Error: Error{
+ Msg: strLink("Удалено заказов 1"),
+ },
+ },
+ },
+ },
+ wantErr: false,
+ },
+ {
+ name: "order not found",
+ fields: fields{
+ client: Client{
+ apiURL: mockServer.URL,
+ },
+ },
+ args: args{
+ req: DeleteOrderReq{
+ Number: strLink("test"),
+ OrderCount: intLink(1),
+ Order: &DeleteOrder{
+ Number: strLink("test_order_number"),
+ },
+ },
+ },
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "wrong quantity error",
+ fields: fields{
+ client: Client{
+ apiURL: mockServer.URL,
+ },
+ },
+ args: args{
+ req: DeleteOrderReq{
+ Number: strLink("test"),
+ OrderCount: intLink(2),
+ Order: &DeleteOrder{
+ Number: strLink("test_order_number"),
+ },
+ },
+ },
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "server error",
+ fields: fields{
+ client: Client{
+ apiURL: mockServerWithError.URL,
+ },
+ },
+ args: args{
+ req: DeleteOrderReq{},
+ },
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "wrong url",
+ fields: fields{
+ client: Client{
+ apiURL: "wrong://url",
+ },
+ },
+ args: args{
+ req: DeleteOrderReq{},
+ },
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "wrong parse url",
+ fields: fields{
+ client: Client{
+ apiURL: " wrong://url ",
+ },
+ },
+ args: args{
+ req: DeleteOrderReq{},
+ },
+ want: nil,
+ wantErr: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ cl := tt.fields.client
+ got, err := cl.DeleteOrder(tt.args.req)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("DeleteOrder() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ if !reflect.DeepEqual(got, tt.want) {
+ g, _ := json.Marshal(got)
+ w, _ := json.Marshal(tt.want)
+ t.Errorf("DeleteOrder() got = %v, want %v", string(g), string(w))
+ }
+ })
+ }
+}
+
+func ExampleClient_DeleteOrder() {
+ client := NewClient("https://integration.edu.cdek.ru/")
+ client.SetAuth("z9GRRu7FxmO53CQ9cFfI6qiy32wpfTkd", "w24JTCv4MnAcuRTx0oHjHLDtyt3I6IBq")
+
+ result, err := client.DeleteOrder(*NewDeleteOrderReq(
+ "number-soOEl0",
+ 1,
+ *NewDeleteOrder().SetNumber("number-soOEl0"),
+ ))
+
+ _, _ = result, err
+}
diff --git a/error-response.go b/error-response.go
new file mode 100644
index 0000000..12be0b6
--- /dev/null
+++ b/error-response.go
@@ -0,0 +1,42 @@
+package cdek
+
+import (
+ "fmt"
+ "strings"
+)
+
+//Error error values in responses
+type Error struct {
+ ErrorCode *string `xml:"ErrorCode,attr,omitempty" json:"code"`
+ Msg *string `xml:"Msg,attr,omitempty" json:"text"`
+}
+
+//IsErroneous check if struct has error
+func (e *Error) IsErroneous() bool {
+ return e.ErrorCode != nil
+}
+
+func (e Error) Error() string {
+ errorMsgParts := []string{
+ *e.Msg,
+ fmt.Sprintf("ErrorCode: %s", *e.ErrorCode),
+ }
+
+ return strings.Join(errorMsgParts, "; ")
+}
+
+//AlertResponse CDEK Alerts model
+type AlertResponse struct {
+ Alerts []*Alert
+}
+
+//Alert CDEK Alert model
+type Alert struct {
+ Type string
+ Msg string
+ ErrorCode string
+}
+
+func (a *Alert) Error() string {
+ return fmt.Sprintf("Type: %s; Msg: %s; ErrorCode: %s", a.Type, a.Msg, a.ErrorCode)
+}
diff --git a/error-response_test.go b/error-response_test.go
new file mode 100644
index 0000000..d373a9c
--- /dev/null
+++ b/error-response_test.go
@@ -0,0 +1,110 @@
+package cdek
+
+import "testing"
+
+func TestError_IsErroneous(t *testing.T) {
+ type fields struct {
+ ErrorCode *string
+ Msg *string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ want bool
+ }{
+ {
+ name: "is erroneous",
+ fields: fields{
+ ErrorCode: strLink("some_code"),
+ Msg: strLink("some message"),
+ },
+ want: true,
+ },
+ {
+ name: "is not erroneous",
+ fields: fields{
+ ErrorCode: nil,
+ Msg: nil,
+ },
+ want: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ e := &Error{
+ ErrorCode: tt.fields.ErrorCode,
+ Msg: tt.fields.Msg,
+ }
+ if got := e.IsErroneous(); got != tt.want {
+ t.Errorf("Error.IsErroneous() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestError_Error(t *testing.T) {
+ type fields struct {
+ ErrorCode *string
+ Msg *string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ want string
+ }{
+ {
+ name: "make error string",
+ fields: fields{
+ ErrorCode: strLink("some_code"),
+ Msg: strLink("some message"),
+ },
+ want: "some message; ErrorCode: some_code",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ e := Error{
+ ErrorCode: tt.fields.ErrorCode,
+ Msg: tt.fields.Msg,
+ }
+ if got := e.Error(); got != tt.want {
+ t.Errorf("Error.Error() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestAlert_Error(t *testing.T) {
+ type fields struct {
+ Type string
+ Msg string
+ ErrorCode string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ want string
+ }{
+ {
+ name: "make error string",
+ fields: fields{
+ Type: "some_type",
+ Msg: "some message",
+ ErrorCode: "some_code",
+ },
+ want: "Type: some_type; Msg: some message; ErrorCode: some_code",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ a := &Alert{
+ Type: tt.fields.Type,
+ Msg: tt.fields.Msg,
+ ErrorCode: tt.fields.ErrorCode,
+ }
+ if got := a.Error(); got != tt.want {
+ t.Errorf("Alert.Error() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..5fa06ff
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,5 @@
+module github.com/vseinstrumentiru/cdek
+
+go 1.12
+
+require github.com/hashicorp/go-multierror v1.0.0
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..d2f1330
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,4 @@
+github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
+github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
+github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o=
+github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
diff --git a/pvzlist-filter.go b/pvzlist-filter.go
new file mode 100755
index 0000000..a6e1b31
--- /dev/null
+++ b/pvzlist-filter.go
@@ -0,0 +1,74 @@
+package cdek
+
+//PvzListFilter key for filtering pvzList
+type PvzListFilter string
+
+const (
+ //PvzListFilterCityPostCode Почтовый индекс города, для которого необходим список ПВЗ
+ PvzListFilterCityPostCode PvzListFilter = "citypostcode"
+
+ //PvzListFilterCityID Код города по базе СДЭК
+ PvzListFilterCityID PvzListFilter = "cityid"
+
+ //PvzListFilterType Тип пункта выдачи, по умолчанию «PVZ».
+ PvzListFilterType PvzListFilter = "type"
+
+ //PvzListFilterCountryID Код страны по базе СДЭК
+ PvzListFilterCountryID PvzListFilter = "countryid"
+
+ //PvzListFilterCountryIso Код страны в формате ISO_3166-1_alpha-2
+ PvzListFilterCountryIso PvzListFilter = "countryiso"
+
+ //PvzListFilterRegionID Код региона по базе СДЭК
+ PvzListFilterRegionID PvzListFilter = "regionid"
+
+ //PvzListFilterHaveCashless Наличие терминала оплаты («1», «true» - есть; «0», «false» - нет.)
+ PvzListFilterHaveCashless PvzListFilter = "havecashless"
+
+ //PvzListFilterAllowedCod Разрешен наложенный платеж («1», «true» - да; «0», «false» - нет.)
+ PvzListFilterAllowedCod PvzListFilter = "allowedcod"
+
+ //PvzListFilterIsDressingRoom Наличие примерочной («1», «true» - есть; «0», «false» - нет.)
+ PvzListFilterIsDressingRoom PvzListFilter = "isdressingroom"
+
+ //PvzListFilterWeightMax Максимальный вес, который может принять ПВЗ
+ PvzListFilterWeightMax PvzListFilter = "weightmax"
+
+ //PvzListFilterLang Локализация ПВЗ. По-умолчанию "rus"
+ PvzListFilterLang PvzListFilter = "lang"
+
+ //PvzListFilterTakeOnly Является ли ПВЗ только пунктом выдачи («1», «true» - да; «0», «false» - нет.)
+ PvzListFilterTakeOnly PvzListFilter = "takeonly"
+)
+
+const (
+ //TypePvz только склады СДЭК
+ TypePvz string = "PVZ"
+
+ //TypePostomat постоматы партнёра
+ TypePostomat string = "POSTOMAT"
+
+ //TypeAll все ПВЗ не зависимо от их типа
+ TypeAll string = "ALL"
+)
+
+//PvzListFilterBuilder builder for pvzList filter
+type PvzListFilterBuilder struct {
+ filter map[PvzListFilter]string
+}
+
+//AddFilter adds filter for pvzList filter
+func (filterBuilder *PvzListFilterBuilder) AddFilter(filter PvzListFilter, value string) *PvzListFilterBuilder {
+ if filterBuilder.filter == nil {
+ filterBuilder.filter = make(map[PvzListFilter]string)
+ }
+
+ filterBuilder.filter[filter] = value
+
+ return filterBuilder
+}
+
+//Filter returns complete filter
+func (filterBuilder PvzListFilterBuilder) Filter() map[PvzListFilter]string {
+ return filterBuilder.filter
+}
diff --git a/pvzlist-filter_test.go b/pvzlist-filter_test.go
new file mode 100644
index 0000000..5cfb52d
--- /dev/null
+++ b/pvzlist-filter_test.go
@@ -0,0 +1,118 @@
+package cdek
+
+import (
+ "reflect"
+ "testing"
+)
+
+func TestPvzListFilterBuilder_AddFilter(t *testing.T) {
+ type fields struct {
+ filter map[PvzListFilter]string
+ }
+ type args struct {
+ filter PvzListFilter
+ value string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *PvzListFilterBuilder
+ }{
+ {
+ name: "add single filter",
+ fields: fields{
+ filter: nil,
+ },
+ args: args{
+ filter: PvzListFilterCityID,
+ value: "33",
+ },
+ want: &PvzListFilterBuilder{
+ filter: map[PvzListFilter]string{
+ PvzListFilterCityID: "33",
+ },
+ },
+ },
+ {
+ name: "rewrite filter",
+ fields: fields{
+ filter: map[PvzListFilter]string{
+ PvzListFilterCityID: "55",
+ },
+ },
+ args: args{
+ filter: PvzListFilterCityID,
+ value: "66",
+ },
+ want: &PvzListFilterBuilder{
+ filter: map[PvzListFilter]string{
+ PvzListFilterCityID: "66",
+ },
+ },
+ },
+ {
+ name: "add filter",
+ fields: fields{
+ filter: map[PvzListFilter]string{
+ PvzListFilterCityID: "77",
+ },
+ },
+ args: args{
+ filter: PvzListFilterRegionID,
+ value: "b8837188-39ee-4ff9-bc91-fcc9ed451bb3",
+ },
+ want: &PvzListFilterBuilder{
+ filter: map[PvzListFilter]string{
+ PvzListFilterCityID: "77",
+ PvzListFilterRegionID: "b8837188-39ee-4ff9-bc91-fcc9ed451bb3",
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ filterBuilder := &PvzListFilterBuilder{
+ filter: tt.fields.filter,
+ }
+ if got := filterBuilder.AddFilter(tt.args.filter, tt.args.value); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("AddFilter() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestPvzListFilterBuilder_Filter(t *testing.T) {
+ type fields struct {
+ filter map[PvzListFilter]string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ want map[PvzListFilter]string
+ }{
+ {
+ name: "multiple filters",
+ fields: fields{
+ filter: map[PvzListFilter]string{
+ PvzListFilterCityID: "77",
+ PvzListFilterRegionID: "b8837188-39ee-4ff9-bc91-fcc9ed451bb3",
+ },
+ },
+ want: map[PvzListFilter]string{
+ PvzListFilterCityID: "77",
+ PvzListFilterRegionID: "b8837188-39ee-4ff9-bc91-fcc9ed451bb3",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ filterBuilder := PvzListFilterBuilder{
+ filter: tt.fields.filter,
+ }
+ if got := filterBuilder.Filter(); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Filter() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
diff --git a/pvzlist-models.go b/pvzlist-models.go
new file mode 100644
index 0000000..29857bb
--- /dev/null
+++ b/pvzlist-models.go
@@ -0,0 +1,57 @@
+package cdek
+
+type pvzList struct {
+ Pvz []*Pvz `xml:"Pvz"`
+}
+
+//Pvz List of Pickup Points
+type Pvz struct {
+ Code *string `xml:"Code,attr"`
+ PostalCode *string `xml:"PostalCode,attr"`
+ Name *string `xml:"Name,attr"`
+ CountryCode *string `xml:"CountryCode,attr"`
+ CountryCodeIso *string `xml:"countryCodeIso,attr"`
+ CountryName *string `xml:"CountryName,attr"`
+ RegionCode *string `xml:"RegionCode,attr"`
+ RegionName *string `xml:"RegionName,attr"`
+ CityCode *int `xml:"CityCode,attr"`
+ City *string `xml:"City,attr"`
+ WorkTime *string `xml:"WorkTime,attr"`
+ Address *string `xml:"Address,attr"`
+ FullAddress *string `xml:"FullAddress,attr"`
+ AddressComment *string `xml:"AddressComment,attr"`
+ Phone *string `xml:"Phone,attr"`
+ Email *string `xml:"Email,attr"`
+ QqID *string `xml:"qqId,attr"`
+ Note *string `xml:"Note,attr"`
+ CoordX *float64 `xml:"coordX,attr"`
+ CoordY *float64 `xml:"coordY,attr"`
+ Type *string `xml:"Type,attr"`
+ OwnerCode *string `xml:"ownerCode,attr"`
+ IsDressingRoom *bool `xml:"IsDressingRoom,attr"`
+ HaveCashless *bool `xml:"HaveCashless,attr"`
+ AllowedCod *bool `xml:"AllowedCod,attr"`
+ NearestStation *string `xml:"NearestStation,attr"`
+ MetroStation *string `xml:"MetroStation,attr"`
+ Site *string `xml:"Site,attr"`
+ OfficeImage []*OfficeImage `xml:"OfficeImage"`
+ WorkTimeY []*WorkTimeY `xml:"WorkTimeY"`
+ WeightLimit *WeightLimit `xml:"WeightLimit"`
+}
+
+//OfficeImage All photos of the office (except for a photo showing how to get to it)
+type OfficeImage struct {
+ URL *string `xml:"url,attr"`
+}
+
+//WorkTimeY Opening hours for every day
+type WorkTimeY struct {
+ Day *int `xml:"day,attr"`
+ Periods *string `xml:"periods,attr"`
+}
+
+//WeightLimit Weight limits for a pickup point (the tag is used only if limits are set)
+type WeightLimit struct {
+ WeightMin *float64 `xml:"WeightMin,attr"`
+ WeightMax *float64 `xml:"WeightMax,attr"`
+}
diff --git a/pvzlist-service.go b/pvzlist-service.go
new file mode 100755
index 0000000..3ab18bf
--- /dev/null
+++ b/pvzlist-service.go
@@ -0,0 +1,48 @@
+package cdek
+
+import (
+ "encoding/xml"
+ "io/ioutil"
+ "net/http"
+ "net/url"
+ "path"
+)
+
+const pvzListURL = "pvzlist/v1/xml"
+
+//GetPvzList The method is used to load the list of active pickup points, from which the client can pick up its order.
+func (c Client) GetPvzList(filter map[PvzListFilter]string) ([]*Pvz, error) {
+ serverURL, err := url.Parse(c.apiURL)
+ if err != nil {
+ return nil, err
+ }
+
+ serverURL.Path = path.Join(serverURL.Path, pvzListURL)
+
+ queryString := serverURL.Query()
+ for filterKey, value := range filter {
+ queryString.Set(string(filterKey), value)
+ }
+ serverURL.RawQuery = queryString.Encode()
+
+ reqURL := serverURL.String()
+
+ resp, err := http.Get(reqURL)
+ if err != nil {
+ return nil, err
+ }
+
+ defer func() {
+ _ = resp.Body.Close()
+ }()
+
+ body, _ := ioutil.ReadAll(resp.Body)
+
+ var pvzList pvzList
+ err = xml.Unmarshal(body, &pvzList)
+ if err != nil {
+ return nil, err
+ }
+
+ return pvzList.Pvz, nil
+}
diff --git a/pvzlist-service_test.go b/pvzlist-service_test.go
new file mode 100644
index 0000000..aa53a06
--- /dev/null
+++ b/pvzlist-service_test.go
@@ -0,0 +1,221 @@
+package cdek
+
+import (
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "reflect"
+ "strconv"
+ "testing"
+)
+
+func getPvzListGetMockServer() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _, _ = res.Write([]byte(`
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `))
+ }))
+}
+
+func getPvzListGetMockServerWithError() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _, _ = res.Write([]byte("err"))
+ }))
+}
+
+func TestClient_GetPvzList(t *testing.T) {
+ mockServer := getPvzListGetMockServer()
+ defer mockServer.Close()
+
+ mockServerWithError := getPvzListGetMockServerWithError()
+ defer mockServerWithError.Close()
+
+ type fields struct {
+ client Client
+ }
+ type args struct {
+ filter map[PvzListFilter]string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want []*Pvz
+ wantErr bool
+ }{
+ {
+ "server ok",
+ fields{
+ Client{
+ apiURL: mockServer.URL,
+ },
+ },
+ args{
+ map[PvzListFilter]string{
+ PvzListFilterCityID: strconv.Itoa(7),
+ },
+ },
+ []*Pvz{
+ {
+ Code: strLink("MIA2"),
+ PostalCode: strLink("456300"),
+ Name: strLink("На Романенко"),
+ CountryCode: strLink("1"),
+ CountryCodeIso: strLink("RU"),
+ CountryName: strLink("Россия"),
+ RegionCode: strLink("3"),
+ RegionName: strLink("Челябинская обл."),
+ CityCode: intLink(7),
+ City: strLink("Миасс"),
+ WorkTime: strLink("Пн-Пт 09:00-19:00, Сб 10:00-16:00"),
+ Address: strLink("ул. Романенко, 93"),
+ FullAddress: strLink("Россия, Челябинская обл., Миасс, ул. Романенко, 93"),
+ AddressComment: strLink("Бывший магазин Престиж, выше ТРК «Слон»"),
+ Phone: strLink("+79511247307, +73513284466"),
+ Email: strLink("n.andruschuk@cdek.ru"),
+ QqID: strLink(""),
+ Note: strLink(""),
+ CoordX: float64Link(60.112205),
+ CoordY: float64Link(55.047874),
+ Type: strLink("PVZ"),
+ OwnerCode: strLink("cdek"),
+ IsDressingRoom: boolLink(true),
+ HaveCashless: boolLink(true),
+ AllowedCod: boolLink(true),
+ NearestStation: strLink("«Центр», «Лихачева»"),
+ MetroStation: strLink(""),
+ Site: strLink(""),
+ OfficeImage: []*OfficeImage{
+ {
+ strLink("edu.api-pvz.imageRepository.service.cdek.tech:8008/images/2638/3222_1_MIA2"),
+ },
+ {
+ strLink("edu.api-pvz.imageRepository.service.cdek.tech:8008/images/2638/3230_2_MIA2"),
+ },
+ {
+ strLink("edu.api-pvz.imageRepository.service.cdek.tech:8008/images/2638/3231_3_MIA2"),
+ },
+ {
+ strLink("edu.api-pvz.imageRepository.service.cdek.tech:8008/images/2638/3232_4_MIA2"),
+ },
+ },
+ WorkTimeY: []*WorkTimeY{
+ {
+ Day: intLink(1),
+ Periods: strLink("09:00/19:00"),
+ },
+ {
+ Day: intLink(2),
+ Periods: strLink("09:00/19:00"),
+ },
+ {
+ Day: intLink(3),
+ Periods: strLink("09:00/19:00"),
+ },
+ {
+ Day: intLink(4),
+ Periods: strLink("09:00/19:00"),
+ },
+ {
+ Day: intLink(5),
+ Periods: strLink("09:00/19:00"),
+ },
+ {
+ Day: intLink(6),
+ Periods: strLink("10:00/16:00"),
+ },
+ },
+ },
+ },
+ false,
+ },
+ {
+ "server error",
+ fields{
+ Client{
+ apiURL: mockServerWithError.URL,
+ },
+ },
+ args{},
+ nil,
+ true,
+ },
+ {
+ "wrong url parse error",
+ fields{
+ Client{
+ apiURL: " wrong://url ",
+ },
+ },
+ args{},
+ nil,
+ true,
+ },
+ {
+ "wrong url",
+ fields{
+ Client{
+ apiURL: "wrong://url",
+ },
+ },
+ args{},
+ nil,
+ true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ cl := tt.fields.client
+ got, err := cl.GetPvzList(tt.args.filter)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("Client.GetPvzList() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ g, _ := json.Marshal(got)
+ w, _ := json.Marshal(tt.want)
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Client.GetPvzList() = \n %v \n, want \n %v", string(g), string(w))
+ }
+ })
+ }
+}
+
+func ExampleClient_GetPvzList() {
+ client := NewClient("https://integration.edu.cdek.ru/")
+ client.SetAuth("z9GRRu7FxmO53CQ9cFfI6qiy32wpfTkd", "w24JTCv4MnAcuRTx0oHjHLDtyt3I6IBq")
+
+ result, err := client.GetPvzList(map[PvzListFilter]string{
+ PvzListFilterCityID: "44",
+ })
+
+ _, _ = result, err
+}
diff --git a/region-filter.go b/region-filter.go
new file mode 100755
index 0000000..3a03c59
--- /dev/null
+++ b/region-filter.go
@@ -0,0 +1,48 @@
+package cdek
+
+//RegionFilter filter key for "List of Regions" request
+type RegionFilter string
+
+const (
+ //RegionFilterRegionCodeExt Region code
+ RegionFilterRegionCodeExt RegionFilter = "regionCodeExt"
+
+ //RegionFilterRegionCode Region code in the CDEK IS
+ RegionFilterRegionCode RegionFilter = "regionCode"
+
+ //RegionFilterRegionFiasGUID Region code according to the Federal Information Address System
+ RegionFilterRegionFiasGUID RegionFilter = "regionFiasGuid"
+
+ //RegionFilterCountryCode Country code in the CDEK IS
+ RegionFilterCountryCode RegionFilter = "countryCode"
+
+ //RegionFilterCountryCodeExt Code according to the Russian Classifier of Countries of the World
+ RegionFilterCountryCodeExt RegionFilter = "countryCodeExt"
+
+ //RegionFilterPage Number of the results page. Default value: 0
+ RegionFilterPage RegionFilter = "page"
+
+ //RegionFilterSize Limitation on the number of results displayed. Default value: 1,000
+ RegionFilterSize RegionFilter = "size"
+)
+
+//RegionFilterBuilder builder for filer for "List of Regions" request
+type RegionFilterBuilder struct {
+ filter map[RegionFilter]string
+}
+
+//AddFilter add filter to set of filters for "List of Regions" request
+func (filterBuilder *RegionFilterBuilder) AddFilter(filter RegionFilter, value string) *RegionFilterBuilder {
+ if filterBuilder.filter == nil {
+ filterBuilder.filter = make(map[RegionFilter]string)
+ }
+
+ filterBuilder.filter[filter] = value
+
+ return filterBuilder
+}
+
+//Filter compile RegionFilterBuilder for "List of Regions" request
+func (filterBuilder *RegionFilterBuilder) Filter() map[RegionFilter]string {
+ return filterBuilder.filter
+}
diff --git a/region-filter_test.go b/region-filter_test.go
new file mode 100644
index 0000000..d683b41
--- /dev/null
+++ b/region-filter_test.go
@@ -0,0 +1,118 @@
+package cdek
+
+import (
+ "reflect"
+ "testing"
+)
+
+func TestRegionFilterBuilder_AddFilter(t *testing.T) {
+ type fields struct {
+ filter map[RegionFilter]string
+ }
+ type args struct {
+ filter RegionFilter
+ value string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *RegionFilterBuilder
+ }{
+ {
+ name: "add single filter",
+ fields: fields{
+ filter: nil,
+ },
+ args: args{
+ filter: RegionFilterPage,
+ value: "3",
+ },
+ want: &RegionFilterBuilder{
+ filter: map[RegionFilter]string{
+ RegionFilterPage: "3",
+ },
+ },
+ },
+ {
+ name: "rewrite filter",
+ fields: fields{
+ filter: map[RegionFilter]string{
+ RegionFilterPage: "3",
+ },
+ },
+ args: args{
+ filter: RegionFilterPage,
+ value: "2",
+ },
+ want: &RegionFilterBuilder{
+ filter: map[RegionFilter]string{
+ RegionFilterPage: "2",
+ },
+ },
+ },
+ {
+ name: "add filter",
+ fields: fields{
+ filter: map[RegionFilter]string{
+ RegionFilterPage: "2",
+ },
+ },
+ args: args{
+ filter: RegionFilterRegionCode,
+ value: "b8837188-39ee-4ff9-bc91-fcc9ed451bb3",
+ },
+ want: &RegionFilterBuilder{
+ filter: map[RegionFilter]string{
+ RegionFilterPage: "2",
+ RegionFilterRegionCode: "b8837188-39ee-4ff9-bc91-fcc9ed451bb3",
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ filterBuilder := &RegionFilterBuilder{
+ filter: tt.fields.filter,
+ }
+ if got := filterBuilder.AddFilter(tt.args.filter, tt.args.value); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("AddFilter() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestRegionFilterBuilder_Filter(t *testing.T) {
+ type fields struct {
+ filter map[RegionFilter]string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ want map[RegionFilter]string
+ }{
+ {
+ name: "multiple filters",
+ fields: fields{
+ filter: map[RegionFilter]string{
+ RegionFilterPage: "2",
+ RegionFilterRegionCode: "b8837188-39ee-4ff9-bc91-fcc9ed451bb3",
+ },
+ },
+ want: map[RegionFilter]string{
+ RegionFilterPage: "2",
+ RegionFilterRegionCode: "b8837188-39ee-4ff9-bc91-fcc9ed451bb3",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ filterBuilder := &RegionFilterBuilder{
+ filter: tt.fields.filter,
+ }
+ if got := filterBuilder.Filter(); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Filter() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
diff --git a/region-models.go b/region-models.go
new file mode 100644
index 0000000..5fefd9f
--- /dev/null
+++ b/region-models.go
@@ -0,0 +1,17 @@
+package cdek
+
+//GetRegionsResp List of Regions response
+type GetRegionsResp []Region
+
+//Region Region response
+type Region struct {
+ RegionUUID *string `json:"regionUuid"`
+ RegionName *string `json:"regionName"`
+ Prefix *string `json:"prefix,omitempty"`
+ RegionCodeExt *int `json:"regionCodeExt,string,omitempty"`
+ RegionCode *int `json:"regionCode,string,omitempty"`
+ RegionFiasGUID *string `json:"regionFiasGuid,omitempty"`
+ CountryName *string `json:"countryName"`
+ CountryCode *string `json:"countryCode,omitempty"`
+ CountryCodeExt *int `json:"countryCodeExt,omitempty,string"`
+}
diff --git a/region-service.go b/region-service.go
new file mode 100755
index 0000000..dfa48a7
--- /dev/null
+++ b/region-service.go
@@ -0,0 +1,61 @@
+package cdek
+
+import (
+ "encoding/json"
+ "io/ioutil"
+ "net/http"
+ "net/url"
+ "path"
+
+ "github.com/hashicorp/go-multierror"
+)
+
+const regionsURL = "/v1/location/regions/json"
+
+//GetRegions This method is used to load detailed information on regions.
+func (c Client) GetRegions(filter map[RegionFilter]string) (*GetRegionsResp, error) {
+ serverURL, err := url.Parse(c.apiURL)
+ if err != nil {
+ return nil, err
+ }
+
+ serverURL.Path = path.Join(serverURL.Path, regionsURL)
+
+ queryString := serverURL.Query()
+ for filterKey, value := range filter {
+ queryString.Set(string(filterKey), value)
+ }
+ serverURL.RawQuery = queryString.Encode()
+
+ reqURL := serverURL.String()
+
+ resp, err := http.Get(reqURL)
+ if err != nil {
+ return nil, err
+ }
+
+ defer func() {
+ _ = resp.Body.Close()
+ }()
+
+ body, _ := ioutil.ReadAll(resp.Body)
+
+ var regions GetRegionsResp
+ err = json.Unmarshal(body, ®ions)
+ if err != nil {
+ var alertResponse AlertResponse
+ err = json.Unmarshal(body, &alertResponse)
+ if err != nil {
+ return nil, err
+ }
+
+ multiError := &multierror.Error{}
+ for _, alert := range alertResponse.Alerts {
+ multiError = multierror.Append(alert)
+ }
+
+ return nil, multiError.ErrorOrNil()
+ }
+
+ return ®ions, nil
+}
diff --git a/region-service_test.go b/region-service_test.go
new file mode 100644
index 0000000..f517a4e
--- /dev/null
+++ b/region-service_test.go
@@ -0,0 +1,166 @@
+package cdek
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "reflect"
+ "testing"
+)
+
+func TestClient_GetRegions(t *testing.T) {
+ mockServer := getRegionsMockServer()
+ defer mockServer.Close()
+
+ mockServerWithValidError := getRegionsMockServerWithValidError()
+ defer mockServerWithValidError.Close()
+
+ mockServerWithError := getRegionsMockServerWithError()
+ defer mockServerWithError.Close()
+
+ type fields struct {
+ client Client
+ }
+ type args struct {
+ filter map[RegionFilter]string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *GetRegionsResp
+ wantErr bool
+ }{
+ {
+ name: "handle response",
+ fields: fields{
+ client: Client{
+ apiURL: mockServer.URL,
+ },
+ },
+ args: args{
+ filter: map[RegionFilter]string{
+ RegionFilterRegionFiasGUID: "61723327-1c20-42fe-8dfa-402638d9b396",
+ },
+ },
+ want: &GetRegionsResp{
+ Region{
+ RegionUUID: strLink("18aff43f-58b8-4608-ade7-92fdab7fc39f"),
+ RegionName: strLink("Тверская"),
+ Prefix: strLink("обл"),
+ RegionCodeExt: intLink(69),
+ RegionCode: intLink(50),
+ RegionFiasGUID: strLink("61723327-1c20-42fe-8dfa-402638d9b396"),
+ CountryName: strLink("Россия"),
+ CountryCode: strLink("RU"),
+ CountryCodeExt: intLink(643),
+ },
+ },
+ wantErr: false,
+ },
+ {
+ name: "handle valid error",
+ fields: fields{
+ client: Client{
+ apiURL: mockServerWithValidError.URL,
+ },
+ },
+ args: args{
+ filter: map[RegionFilter]string{
+ RegionFilterRegionFiasGUID: "61723327-1c20-42fe-8dfa-402638d9b396",
+ },
+ },
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "uncompilable url",
+ fields: fields{
+ client: Client{
+ apiURL: " wrong://url ",
+ },
+ },
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "wrong url",
+ fields: fields{
+ client: Client{
+ apiURL: "wrong://url",
+ },
+ },
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "server error",
+ fields: fields{
+ client: Client{
+ apiURL: mockServerWithError.URL,
+ },
+ },
+ want: nil,
+ wantErr: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ cl := tt.fields.client
+ got, err := cl.GetRegions(tt.args.filter)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("Client.GetRegions() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Client.GetRegions() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func getRegionsMockServer() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _, _ = res.Write([]byte(`[
+ {
+ "regionName":"Тверская",
+ "regionCode":"50",
+ "regionUuid":"18aff43f-58b8-4608-ade7-92fdab7fc39f",
+ "prefix":"обл",
+ "regionCodeExt":"69",
+ "regionFiasGuid":"61723327-1c20-42fe-8dfa-402638d9b396",
+ "countryName":"Россия",
+ "countryCode":"RU",
+ "countryCodeExt":"643"
+ }
+ ]`))
+ }))
+}
+
+func getRegionsMockServerWithValidError() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _, _ = res.Write([]byte(`
+ {
+ "alerts": [
+ {"type":"danger","msg":"API location not available","errorCode":"connector.location.error.send"}
+ ]
+ }
+ `))
+ }))
+}
+
+func getRegionsMockServerWithError() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _, _ = res.Write([]byte("err"))
+ }))
+}
+
+func ExampleClient_GetRegions() {
+ client := NewClient("https://integration.edu.cdek.ru/")
+ client.SetAuth("z9GRRu7FxmO53CQ9cFfI6qiy32wpfTkd", "w24JTCv4MnAcuRTx0oHjHLDtyt3I6IBq")
+
+ result, err := client.GetRegions(map[RegionFilter]string{
+ RegionFilterPage: "3",
+ })
+
+ _, _ = result, err
+}
diff --git a/register-order-models.go b/register-order-models.go
new file mode 100644
index 0000000..bc2bc42
--- /dev/null
+++ b/register-order-models.go
@@ -0,0 +1,201 @@
+package cdek
+
+import (
+ "encoding/xml"
+ "errors"
+ "fmt"
+ "strings"
+)
+
+//RegisterOrderReq Order registration request
+type RegisterOrderReq struct {
+ securableXML
+ XMLName xml.Name `xml:"DeliveryRequest"`
+ Number *string `xml:"Number,attr"`
+ OrderCount *int `xml:"OrderCount,attr"`
+ Currency *string `xml:"Currency,attr,omitempty"`
+ Order *OrderReq `xml:"Order"`
+ CallCourier *CallCourier `xml:"CallCourier"`
+}
+
+//OrderReq Shipment (order)
+type OrderReq struct {
+ Number *string `xml:"Number,attr"`
+ SendCityCode *int `xml:"SendCityCode,attr"`
+ RecCityCode *int `xml:"RecCityCode,attr"`
+ SendCityPostCode *int `xml:"SendCityPostCode,attr"`
+ RecCityPostCode *int `xml:"RecCityPostCode,attr"`
+ SendCountryCode *int `xml:"SendCountryCode,attr,omitempty"`
+ RecCountryCode *int `xml:"RecCountryCode,attr,omitempty"`
+ SendCityName *string `xml:"SendCityName,attr,omitempty"`
+ RecCityName *string `xml:"RecCityName,attr,omitempty"`
+ RecipientINN *string `xml:"RecipientINN,attr,omitempty"`
+ DateInvoice *string `xml:"DateInvoice,attr,omitempty"`
+ ShipperName *string `xml:"ShipperName,attr,omitempty"`
+ ShipperAddress *string `xml:"ShipperAddress,attr,omitempty"`
+ Passport *Passport `xml:"Passport,omitempty"`
+ Sender *Sender `xml:"Sender,omitempty"`
+ RecipientName *string `xml:"RecipientName,attr"`
+ RecipientEmail *string `xml:"RecipientEmail,attr,omitempty"`
+ Phone *string `xml:"Phone,attr"`
+ TariffTypeCode *int `xml:"TariffTypeCode,attr"`
+ DeliveryRecipientCost *float64 `xml:"DeliveryRecipientCost,attr,omitempty"`
+ DeliveryRecipientVATRate *string `xml:"DeliveryRecipientVATRate,attr,omitempty"`
+ DeliveryRecipientVATSum *float64 `xml:"DeliveryRecipientVATSum,attr,omitempty"`
+ RecipientCurrency *string `xml:"RecipientCurrency,attr,omitempty"`
+ ItemsCurrency *string `xml:"ItemsCurrency,attr,omitempty"`
+ Seller *Seller `xml:"Seller,omitempty"`
+ Comment *string `xml:"Comment,attr,omitempty"`
+ Address *Address `xml:"Address,omitempty"`
+ Package []*OrderPackage `xml:"Package,omitempty"`
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv `xml:"DeliveryRecipientCostAdv,omitempty"`
+ AddService *AddService `xml:"AddService,omitempty"`
+ Schedule *Schedule `xml:"Schedule,omitempty"`
+}
+
+//Passport Details of the receiver’s passport. Used to print waybills. Only for international orders.
+type Passport struct {
+ Series *string `xml:"Series,attr"`
+ Number *string `xml:"Number,attr"`
+ IssueDate *string `xml:"IssueDate,attr"`
+ IssuedBy *string `xml:"IssuedBy,attr"`
+ DateBirth *string `xml:"DateBirth,attr"`
+}
+
+//Sender Sender. Must be defined if it is different from the online store Client.
+// If the online store is a sender, the Sender tag is not available.
+type Sender struct {
+ Company *string `xml:"Company,attr"`
+ Name *string `xml:"Name,attr"`
+ Address *Address `xml:"Address,omitempty"`
+ Phone []*string `xml:"Phone,omitempty"`
+}
+
+//Address Address of pickup
+type Address struct {
+ Street *string `xml:"Street,attr"`
+ House *string `xml:"House,attr"`
+ Flat *string `xml:"Flat,attr,omitempty"`
+ Phone *string `xml:"Phone,attr,omitempty"`
+ PvzCode *string `xml:"PvzCode,attr,omitempty"`
+}
+
+//Seller Requisites of the real seller
+type Seller struct {
+ Address *string `xml:"Address,attr,omitempty"`
+ Name *string `xml:"Name,attr,omitempty"`
+ INN *string `xml:"INN,attr,omitempty"`
+ Phone *string `xml:"Phone,attr,omitempty"`
+ OwnershipForm *int `xml:"OwnershipForm,attr,omitempty"`
+}
+
+//OrderPackage Package (all packages are sent with different Package tags)
+type OrderPackage struct {
+ Number *string `xml:"Number,attr"`
+ BarCode *string `xml:"BarCode,attr"`
+ Weight *int `xml:"Weight,attr"`
+ SizeA *int `xml:"SizeA,attr,omitempty"`
+ SizeB *int `xml:"SizeB,attr,omitempty"`
+ SizeC *int `xml:"SizeC,attr,omitempty"`
+ Item []*OrderPackageItem `xml:"Item"`
+}
+
+//OrderPackageItem Items (goods)
+type OrderPackageItem struct {
+ Amount *int `xml:"Amount,attr"`
+ WareKey *string `xml:"WareKey,attr"`
+ Cost *float64 `xml:"Cost,attr"`
+ Payment *float64 `xml:"Payment,attr"`
+ PaymentVATRate *string `xml:"PaymentVATRate,attr,omitempty"`
+ PaymentVATSum *float64 `xml:"PaymentVATSum,attr,omitempty"`
+ Weight *int `xml:"Weight,attr"`
+ Comment *string `xml:"Comment,attr"`
+ WeightBrutto *int `xml:"WeightBrutto,attr,omitempty"`
+ CommentEx *string `xml:"CommentEx,attr,omitempty"`
+ Link *string `xml:"Link,attr,omitempty"`
+}
+
+//DeliveryRecipientCostAdv Additional charge for delivery (E-shop charges the receiver), depending on the order’s sum
+type DeliveryRecipientCostAdv struct {
+ Threshold *int `xml:"Threshold,attr"`
+ Sum *float64 `xml:"Sum,attr"`
+ VATRate *string `xml:"VATRate,attr,omitempty"`
+ VATSum *float64 `xml:"VATSum,attr,omitempty"`
+}
+
+//AddService Additional services
+type AddService struct {
+ ServiceCode *int `xml:"ServiceCode,attr"`
+ Count *int `xml:"Count,attr,omitempty"`
+}
+
+//Schedule Schedule for delivery/pickup
+type Schedule struct {
+ Attempt []*ScheduleAttempt `xml:"Attempt"`
+}
+
+//ScheduleAttempt Time of delivery (one time interval not less than 3 hours is permitted for one day)
+type ScheduleAttempt struct {
+ ID *string `xml:"ID,attr"`
+ Date *string `xml:"Date,attr"`
+ Comment *string `xml:"Comment,attr"`
+ TimeBeg *string `xml:"TimeBeg,attr"`
+ TimeEnd *string `xml:"TimeEnd,attr"`
+ Address *Address `xml:"Address"`
+}
+
+//CallCourier Call courier
+type CallCourier struct {
+ Call *CourierCallReq `xml:"Call"`
+}
+
+//CourierCallReq Waiting for a courier
+type CourierCallReq struct {
+ Date *string `xml:"Date,attr"`
+ TimeBeg *string `xml:"TimeBeg,attr"`
+ TimeEnd *string `xml:"TimeEnd,attr"`
+ LunchBeg *string `xml:"LunchBeg,attr"`
+ LunchEnd *string `xml:"LunchEnd,attr"`
+ SendCityCode *int `xml:"SendCityCode,attr"`
+ SendCityPostCode *string `xml:"SendCityPostCode,attr"`
+ SendCountryCode *string `xml:"SendCountryCode,attr"`
+ SendCityName *string `xml:"SendCityName,attr"`
+ SendPhone *string `xml:"SendPhone,attr"`
+ SenderName *string `xml:"SenderName,attr"`
+ Comment *string `xml:"Comment,attr"`
+ SendAddress *Address `xml:"SendAddress"`
+}
+
+//RegisterOrderResp Order registration response structure
+type RegisterOrderResp struct {
+ Order []*OrderResp `xml:"Order,omitempty"`
+ Call []*CourierCallResp `xml:"Call,omitempty"`
+}
+
+//OrderResp Order
+type OrderResp struct {
+ Error
+ DispatchNumber *int `xml:"DispatchNumber,attr"`
+ Number *string `xml:"Number,attr"`
+}
+
+//CourierCallResp Call courier
+type CourierCallResp struct {
+ Error
+ Number *string `xml:"Number,attr"`
+}
+
+//GetError returns error supplemented with order data
+func (o *OrderResp) GetError() error {
+ errorMsgParts := []string{
+ o.Error.Error(),
+ }
+ if o.DispatchNumber != nil {
+ errorMsgParts = append(errorMsgParts, fmt.Sprintf("DispatchNumber: %d", *o.DispatchNumber))
+ }
+ if o.Number != nil {
+ errorMsgParts = append(errorMsgParts, fmt.Sprintf("Number: %s", *o.Number))
+ }
+
+ return errors.New(strings.Join(errorMsgParts, "; "))
+}
diff --git a/register-order-models_test.go b/register-order-models_test.go
new file mode 100644
index 0000000..70f51ee
--- /dev/null
+++ b/register-order-models_test.go
@@ -0,0 +1,41 @@
+package cdek
+
+import "testing"
+
+func TestOrderResp_GetError(t *testing.T) {
+ type fields struct {
+ Error Error
+ DispatchNumber *int
+ Number *string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ wantErr bool
+ }{
+ {
+ name: "err",
+ fields: fields{
+ Error: Error{
+ ErrorCode: strLink("err_code"),
+ Msg: strLink("error text"),
+ },
+ DispatchNumber: intLink(192957),
+ Number: strLink("test_number"),
+ },
+ wantErr: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ o := &OrderResp{
+ Error: tt.fields.Error,
+ DispatchNumber: tt.fields.DispatchNumber,
+ Number: tt.fields.Number,
+ }
+ if err := o.GetError(); (err != nil) != tt.wantErr {
+ t.Errorf("OrderResp.GetError() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ })
+ }
+}
diff --git a/register-order-req-builder.go b/register-order-req-builder.go
new file mode 100644
index 0000000..d52d1d9
--- /dev/null
+++ b/register-order-req-builder.go
@@ -0,0 +1,670 @@
+package cdek
+
+import (
+ "time"
+)
+
+//NewDeliveryRequest Order registration request builder
+// number: ID number of the acceptance certificate/waybill,
+// accompanying document attached upon the transfer of the cargo to CDEK, generated in the online store's system.
+// Identifier of the list of cargoes in the IS of the CDEK Client. By default, you can use 1.
+// orderCount: The total number of orders in a document, default value: 1.
+// order: Shipment (order)
+func NewDeliveryRequest(number string, orderCount int, order *OrderReq) *RegisterOrderReq {
+ return &RegisterOrderReq{
+ Number: &number,
+ OrderCount: &orderCount,
+ Order: order,
+ }
+}
+
+//SetCurrency Currency identifier for prices, RUB is a default parameter. Only for international orders
+func (registerOrderReq *RegisterOrderReq) SetCurrency(currency string) *RegisterOrderReq {
+ registerOrderReq.Currency = ¤cy
+
+ return registerOrderReq
+}
+
+//SetCallCourier Call courier
+func (registerOrderReq *RegisterOrderReq) SetCallCourier(callCourier CallCourier) *RegisterOrderReq {
+ registerOrderReq.CallCourier = &callCourier
+
+ return registerOrderReq
+}
+
+//NewOrderReq Shipment (order) builder
+// number: Client shipment number (unique for orders of a particular Client). Order identifier in the Client's IS
+// recipientName: Receiver (full name). At least 3 characters.
+// phone: Receiver's phone
+// tariffTypeCode: Code of tariff type
+func NewOrderReq(number string, recipientName string, phone string, tariffTypeCode int) *OrderReq {
+ return &OrderReq{
+ Number: &number,
+ RecipientName: &recipientName,
+ Phone: &phone,
+ TariffTypeCode: &tariffTypeCode,
+ }
+}
+
+//SetSendCityCode Sender's city code from the CDEK base
+func (orderReq *OrderReq) SetSendCityCode(sendCityCode int) *OrderReq {
+ orderReq.SendCityCode = &sendCityCode
+
+ return orderReq
+}
+
+//SetRecCityCode Receiver's city code from the CDEK base
+func (orderReq *OrderReq) SetRecCityCode(recCityCode int) *OrderReq {
+ orderReq.RecCityCode = &recCityCode
+
+ return orderReq
+}
+
+//SetSendCityPostCode Postal code of the sender's city
+func (orderReq *OrderReq) SetSendCityPostCode(sendCityPostCode int) *OrderReq {
+ orderReq.SendCityPostCode = &sendCityPostCode
+
+ return orderReq
+}
+
+//SetRecCityPostCode Postal code of the receiver's city
+func (orderReq *OrderReq) SetRecCityPostCode(recCityPostCode int) *OrderReq {
+ orderReq.RecCityPostCode = &recCityPostCode
+
+ return orderReq
+}
+
+//SetSendCountryCode Sender's country code to identify a country by postal code. Default value: RU
+func (orderReq *OrderReq) SetSendCountryCode(sendCountryCode int) *OrderReq {
+ orderReq.SendCountryCode = &sendCountryCode
+
+ return orderReq
+}
+
+//SetRecCountryCode Receiver's country code to identify a country by postal code. Default value: RU
+func (orderReq *OrderReq) SetRecCountryCode(recCountryCode int) *OrderReq {
+ orderReq.RecCountryCode = &recCountryCode
+
+ return orderReq
+}
+
+//SetSendCityName Name of sender's city
+func (orderReq *OrderReq) SetSendCityName(sendCityName string) *OrderReq {
+ orderReq.SendCityName = &sendCityName
+
+ return orderReq
+}
+
+//SetRecCityName Name of receiver's city
+func (orderReq *OrderReq) SetRecCityName(recCityName string) *OrderReq {
+ orderReq.RecCityName = &recCityName
+
+ return orderReq
+}
+
+//SetRecipientINN TIN of the receiver. Only for international orders.
+func (orderReq *OrderReq) SetRecipientINN(recipientINN string) *OrderReq {
+ orderReq.RecipientINN = &recipientINN
+
+ return orderReq
+}
+
+//SetDateInvoice Invoice date. Only for international orders.
+func (orderReq *OrderReq) SetDateInvoice(dateInvoice time.Time) *OrderReq {
+ dateInvoiceFmt := dateInvoice.Format("2006-01-02")
+ orderReq.DateInvoice = &dateInvoiceFmt
+
+ return orderReq
+}
+
+//SetShipperName Shipper. Used to print waybills. Only for international orders.
+func (orderReq *OrderReq) SetShipperName(shipperName string) *OrderReq {
+ orderReq.ShipperName = &shipperName
+
+ return orderReq
+}
+
+//SetShipperAddress Shipper’s address. Used to print waybills. Only for international orders
+func (orderReq *OrderReq) SetShipperAddress(shipperAddress string) *OrderReq {
+ orderReq.ShipperAddress = &shipperAddress
+
+ return orderReq
+}
+
+//SetPassport Details of the receiver’s passport. Used to print waybills. Only for international orders.
+func (orderReq *OrderReq) SetPassport(passport Passport) *OrderReq {
+ orderReq.Passport = &passport
+
+ return orderReq
+}
+
+//SetSender Sender. Must be defined if it is different from the online store Client.
+// If the online store is a sender, the Sender tag is not available.
+func (orderReq *OrderReq) SetSender(sender Sender) *OrderReq {
+ orderReq.Sender = &sender
+
+ return orderReq
+}
+
+//SetRecipientEmail Receiver's email for sending order status notifications and contacting in case of failed calls
+func (orderReq *OrderReq) SetRecipientEmail(recipientEmail string) *OrderReq {
+ orderReq.RecipientEmail = &recipientEmail
+
+ return orderReq
+}
+
+//SetDeliveryRecipientCost Extra delivery charge collected by the online store from the receiver
+// (in the specified currency)
+func (orderReq *OrderReq) SetDeliveryRecipientCost(deliveryRecipientCost float64) *OrderReq {
+ orderReq.DeliveryRecipientCost = &deliveryRecipientCost
+
+ return orderReq
+}
+
+//SetDeliveryRecipientVATRate VAT rate included in the extra delivery charge
+func (orderReq *OrderReq) SetDeliveryRecipientVATRate(deliveryRecipientVATRate string) *OrderReq {
+ orderReq.DeliveryRecipientVATRate = &deliveryRecipientVATRate
+
+ return orderReq
+}
+
+//SetDeliveryRecipientVATSum VAT amount included in the extra delivery charge
+func (orderReq *OrderReq) SetDeliveryRecipientVATSum(deliveryRecipientVATSum float64) *OrderReq {
+ orderReq.DeliveryRecipientVATSum = &deliveryRecipientVATSum
+
+ return orderReq
+}
+
+//SetRecipientCurrency Code of cash-on-delivery currency:
+// extra delivery charge and payment for the goods to be collected from the receiver.
+// The currency is considered to be a currency of the receiver's country
+func (orderReq *OrderReq) SetRecipientCurrency(recipientCurrency string) *OrderReq {
+ orderReq.RecipientCurrency = &recipientCurrency
+
+ return orderReq
+}
+
+//SetItemsCurrency Code of declared value currency (all items in the order).
+// Currency of settlements with the CDEK Client under contract.
+func (orderReq *OrderReq) SetItemsCurrency(itemsCurrency string) *OrderReq {
+ orderReq.ItemsCurrency = &itemsCurrency
+
+ return orderReq
+}
+
+//SetSeller Requisites of the real seller
+func (orderReq *OrderReq) SetSeller(seller Seller) *OrderReq {
+ orderReq.Seller = &seller
+
+ return orderReq
+}
+
+//SetComment Comments (special notes on the order)
+func (orderReq *OrderReq) SetComment(comment string) *OrderReq {
+ orderReq.Comment = &comment
+
+ return orderReq
+}
+
+//SetAddress Depending on a delivery mode, it is necessary to specify either Street, House, Flat attributes
+// (delivery to the receiver's address) or PvzCode (pickup)
+func (orderReq *OrderReq) SetAddress(address Address) *OrderReq {
+ orderReq.Address = &address
+
+ return orderReq
+}
+
+//AddPackage Package (all packages are sent with different Package tags)
+func (orderReq *OrderReq) AddPackage(pack OrderPackage) *OrderReq {
+ orderReq.Package = append(orderReq.Package, &pack)
+
+ return orderReq
+}
+
+//SetDeliveryRecipientCostAdv Additional charge for delivery (E-shop charges the receiver), depending on the order’s sum
+func (orderReq *OrderReq) SetDeliveryRecipientCostAdv(deliveryRecipientCostAdv DeliveryRecipientCostAdv) *OrderReq {
+ orderReq.DeliveryRecipientCostAdv = &deliveryRecipientCostAdv
+
+ return orderReq
+}
+
+//SetAddService Additional services
+func (orderReq *OrderReq) SetAddService(addService AddService) *OrderReq {
+ orderReq.AddService = &addService
+
+ return orderReq
+}
+
+//SetSchedule Schedule for delivery/pickup
+func (orderReq *OrderReq) SetSchedule(schedule Schedule) *OrderReq {
+ orderReq.Schedule = &schedule
+
+ return orderReq
+}
+
+//NewPassport Passport builder
+func NewPassport() *Passport {
+ return new(Passport)
+}
+
+//SetSeries Series of the receiver’s passport.
+func (passport *Passport) SetSeries(series string) *Passport {
+ passport.Series = &series
+
+ return passport
+}
+
+//SetNumber Number of the receiver’s passport.
+func (passport *Passport) SetNumber(number string) *Passport {
+ passport.Number = &number
+
+ return passport
+}
+
+//SetIssueDate Date of issue of the receiver’s passport.
+func (passport *Passport) SetIssueDate(issueDate time.Time) *Passport {
+ issueDateFmt := issueDate.Format("2006-01-02")
+
+ passport.IssueDate = &issueDateFmt
+
+ return passport
+}
+
+//SetIssuedBy Issuing authority of the receiver’s passport.
+func (passport *Passport) SetIssuedBy(issuedBy string) *Passport {
+ passport.IssuedBy = &issuedBy
+
+ return passport
+}
+
+//SetDateBirth The receiver’s birthdate
+func (passport *Passport) SetDateBirth(dateBirth time.Time) *Passport {
+ dateBirthFmt := dateBirth.Format("2006-01-02")
+ passport.DateBirth = &dateBirthFmt
+
+ return passport
+}
+
+//NewSender Sender builder
+func NewSender() *Sender {
+ return new(Sender)
+}
+
+//SetCompany Name of sender's company
+func (sender *Sender) SetCompany(company string) *Sender {
+ sender.Company = &company
+
+ return sender
+}
+
+//SetName Sender's contact person
+func (sender *Sender) SetName(name string) *Sender {
+ sender.Name = &name
+
+ return sender
+}
+
+//SetAddress Address of pickup builder
+func (sender *Sender) SetAddress(address Address) *Sender {
+ sender.Address = &address
+
+ return sender
+}
+
+//AddPhone Sender's phone
+func (sender *Sender) AddPhone(phone string) *Sender {
+ sender.Phone = append(sender.Phone, &phone)
+
+ return sender
+}
+
+//NewAddress Address of pickup builder
+func NewAddress(street string, house string) *Address {
+ return &Address{
+ Street: &street,
+ House: &house,
+ }
+}
+
+//SetFlat Flat/office
+func (address *Address) SetFlat(flat string) *Address {
+ address.Flat = &flat
+
+ return address
+}
+
+//SetPhone Sender's phone
+func (address *Address) SetPhone(phone string) *Address {
+ address.Phone = &phone
+
+ return address
+}
+
+//SetPvzCode Pickup code. The attribute is required only for orders with the delivery mode “to warehouse”,
+// provided that no additional service “Delivery in the receiver's city” is ordered.
+// If the specified pickup point is closed at the time of order creation, the order will be accepted for the nearest
+// functioning pickup point. The receiver will be notified about change of the pickup point via SMS.
+// If all pickup points in the city that can provide the selected service are closed,
+// order registration will be impossible. The relevant error message will be sent.
+func (address *Address) SetPvzCode(pvzCode string) *Address {
+ address.PvzCode = &pvzCode
+
+ return address
+}
+
+//NewSeller Requisites of the real seller builder
+func NewSeller() *Seller {
+ return new(Seller)
+}
+
+//SetAddress Real seller’s address. Used to print invoices to display the address of the true seller or trade name.
+// Only for international orders.
+func (seller *Seller) SetAddress(address string) *Seller {
+ seller.Address = &address
+
+ return seller
+}
+
+//SetName Real seller
+func (seller *Seller) SetName(name string) *Seller {
+ seller.Name = &name
+
+ return seller
+}
+
+//SetINN ITN (Individual Taxpayer Number) of the real seller
+func (seller *Seller) SetINN(inn string) *Seller {
+ seller.INN = &inn
+
+ return seller
+}
+
+//SetPhone Telephone of the real seller
+func (seller *Seller) SetPhone(phone string) *Seller {
+ seller.Phone = &phone
+
+ return seller
+}
+
+//SetOwnershipForm Code of type ownership
+func (seller *Seller) SetOwnershipForm(ownershipForm int) *Seller {
+ seller.OwnershipForm = &ownershipForm
+
+ return seller
+}
+
+//NewOrderPackage OrderPackage builder
+// number: Package number (ordinal package number or order number can be used), unique for this order.
+// Order identifier in the Client's IS.
+// barCode: Package barcode, package identifier (if any);
+// otherwise, transmit a value of the package number: Packege.Number).
+// The parameter is used to handle the cargo at CDEK warehouses), unique for this order.
+// Package identifier in the Client's IS.
+// weight: Total weight (in grams)
+func NewOrderPackage(number string, barCode string, weight int) *OrderPackage {
+ return &OrderPackage{
+ Number: &number,
+ BarCode: &barCode,
+ Weight: &weight,
+ }
+}
+
+//SetSize Package dimensions
+// length: Length (in centimeters)
+// width: Width (in centimeters)
+// height: Height (in centimeters)
+func (orderPackage *OrderPackage) SetSize(length int, width int, height int) *OrderPackage {
+ orderPackage.SizeA = &length
+ orderPackage.SizeB = &width
+ orderPackage.SizeC = &height
+
+ return orderPackage
+}
+
+//AddItem Add OrderPackageItem to OrderPackageItems list
+func (orderPackage *OrderPackage) AddItem(item OrderPackageItem) *OrderPackage {
+ orderPackage.Item = append(orderPackage.Item, &item)
+
+ return orderPackage
+}
+
+//NewOrderPackageItem OrderPackageItem builder
+// amount: Quantity of goods of the same type (pcs). The maximum number is 999.
+// wareKey: Identifier/item number of the goods (Unique for this Package).
+// cost: Declared value of the goods (per item in the specified currency, value >=0).
+// This value is used to calculate the amount of insurance.
+// payment: Cash on delivery (per item in the specified currency, value >=0) — cash on delivery;
+// in case of prepayment, value = 0.
+// weight: Weight (per item, in grams)
+// comment: Name of the goods (may contain description of the goods: size, color)
+func NewOrderPackageItem(
+ amount int,
+ wareKey string,
+ cost float64,
+ payment float64,
+ weight int,
+ comment string,
+) *OrderPackageItem {
+ return &OrderPackageItem{
+ Amount: &amount,
+ WareKey: &wareKey,
+ Cost: &cost,
+ Payment: &payment,
+ Weight: &weight,
+ Comment: &comment,
+ }
+}
+
+//SetPaymentVATRate VAT rate included in the value of the goods
+func (item *OrderPackageItem) SetPaymentVATRate(paymentVATRate string) *OrderPackageItem {
+ item.PaymentVATRate = &paymentVATRate
+
+ return item
+}
+
+//SetPaymentVATSum VAT amount included in the value (payment) of the goods.
+func (item *OrderPackageItem) SetPaymentVATSum(paymentVATSum float64) *OrderPackageItem {
+ item.PaymentVATSum = &paymentVATSum
+
+ return item
+}
+
+//SetWeightBrutto Gross weight (for one unit of goods, in grams). Only for international orders.
+func (item *OrderPackageItem) SetWeightBrutto(weightBrutto int) *OrderPackageItem {
+ item.WeightBrutto = &weightBrutto
+
+ return item
+}
+
+//SetCommentEx Name of the goods, in English (also can contain description of the goods, such as size and color).
+// Only for international orders.
+func (item *OrderPackageItem) SetCommentEx(commentEx string) *OrderPackageItem {
+ item.CommentEx = &commentEx
+
+ return item
+}
+
+//SetLink Link to the e-shop’s website with the goods’ description. Only for international orders.
+func (item *OrderPackageItem) SetLink(link string) *OrderPackageItem {
+ item.Link = &link
+
+ return item
+}
+
+//NewDeliveryRecipientCostAdv DeliveryRecipientCostAdv builder
+// threshold: Goods price threshold (valid by condition less than or equal to), in even monetary units
+// sum: Additional charge for delivery with total amount that falls within the interval
+func NewDeliveryRecipientCostAdv(threshold int, sum float64) *DeliveryRecipientCostAdv {
+ return &DeliveryRecipientCostAdv{
+ Threshold: &threshold,
+ Sum: &sum,
+ }
+}
+
+//SetVATRate VAT rate included in the additional charge for delivery.
+// If the value is unknown, then default value “No VAT” is applied
+func (d *DeliveryRecipientCostAdv) SetVATRate(vatRate string) *DeliveryRecipientCostAdv {
+ d.VATRate = &vatRate
+
+ return d
+}
+
+//SetVATSum VAT sum included in the additional charge for delivery
+func (d *DeliveryRecipientCostAdv) SetVATSum(vatSum float64) *DeliveryRecipientCostAdv {
+ d.VATSum = &vatSum
+
+ return d
+}
+
+//NewAddService Additional services builder
+// serviceCode: Type of additional service
+func NewAddService(serviceCode int) *AddService {
+ return &AddService{
+ ServiceCode: &serviceCode,
+ }
+}
+
+//SetCount Number of packages. It is used and is mandatory only for the additional service "Package 1".
+func (addService *AddService) SetCount(count int) *AddService {
+ addService.Count = &count
+
+ return addService
+}
+
+//NewSchedule Schedule for delivery/pickup builder
+func NewSchedule() *Schedule {
+ return new(Schedule)
+}
+
+//AddAttempt add Time of delivery
+func (schedule *Schedule) AddAttempt(attempt ScheduleAttempt) *Schedule {
+ schedule.Attempt = append(schedule.Attempt, &attempt)
+
+ return schedule
+}
+
+//NewScheduleAttempt Time of delivery builder
+// id: ID number of a schedule from the online store's database. You may use 1 as a default value
+// date: Date of delivery as agreed by the receiver
+func NewScheduleAttempt(id string, date time.Time) *ScheduleAttempt {
+ dateFmt := date.Format("2006-01-02")
+
+ return &ScheduleAttempt{
+ ID: &id,
+ Date: &dateFmt,
+ }
+}
+
+//SetComment Comment
+func (scheduleAttempt *ScheduleAttempt) SetComment(comment string) *ScheduleAttempt {
+ scheduleAttempt.Comment = &comment
+
+ return scheduleAttempt
+}
+
+//SetTimeBeg Start of a delivery time range (receiver's time)
+func (scheduleAttempt *ScheduleAttempt) SetTimeBeg(timeBeg string) *ScheduleAttempt {
+ scheduleAttempt.TimeBeg = &timeBeg
+
+ return scheduleAttempt
+}
+
+//SetTimeEnd End of a delivery time range (receiver's time)
+func (scheduleAttempt *ScheduleAttempt) SetTimeEnd(timeEnd string) *ScheduleAttempt {
+ scheduleAttempt.TimeEnd = &timeEnd
+
+ return scheduleAttempt
+}
+
+//SetAddress New delivery address (if change is required).
+// Depending on a delivery mode, Street or House attributes should be specified.
+// Flat – delivery to the receiver's address, or PvzCode – pickup
+func (scheduleAttempt *ScheduleAttempt) SetAddress(address Address) *ScheduleAttempt {
+ scheduleAttempt.Address = &address
+
+ return scheduleAttempt
+}
+
+//NewCallCourier Call courier builder
+// call: Waiting for a courier
+func NewCallCourier(call CourierCallReq) *CallCourier {
+ return &CallCourier{
+ Call: &call,
+ }
+}
+
+//NewCourierCall NewCourierCall builder
+// date: Date of courier waiting
+// timeBeg: Start time of courier waiting
+// timeEnd: End time of courier waiting
+// sendPhone: Sender's contact phone
+// senderName: Sender (full name)
+// sendAddress: Sender's address
+func NewCourierCall(
+ date time.Time,
+ timeBeg string,
+ timeEnd string,
+ sendPhone string,
+ senderName string,
+ sendAddress Address,
+) *CourierCallReq {
+ dateFmt := date.Format("2006-01-02")
+
+ return &CourierCallReq{
+ Date: &dateFmt,
+ TimeBeg: &timeBeg,
+ TimeEnd: &timeEnd,
+ SendPhone: &sendPhone,
+ SenderName: &senderName,
+ SendAddress: &sendAddress,
+ }
+}
+
+//SetLunchBeg Start time of a lunch break, if it is within a time range [TimeBeg; TimeEnd]
+func (call *CourierCallReq) SetLunchBeg(lunchBeg string) *CourierCallReq {
+ call.LunchBeg = &lunchBeg
+
+ return call
+}
+
+//SetLunchEnd End time of a lunch break, if it is within a time range [TimeBeg; TimeEnd]
+func (call *CourierCallReq) SetLunchEnd(lunchEnd string) *CourierCallReq {
+ call.LunchEnd = &lunchEnd
+
+ return call
+}
+
+//SetSendCityCode Sender's city code from the CDEK base
+func (call *CourierCallReq) SetSendCityCode(sendCityCode int) *CourierCallReq {
+ call.SendCityCode = &sendCityCode
+
+ return call
+}
+
+//SetSendCityPostCode Postal code of the sender's city
+func (call *CourierCallReq) SetSendCityPostCode(sendCityPostCode string) *CourierCallReq {
+ call.SendCityPostCode = &sendCityPostCode
+
+ return call
+}
+
+//SetSendCountryCode Sender's country code to identify a country by postal code
+func (call *CourierCallReq) SetSendCountryCode(sendCountryCode string) *CourierCallReq {
+ call.SendCountryCode = &sendCountryCode
+
+ return call
+}
+
+//SetSendCityName Name of sender's city
+func (call *CourierCallReq) SetSendCityName(sendCityName string) *CourierCallReq {
+ call.SendCityName = &sendCityName
+
+ return call
+}
+
+//SetComment Comment for courier
+func (call *CourierCallReq) SetComment(comment string) *CourierCallReq {
+ call.Comment = &comment
+
+ return call
+}
diff --git a/register-order-req-builder_test.go b/register-order-req-builder_test.go
new file mode 100644
index 0000000..0135c18
--- /dev/null
+++ b/register-order-req-builder_test.go
@@ -0,0 +1,7156 @@
+package cdek
+
+import (
+ "reflect"
+ "testing"
+ "time"
+)
+
+func TestNewDeliveryRequest(t *testing.T) {
+ type args struct {
+ number string
+ orderCount int
+ order *OrderReq
+ }
+ tests := []struct {
+ name string
+ args args
+ want *RegisterOrderReq
+ }{
+ {
+ name: "constructor",
+ args: args{
+ number: "test_number",
+ orderCount: 1,
+ order: &OrderReq{},
+ },
+ want: &RegisterOrderReq{
+ Number: strLink("test_number"),
+ OrderCount: intLink(1),
+ Order: &OrderReq{},
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewDeliveryRequest(tt.args.number, tt.args.orderCount, tt.args.order); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewDeliveryRequest() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestRegisterOrderReq_SetCurrency(t *testing.T) {
+ type fields struct {
+ Number *string
+ OrderCount *int
+ Currency *string
+ Order *OrderReq
+ CallCourier *CallCourier
+ }
+ type args struct {
+ currency string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *RegisterOrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ OrderCount: intLink(1),
+ Order: &OrderReq{},
+ Currency: nil,
+ },
+ args: args{
+ currency: "RUB",
+ },
+ want: &RegisterOrderReq{
+ Number: strLink("test_number"),
+ OrderCount: intLink(1),
+ Order: &OrderReq{},
+ Currency: strLink("RUB"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ OrderCount: intLink(1),
+ Order: &OrderReq{},
+ Currency: strLink("EUR"),
+ },
+ args: args{
+ currency: "RUB",
+ },
+ want: &RegisterOrderReq{
+ Number: strLink("test_number"),
+ OrderCount: intLink(1),
+ Order: &OrderReq{},
+ Currency: strLink("RUB"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ registerOrderReq := &RegisterOrderReq{
+ Number: tt.fields.Number,
+ OrderCount: tt.fields.OrderCount,
+ Currency: tt.fields.Currency,
+ Order: tt.fields.Order,
+ CallCourier: tt.fields.CallCourier,
+ }
+ if got := registerOrderReq.SetCurrency(tt.args.currency); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("RegisterOrderReq.SetCurrency() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestRegisterOrderReq_SetCallCourier(t *testing.T) {
+ type fields struct {
+ Number *string
+ OrderCount *int
+ Currency *string
+ Order *OrderReq
+ CallCourier *CallCourier
+ }
+ type args struct {
+ callCourier CallCourier
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *RegisterOrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ OrderCount: intLink(1),
+ Order: &OrderReq{},
+ CallCourier: nil,
+ },
+ args: args{
+ callCourier: CallCourier{
+ Call: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ },
+ },
+ want: &RegisterOrderReq{
+ Number: strLink("test_number"),
+ OrderCount: intLink(1),
+ Order: &OrderReq{},
+ CallCourier: &CallCourier{
+ Call: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ },
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ OrderCount: intLink(1),
+ Order: &OrderReq{},
+ CallCourier: &CallCourier{
+ Call: &CourierCallReq{
+ Date: strLink("2019-07-16"),
+ TimeBeg: strLink("11:00"),
+ TimeEnd: strLink("15:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ },
+ },
+ args: args{
+ callCourier: CallCourier{
+ Call: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ },
+ },
+ want: &RegisterOrderReq{
+ Number: strLink("test_number"),
+ OrderCount: intLink(1),
+ Order: &OrderReq{},
+ CallCourier: &CallCourier{
+ Call: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ registerOrderReq := &RegisterOrderReq{
+ Number: tt.fields.Number,
+ OrderCount: tt.fields.OrderCount,
+ Currency: tt.fields.Currency,
+ Order: tt.fields.Order,
+ CallCourier: tt.fields.CallCourier,
+ }
+ if got := registerOrderReq.SetCallCourier(tt.args.callCourier); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("RegisterOrderReq.SetCallCourier() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNewOrderReq(t *testing.T) {
+ type args struct {
+ number string
+ recipientName string
+ phone string
+ tariffTypeCode int
+ }
+ tests := []struct {
+ name string
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "constructor",
+ args: args{
+ number: "test_number",
+ recipientName: "recipient name",
+ phone: "+79138739944",
+ tariffTypeCode: 10,
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := NewOrderReq(tt.args.number, tt.args.recipientName, tt.args.phone, tt.args.tariffTypeCode)
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewOrderReq() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetSendCityCode(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ sendCityCode int
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ SendCityCode: nil,
+ },
+ args: args{
+ sendCityCode: 1234321,
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ SendCityCode: intLink(1234321),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ SendCityCode: intLink(4321234),
+ },
+ args: args{
+ sendCityCode: 1234321,
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ SendCityCode: intLink(1234321),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetSendCityCode(tt.args.sendCityCode); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetSendCityCode() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetRecCityCode(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ recCityCode int
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecCityCode: nil,
+ },
+ args: args{
+ recCityCode: 1234321,
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecCityCode: intLink(1234321),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecCityCode: intLink(4321234),
+ },
+ args: args{
+ recCityCode: 1234321,
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecCityCode: intLink(1234321),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetRecCityCode(tt.args.recCityCode); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetRecCityCode() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetSendCityPostCode(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ sendCityPostCode int
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ SendCityPostCode: nil,
+ },
+ args: args{
+ sendCityPostCode: 1234321,
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ SendCityPostCode: intLink(1234321),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ SendCityPostCode: intLink(4321234),
+ },
+ args: args{
+ sendCityPostCode: 1234321,
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ SendCityPostCode: intLink(1234321),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetSendCityPostCode(tt.args.sendCityPostCode); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetSendCityPostCode() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetRecCityPostCode(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ recCityPostCode int
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecCityPostCode: nil,
+ },
+ args: args{
+ recCityPostCode: 1234321,
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecCityPostCode: intLink(1234321),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecCityPostCode: intLink(4321234),
+ },
+ args: args{
+ recCityPostCode: 1234321,
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecCityPostCode: intLink(1234321),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetRecCityPostCode(tt.args.recCityPostCode); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetRecCityPostCode() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetSendCountryCode(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ sendCountryCode int
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ SendCountryCode: nil,
+ },
+ args: args{
+ sendCountryCode: 1234321,
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ SendCountryCode: intLink(1234321),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ SendCountryCode: intLink(4321234),
+ },
+ args: args{
+ sendCountryCode: 1234321,
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ SendCountryCode: intLink(1234321),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetSendCountryCode(tt.args.sendCountryCode); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetSendCountryCode() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetRecCountryCode(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ recCountryCode int
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecCountryCode: nil,
+ },
+ args: args{
+ recCountryCode: 1234321,
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecCountryCode: intLink(1234321),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecCountryCode: intLink(4321234),
+ },
+ args: args{
+ recCountryCode: 1234321,
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecCountryCode: intLink(1234321),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetRecCountryCode(tt.args.recCountryCode); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetRecCountryCode() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetSendCityName(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ sendCityName string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ SendCityName: nil,
+ },
+ args: args{
+ sendCityName: "Багинск",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ SendCityName: strLink("Багинск"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ SendCityName: strLink("Суздаль"),
+ },
+ args: args{
+ sendCityName: "Багинск",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ SendCityName: strLink("Багинск"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetSendCityName(tt.args.sendCityName); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetSendCityName() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetRecCityName(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ recCityName string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecCityName: nil,
+ },
+ args: args{
+ recCityName: "Багинск",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecCityName: strLink("Багинск"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecCityName: strLink("Суздаль"),
+ },
+ args: args{
+ recCityName: "Багинск",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecCityName: strLink("Багинск"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetRecCityName(tt.args.recCityName); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetRecCityName() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetRecipientINN(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ recipientINN string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecipientINN: nil,
+ },
+ args: args{
+ recipientINN: "12345678987",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecipientINN: strLink("12345678987"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecipientINN: strLink("98765432123"),
+ },
+ args: args{
+ recipientINN: "12345678987",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecipientINN: strLink("12345678987"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetRecipientINN(tt.args.recipientINN); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetRecipientINN() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetDateInvoice(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ dateInvoice time.Time
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DateInvoice: nil,
+ },
+ args: args{
+ dateInvoice: time.Date(2019, 7, 20, 0, 0, 0, 0, time.UTC),
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DateInvoice: strLink("2019-07-20"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DateInvoice: strLink("2019-07-17"),
+ },
+ args: args{
+ dateInvoice: time.Date(2019, 7, 20, 0, 0, 0, 0, time.UTC),
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DateInvoice: strLink("2019-07-20"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetDateInvoice(tt.args.dateInvoice); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetDateInvoice() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetShipperName(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ shipperName string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ ShipperName: nil,
+ },
+ args: args{
+ shipperName: "shipper name",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ ShipperName: strLink("shipper name"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ ShipperName: strLink("previous shipper name"),
+ },
+ args: args{
+ shipperName: "shipper name",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ ShipperName: strLink("shipper name"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetShipperName(tt.args.shipperName); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetShipperName() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetShipperAddress(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ shipperAddress string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ ShipperAddress: nil,
+ },
+ args: args{
+ shipperAddress: "shipper address",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ ShipperAddress: strLink("shipper address"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ ShipperAddress: strLink("previous shipper address"),
+ },
+ args: args{
+ shipperAddress: "shipper address",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ ShipperAddress: strLink("shipper address"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetShipperAddress(tt.args.shipperAddress); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetShipperAddress() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetPassport(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ passport Passport
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Passport: nil,
+ },
+ args: args{
+ passport: Passport{
+ Series: strLink("some series"),
+ },
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Passport: &Passport{
+ Series: strLink("some series"),
+ },
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Passport: &Passport{
+ Series: strLink("previous series"),
+ },
+ },
+ args: args{
+ passport: Passport{
+ Series: strLink("some series"),
+ },
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Passport: &Passport{
+ Series: strLink("some series"),
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetPassport(tt.args.passport); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetPassport() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetSender(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ sender Sender
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Sender: nil,
+ },
+ args: args{
+ sender: Sender{
+ Name: strLink("sender name"),
+ },
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Sender: &Sender{
+ Name: strLink("sender name"),
+ },
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Sender: &Sender{
+ Name: strLink("previous sender name"),
+ },
+ },
+ args: args{
+ sender: Sender{
+ Name: strLink("sender name"),
+ },
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Sender: &Sender{
+ Name: strLink("sender name"),
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetSender(tt.args.sender); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetSender() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetRecipientEmail(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ recipientEmail string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecipientEmail: nil,
+ },
+ args: args{
+ recipientEmail: "recipient@actual.email",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecipientEmail: strLink("recipient@actual.email"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecipientEmail: strLink("recipient@previous.email"),
+ },
+ args: args{
+ recipientEmail: "recipient@actual.email",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecipientEmail: strLink("recipient@actual.email"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetRecipientEmail(tt.args.recipientEmail); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetRecipientEmail() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetDeliveryRecipientCost(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ deliveryRecipientCost float64
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DeliveryRecipientCost: nil,
+ },
+ args: args{
+ deliveryRecipientCost: 399.99,
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DeliveryRecipientCost: float64Link(399.99),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DeliveryRecipientCost: float64Link(400.),
+ },
+ args: args{
+ deliveryRecipientCost: 399.99,
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DeliveryRecipientCost: float64Link(399.99),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetDeliveryRecipientCost(tt.args.deliveryRecipientCost); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetDeliveryRecipientCost() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetDeliveryRecipientVATRate(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ deliveryRecipientVATRate string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DeliveryRecipientVATRate: nil,
+ },
+ args: args{
+ deliveryRecipientVATRate: "VATX",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DeliveryRecipientVATRate: strLink("VATX"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DeliveryRecipientVATRate: strLink("VATY"),
+ },
+ args: args{
+ deliveryRecipientVATRate: "VATX",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DeliveryRecipientVATRate: strLink("VATX"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetDeliveryRecipientVATRate(tt.args.deliveryRecipientVATRate); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetDeliveryRecipientVATRate() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetDeliveryRecipientVATSum(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ deliveryRecipientVATSum float64
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DeliveryRecipientVATSum: nil,
+ },
+ args: args{
+ deliveryRecipientVATSum: 399.99,
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DeliveryRecipientVATSum: float64Link(399.99),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DeliveryRecipientVATSum: float64Link(400.),
+ },
+ args: args{
+ deliveryRecipientVATSum: 399.99,
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DeliveryRecipientVATSum: float64Link(399.99),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetDeliveryRecipientVATSum(tt.args.deliveryRecipientVATSum); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetDeliveryRecipientVATSum() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetRecipientCurrency(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ recipientCurrency string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecipientCurrency: nil,
+ },
+ args: args{
+ recipientCurrency: "RUB",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecipientCurrency: strLink("RUB"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecipientCurrency: strLink("EUR"),
+ },
+ args: args{
+ recipientCurrency: "RUB",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ RecipientCurrency: strLink("RUB"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetRecipientCurrency(tt.args.recipientCurrency); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetRecipientCurrency() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetItemsCurrency(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ itemsCurrency string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ ItemsCurrency: nil,
+ },
+ args: args{
+ itemsCurrency: "RUB",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ ItemsCurrency: strLink("RUB"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ ItemsCurrency: strLink("EUR"),
+ },
+ args: args{
+ itemsCurrency: "RUB",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ ItemsCurrency: strLink("RUB"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetItemsCurrency(tt.args.itemsCurrency); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetItemsCurrency() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetSeller(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ seller Seller
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Seller: nil,
+ },
+ args: args{
+ seller: Seller{
+ Name: strLink("seller name"),
+ },
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Seller: &Seller{
+ Name: strLink("seller name"),
+ },
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Seller: &Seller{
+ Name: strLink("previous seller name"),
+ },
+ },
+ args: args{
+ seller: Seller{
+ Name: strLink("seller name"),
+ },
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Seller: &Seller{
+ Name: strLink("seller name"),
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetSeller(tt.args.seller); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetSeller() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetComment(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ comment string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Comment: nil,
+ },
+ args: args{
+ comment: "comment",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Comment: strLink("comment"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Comment: strLink("previous comment"),
+ },
+ args: args{
+ comment: "comment",
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Comment: strLink("comment"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetComment(tt.args.comment); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetComment() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetAddress(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ address Address
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Address: nil,
+ },
+ args: args{
+ address: Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Address: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Address: &Address{
+ Street: strLink("previous street"),
+ House: strLink("11/4"),
+ },
+ },
+ args: args{
+ address: Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Address: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetAddress(tt.args.address); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetAddress() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_AddPackage(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ pack OrderPackage
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "add first",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Package: nil,
+ },
+ args: args{
+ pack: OrderPackage{
+ Number: strLink("package number"),
+ BarCode: strLink("package barcode"),
+ Weight: intLink(1500),
+ },
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Package: []*OrderPackage{
+ {
+ Number: strLink("package number"),
+ BarCode: strLink("package barcode"),
+ Weight: intLink(1500),
+ },
+ },
+ },
+ },
+ {
+ name: "add second",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Package: []*OrderPackage{
+ {
+ Number: strLink("package number"),
+ BarCode: strLink("package barcode"),
+ Weight: intLink(1500),
+ },
+ },
+ },
+ args: args{
+ pack: OrderPackage{
+ Number: strLink("package number 2"),
+ BarCode: strLink("package barcode 2"),
+ Weight: intLink(3000),
+ },
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Package: []*OrderPackage{
+ {
+ Number: strLink("package number"),
+ BarCode: strLink("package barcode"),
+ Weight: intLink(1500),
+ },
+ {
+ Number: strLink("package number 2"),
+ BarCode: strLink("package barcode 2"),
+ Weight: intLink(3000),
+ },
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.AddPackage(tt.args.pack); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.AddPackage() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetDeliveryRecipientCostAdv(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ deliveryRecipientCostAdv DeliveryRecipientCostAdv
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DeliveryRecipientCostAdv: nil,
+ },
+ args: args{
+ deliveryRecipientCostAdv: DeliveryRecipientCostAdv{
+ Threshold: intLink(999),
+ Sum: float64Link(333.99),
+ },
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DeliveryRecipientCostAdv: &DeliveryRecipientCostAdv{
+ Threshold: intLink(999),
+ Sum: float64Link(333.99),
+ },
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DeliveryRecipientCostAdv: &DeliveryRecipientCostAdv{
+ Threshold: intLink(777),
+ Sum: float64Link(666.55),
+ },
+ },
+ args: args{
+ deliveryRecipientCostAdv: DeliveryRecipientCostAdv{
+ Threshold: intLink(999),
+ Sum: float64Link(333.99),
+ },
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ DeliveryRecipientCostAdv: &DeliveryRecipientCostAdv{
+ Threshold: intLink(999),
+ Sum: float64Link(333.99),
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetDeliveryRecipientCostAdv(tt.args.deliveryRecipientCostAdv); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetDeliveryRecipientCostAdv() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetAddService(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ addService AddService
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ AddService: nil,
+ },
+ args: args{
+ addService: AddService{
+ ServiceCode: intLink(783498),
+ },
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ AddService: &AddService{
+ ServiceCode: intLink(783498),
+ },
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ AddService: &AddService{
+ ServiceCode: intLink(857432),
+ },
+ },
+ args: args{
+ addService: AddService{
+ ServiceCode: intLink(783498),
+ },
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ AddService: &AddService{
+ ServiceCode: intLink(783498),
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetAddService(tt.args.addService); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetAddService() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderReq_SetSchedule(t *testing.T) {
+ type fields struct {
+ Number *string
+ SendCityCode *int
+ RecCityCode *int
+ SendCityPostCode *int
+ RecCityPostCode *int
+ SendCountryCode *int
+ RecCountryCode *int
+ SendCityName *string
+ RecCityName *string
+ RecipientINN *string
+ DateInvoice *string
+ ShipperName *string
+ ShipperAddress *string
+ Passport *Passport
+ Sender *Sender
+ RecipientName *string
+ RecipientEmail *string
+ Phone *string
+ TariffTypeCode *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientCurrency *string
+ ItemsCurrency *string
+ Seller *Seller
+ Comment *string
+ Address *Address
+ Package []*OrderPackage
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ AddService *AddService
+ Schedule *Schedule
+ }
+ type args struct {
+ schedule Schedule
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Schedule: nil,
+ },
+ args: args{
+ schedule: Schedule{
+ Attempt: []*ScheduleAttempt{
+ {
+ ID: strLink("attempt id"),
+ Date: strLink("2019-07-17"),
+ },
+ },
+ },
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Schedule: &Schedule{
+ Attempt: []*ScheduleAttempt{
+ {
+ ID: strLink("attempt id"),
+ Date: strLink("2019-07-17"),
+ },
+ },
+ },
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Schedule: &Schedule{
+ Attempt: []*ScheduleAttempt{
+ {
+ ID: strLink("previous attempt id"),
+ Date: strLink("2019-07-16"),
+ },
+ },
+ },
+ },
+ args: args{
+ schedule: Schedule{
+ Attempt: []*ScheduleAttempt{
+ {
+ ID: strLink("attempt id"),
+ Date: strLink("2019-07-17"),
+ },
+ },
+ },
+ },
+ want: &OrderReq{
+ Number: strLink("test_number"),
+ RecipientName: strLink("recipient name"),
+ Phone: strLink("+79138739944"),
+ TariffTypeCode: intLink(10),
+ Schedule: &Schedule{
+ Attempt: []*ScheduleAttempt{
+ {
+ ID: strLink("attempt id"),
+ Date: strLink("2019-07-17"),
+ },
+ },
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderReq := &OrderReq{
+ Number: tt.fields.Number,
+ SendCityCode: tt.fields.SendCityCode,
+ RecCityCode: tt.fields.RecCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ RecCityPostCode: tt.fields.RecCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ RecCountryCode: tt.fields.RecCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ RecCityName: tt.fields.RecCityName,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ ShipperName: tt.fields.ShipperName,
+ ShipperAddress: tt.fields.ShipperAddress,
+ Passport: tt.fields.Passport,
+ Sender: tt.fields.Sender,
+ RecipientName: tt.fields.RecipientName,
+ RecipientEmail: tt.fields.RecipientEmail,
+ Phone: tt.fields.Phone,
+ TariffTypeCode: tt.fields.TariffTypeCode,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientCurrency: tt.fields.RecipientCurrency,
+ ItemsCurrency: tt.fields.ItemsCurrency,
+ Seller: tt.fields.Seller,
+ Comment: tt.fields.Comment,
+ Address: tt.fields.Address,
+ Package: tt.fields.Package,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ AddService: tt.fields.AddService,
+ Schedule: tt.fields.Schedule,
+ }
+ if got := orderReq.SetSchedule(tt.args.schedule); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderReq.SetSchedule() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNewPassport(t *testing.T) {
+ tests := []struct {
+ name string
+ want *Passport
+ }{
+ {
+ name: "constructor",
+ want: &Passport{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewPassport(); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewPassport() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestPassport_SetSeries(t *testing.T) {
+ type fields struct {
+ Series *string
+ Number *string
+ IssueDate *string
+ IssuedBy *string
+ DateBirth *string
+ }
+ type args struct {
+ series string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Passport
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Series: nil,
+ },
+ args: args{
+ series: "passport series",
+ },
+ want: &Passport{
+ Series: strLink("passport series"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Series: strLink("previous passport series"),
+ },
+ args: args{
+ series: "passport series",
+ },
+ want: &Passport{
+ Series: strLink("passport series"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ passport := &Passport{
+ Series: tt.fields.Series,
+ Number: tt.fields.Number,
+ IssueDate: tt.fields.IssueDate,
+ IssuedBy: tt.fields.IssuedBy,
+ DateBirth: tt.fields.DateBirth,
+ }
+ if got := passport.SetSeries(tt.args.series); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Passport.SetSeries() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestPassport_SetNumber(t *testing.T) {
+ type fields struct {
+ Series *string
+ Number *string
+ IssueDate *string
+ IssuedBy *string
+ DateBirth *string
+ }
+ type args struct {
+ number string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Passport
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: nil,
+ },
+ args: args{
+ number: "passport number",
+ },
+ want: &Passport{
+ Number: strLink("passport number"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("previous passport number"),
+ },
+ args: args{
+ number: "passport number",
+ },
+ want: &Passport{
+ Number: strLink("passport number"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ passport := &Passport{
+ Series: tt.fields.Series,
+ Number: tt.fields.Number,
+ IssueDate: tt.fields.IssueDate,
+ IssuedBy: tt.fields.IssuedBy,
+ DateBirth: tt.fields.DateBirth,
+ }
+ if got := passport.SetNumber(tt.args.number); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Passport.SetNumber() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestPassport_SetIssueDate(t *testing.T) {
+ type fields struct {
+ Series *string
+ Number *string
+ IssueDate *string
+ IssuedBy *string
+ DateBirth *string
+ }
+ type args struct {
+ issueDate time.Time
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Passport
+ }{
+ {
+ name: "set",
+ fields: fields{
+ IssueDate: nil,
+ },
+ args: args{
+ issueDate: time.Date(2009, 7, 17, 0, 0, 0, 0, time.UTC),
+ },
+ want: &Passport{
+ IssueDate: strLink("2009-07-17"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ IssueDate: strLink("2019-07-17"),
+ },
+ args: args{
+ issueDate: time.Date(2009, 7, 17, 0, 0, 0, 0, time.UTC),
+ },
+ want: &Passport{
+ IssueDate: strLink("2009-07-17"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ passport := &Passport{
+ Series: tt.fields.Series,
+ Number: tt.fields.Number,
+ IssueDate: tt.fields.IssueDate,
+ IssuedBy: tt.fields.IssuedBy,
+ DateBirth: tt.fields.DateBirth,
+ }
+ if got := passport.SetIssueDate(tt.args.issueDate); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Passport.SetIssueDate() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestPassport_SetIssuedBy(t *testing.T) {
+ type fields struct {
+ Series *string
+ Number *string
+ IssueDate *string
+ IssuedBy *string
+ DateBirth *string
+ }
+ type args struct {
+ issuedBy string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Passport
+ }{
+ {
+ name: "set",
+ fields: fields{
+ IssuedBy: nil,
+ },
+ args: args{
+ issuedBy: "me",
+ },
+ want: &Passport{
+ IssuedBy: strLink("me"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ IssuedBy: strLink("you"),
+ },
+ args: args{
+ issuedBy: "me",
+ },
+ want: &Passport{
+ IssuedBy: strLink("me"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ passport := &Passport{
+ Series: tt.fields.Series,
+ Number: tt.fields.Number,
+ IssueDate: tt.fields.IssueDate,
+ IssuedBy: tt.fields.IssuedBy,
+ DateBirth: tt.fields.DateBirth,
+ }
+ if got := passport.SetIssuedBy(tt.args.issuedBy); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Passport.SetIssuedBy() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestPassport_SetDateBirth(t *testing.T) {
+ type fields struct {
+ Series *string
+ Number *string
+ IssueDate *string
+ IssuedBy *string
+ DateBirth *string
+ }
+ type args struct {
+ dateBirth time.Time
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Passport
+ }{
+ {
+ name: "set",
+ fields: fields{
+ DateBirth: nil,
+ },
+ args: args{
+ dateBirth: time.Date(1999, 7, 17, 0, 0, 0, 0, time.UTC),
+ },
+ want: &Passport{
+ DateBirth: strLink("1999-07-17"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ DateBirth: strLink("2019-07-17"),
+ },
+ args: args{
+ dateBirth: time.Date(1999, 7, 17, 0, 0, 0, 0, time.UTC),
+ },
+ want: &Passport{
+ DateBirth: strLink("1999-07-17"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ passport := &Passport{
+ Series: tt.fields.Series,
+ Number: tt.fields.Number,
+ IssueDate: tt.fields.IssueDate,
+ IssuedBy: tt.fields.IssuedBy,
+ DateBirth: tt.fields.DateBirth,
+ }
+ if got := passport.SetDateBirth(tt.args.dateBirth); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Passport.SetDateBirth() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNewSender(t *testing.T) {
+ tests := []struct {
+ name string
+ want *Sender
+ }{
+ {
+ name: "constructor",
+ want: &Sender{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewSender(); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewSender() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestSender_SetCompany(t *testing.T) {
+ type fields struct {
+ Company *string
+ Name *string
+ Address *Address
+ }
+ type args struct {
+ company string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Sender
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Company: nil,
+ },
+ args: args{
+ company: "sender company",
+ },
+ want: &Sender{
+ Company: strLink("sender company"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Company: strLink("previous sender company"),
+ },
+ args: args{
+ company: "sender company",
+ },
+ want: &Sender{
+ Company: strLink("sender company"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ sender := &Sender{
+ Company: tt.fields.Company,
+ Name: tt.fields.Name,
+ Address: tt.fields.Address,
+ }
+ if got := sender.SetCompany(tt.args.company); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Sender.SetCompany() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestSender_SetName(t *testing.T) {
+ type fields struct {
+ Company *string
+ Name *string
+ Address *Address
+ }
+ type args struct {
+ name string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Sender
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Name: nil,
+ },
+ args: args{
+ name: "Bobby",
+ },
+ want: &Sender{
+ Name: strLink("Bobby"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Name: strLink("Alex"),
+ },
+ args: args{
+ name: "Bobby",
+ },
+ want: &Sender{
+ Name: strLink("Bobby"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ sender := &Sender{
+ Company: tt.fields.Company,
+ Name: tt.fields.Name,
+ Address: tt.fields.Address,
+ }
+ if got := sender.SetName(tt.args.name); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Sender.SetName() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestSender_SetAddress(t *testing.T) {
+ type fields struct {
+ Company *string
+ Name *string
+ Address *Address
+ }
+ type args struct {
+ address Address
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Sender
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Address: nil,
+ },
+ args: args{
+ address: Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ want: &Sender{
+ Address: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Address: &Address{
+ Street: strLink("previous street"),
+ House: strLink("11/4"),
+ },
+ },
+ args: args{
+ address: Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ want: &Sender{
+ Address: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ sender := &Sender{
+ Company: tt.fields.Company,
+ Name: tt.fields.Name,
+ Address: tt.fields.Address,
+ }
+ if got := sender.SetAddress(tt.args.address); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Sender.SetAddress() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNewAddress(t *testing.T) {
+ type args struct {
+ street string
+ house string
+ }
+ tests := []struct {
+ name string
+ args args
+ want *Address
+ }{
+ {
+ name: "constructor",
+ args: args{
+ street: "test street",
+ house: "10/3",
+ },
+ want: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewAddress(tt.args.street, tt.args.house); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewAddress() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestAddress_SetFlat(t *testing.T) {
+ type fields struct {
+ Street *string
+ House *string
+ Flat *string
+ Phone *string
+ PvzCode *string
+ }
+ type args struct {
+ flat string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Address
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ Flat: nil,
+ },
+ args: args{
+ flat: "12b",
+ },
+ want: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ Flat: strLink("12b"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ Flat: strLink("12a"),
+ },
+ args: args{
+ flat: "12b",
+ },
+ want: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ Flat: strLink("12b"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ address := &Address{
+ Street: tt.fields.Street,
+ House: tt.fields.House,
+ Flat: tt.fields.Flat,
+ Phone: tt.fields.Phone,
+ PvzCode: tt.fields.PvzCode,
+ }
+ if got := address.SetFlat(tt.args.flat); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Address.SetFlat() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestAddress_SetPhone(t *testing.T) {
+ type fields struct {
+ Street *string
+ House *string
+ Flat *string
+ Phone *string
+ PvzCode *string
+ }
+ type args struct {
+ phone string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Address
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ Phone: nil,
+ },
+ args: args{
+ phone: "+79138739944",
+ },
+ want: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ Phone: strLink("+79138739944"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ Phone: strLink("+89138739999"),
+ },
+ args: args{
+ phone: "+79138739944",
+ },
+ want: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ Phone: strLink("+79138739944"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ address := &Address{
+ Street: tt.fields.Street,
+ House: tt.fields.House,
+ Flat: tt.fields.Flat,
+ Phone: tt.fields.Phone,
+ PvzCode: tt.fields.PvzCode,
+ }
+ if got := address.SetPhone(tt.args.phone); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Address.SetPhone() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestAddress_SetPvzCode(t *testing.T) {
+ type fields struct {
+ Street *string
+ House *string
+ Flat *string
+ Phone *string
+ PvzCode *string
+ }
+ type args struct {
+ pvzCode string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Address
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ PvzCode: nil,
+ },
+ args: args{
+ pvzCode: "NSK333",
+ },
+ want: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ PvzCode: strLink("NSK333"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ PvzCode: strLink("NSK777"),
+ },
+ args: args{
+ pvzCode: "NSK333",
+ },
+ want: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ PvzCode: strLink("NSK333"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ address := &Address{
+ Street: tt.fields.Street,
+ House: tt.fields.House,
+ Flat: tt.fields.Flat,
+ Phone: tt.fields.Phone,
+ PvzCode: tt.fields.PvzCode,
+ }
+ if got := address.SetPvzCode(tt.args.pvzCode); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Address.SetPvzCode() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNewSeller(t *testing.T) {
+ tests := []struct {
+ name string
+ want *Seller
+ }{
+ {
+ name: "constructor",
+ want: &Seller{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewSeller(); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewSeller() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestSeller_SetAddress(t *testing.T) {
+ type fields struct {
+ Address *string
+ Name *string
+ INN *string
+ Phone *string
+ OwnershipForm *int
+ }
+ type args struct {
+ address string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Seller
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Address: nil,
+ },
+ args: args{
+ address: "test address",
+ },
+ want: &Seller{
+ Address: strLink("test address"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Address: strLink("previous address"),
+ },
+ args: args{
+ address: "test address",
+ },
+ want: &Seller{
+ Address: strLink("test address"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ seller := &Seller{
+ Address: tt.fields.Address,
+ Name: tt.fields.Name,
+ INN: tt.fields.INN,
+ Phone: tt.fields.Phone,
+ OwnershipForm: tt.fields.OwnershipForm,
+ }
+ if got := seller.SetAddress(tt.args.address); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Seller.SetAddress() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestSeller_SetName(t *testing.T) {
+ type fields struct {
+ Address *string
+ Name *string
+ INN *string
+ Phone *string
+ OwnershipForm *int
+ }
+ type args struct {
+ name string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Seller
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Name: nil,
+ },
+ args: args{
+ name: "test name",
+ },
+ want: &Seller{
+ Name: strLink("test name"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Name: strLink("previous name"),
+ },
+ args: args{
+ name: "test name",
+ },
+ want: &Seller{
+ Name: strLink("test name"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ seller := &Seller{
+ Address: tt.fields.Address,
+ Name: tt.fields.Name,
+ INN: tt.fields.INN,
+ Phone: tt.fields.Phone,
+ OwnershipForm: tt.fields.OwnershipForm,
+ }
+ if got := seller.SetName(tt.args.name); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Seller.SetName() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestSeller_SetINN(t *testing.T) {
+ type fields struct {
+ Address *string
+ Name *string
+ INN *string
+ Phone *string
+ OwnershipForm *int
+ }
+ type args struct {
+ inn string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Seller
+ }{
+ {
+ name: "set",
+ fields: fields{
+ INN: nil,
+ },
+ args: args{
+ inn: "12345678987",
+ },
+ want: &Seller{
+ INN: strLink("12345678987"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ INN: strLink("98765432123"),
+ },
+ args: args{
+ inn: "12345678987",
+ },
+ want: &Seller{
+ INN: strLink("12345678987"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ seller := &Seller{
+ Address: tt.fields.Address,
+ Name: tt.fields.Name,
+ INN: tt.fields.INN,
+ Phone: tt.fields.Phone,
+ OwnershipForm: tt.fields.OwnershipForm,
+ }
+ if got := seller.SetINN(tt.args.inn); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Seller.SetINN() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestSeller_SetPhone(t *testing.T) {
+ type fields struct {
+ Address *string
+ Name *string
+ INN *string
+ Phone *string
+ OwnershipForm *int
+ }
+ type args struct {
+ phone string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Seller
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Phone: nil,
+ },
+ args: args{
+ phone: "+79138739944",
+ },
+ want: &Seller{
+ Phone: strLink("+79138739944"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Phone: strLink("+89138739999"),
+ },
+ args: args{
+ phone: "+79138739944",
+ },
+ want: &Seller{
+ Phone: strLink("+79138739944"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ seller := &Seller{
+ Address: tt.fields.Address,
+ Name: tt.fields.Name,
+ INN: tt.fields.INN,
+ Phone: tt.fields.Phone,
+ OwnershipForm: tt.fields.OwnershipForm,
+ }
+ if got := seller.SetPhone(tt.args.phone); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Seller.SetPhone() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestSeller_SetOwnershipForm(t *testing.T) {
+ type fields struct {
+ Address *string
+ Name *string
+ INN *string
+ Phone *string
+ OwnershipForm *int
+ }
+ type args struct {
+ ownershipForm int
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Seller
+ }{
+ {
+ name: "set",
+ fields: fields{
+ OwnershipForm: nil,
+ },
+ args: args{
+ ownershipForm: 1,
+ },
+ want: &Seller{
+ OwnershipForm: intLink(1),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ OwnershipForm: intLink(2),
+ },
+ args: args{
+ ownershipForm: 1,
+ },
+ want: &Seller{
+ OwnershipForm: intLink(1),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ seller := &Seller{
+ Address: tt.fields.Address,
+ Name: tt.fields.Name,
+ INN: tt.fields.INN,
+ Phone: tt.fields.Phone,
+ OwnershipForm: tt.fields.OwnershipForm,
+ }
+ if got := seller.SetOwnershipForm(tt.args.ownershipForm); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Seller.SetOwnershipForm() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNewOrderPackage(t *testing.T) {
+ type args struct {
+ number string
+ barCode string
+ weight int
+ }
+ tests := []struct {
+ name string
+ args args
+ want *OrderPackage
+ }{
+ {
+ name: "constructor",
+ args: args{
+ number: "test number",
+ barCode: "test barcode",
+ weight: 4500,
+ },
+ want: &OrderPackage{
+ Number: strLink("test number"),
+ BarCode: strLink("test barcode"),
+ Weight: intLink(4500),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewOrderPackage(tt.args.number, tt.args.barCode, tt.args.weight); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewOrderPackage() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderPackage_SetSize(t *testing.T) {
+ type fields struct {
+ Number *string
+ BarCode *string
+ Weight *int
+ SizeA *int
+ SizeB *int
+ SizeC *int
+ Item []*OrderPackageItem
+ }
+ type args struct {
+ length int
+ width int
+ height int
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderPackage
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: strLink("test number"),
+ BarCode: strLink("test barcode"),
+ Weight: intLink(4500),
+ SizeA: nil,
+ SizeB: nil,
+ SizeC: nil,
+ },
+ args: args{
+ length: 50,
+ width: 30,
+ height: 20,
+ },
+ want: &OrderPackage{
+ Number: strLink("test number"),
+ BarCode: strLink("test barcode"),
+ Weight: intLink(4500),
+ SizeA: intLink(50),
+ SizeB: intLink(30),
+ SizeC: intLink(20),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("test number"),
+ BarCode: strLink("test barcode"),
+ Weight: intLink(4500),
+ SizeA: intLink(100),
+ SizeB: intLink(60),
+ SizeC: intLink(40),
+ },
+ args: args{
+ length: 50,
+ width: 30,
+ height: 20,
+ },
+ want: &OrderPackage{
+ Number: strLink("test number"),
+ BarCode: strLink("test barcode"),
+ Weight: intLink(4500),
+ SizeA: intLink(50),
+ SizeB: intLink(30),
+ SizeC: intLink(20),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderPackage := &OrderPackage{
+ Number: tt.fields.Number,
+ BarCode: tt.fields.BarCode,
+ Weight: tt.fields.Weight,
+ SizeA: tt.fields.SizeA,
+ SizeB: tt.fields.SizeB,
+ SizeC: tt.fields.SizeC,
+ Item: tt.fields.Item,
+ }
+ if got := orderPackage.SetSize(tt.args.length, tt.args.width, tt.args.height); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderPackage.SetSize() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderPackage_AddItem(t *testing.T) {
+ type fields struct {
+ Number *string
+ BarCode *string
+ Weight *int
+ SizeA *int
+ SizeB *int
+ SizeC *int
+ Item []*OrderPackageItem
+ }
+ type args struct {
+ item OrderPackageItem
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderPackage
+ }{
+ {
+ name: "add first",
+ fields: fields{
+ Number: strLink("test number"),
+ BarCode: strLink("test barcode"),
+ Weight: intLink(4500),
+ Item: nil,
+ },
+ args: args{
+ item: OrderPackageItem{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ },
+ },
+ want: &OrderPackage{
+ Number: strLink("test number"),
+ BarCode: strLink("test barcode"),
+ Weight: intLink(4500),
+ Item: []*OrderPackageItem{
+ {
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ },
+ },
+ },
+ },
+ {
+ name: "add second",
+ fields: fields{
+ Number: strLink("test number"),
+ BarCode: strLink("test barcode"),
+ Weight: intLink(4500),
+ Item: []*OrderPackageItem{
+ {
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ },
+ },
+ },
+ args: args{
+ item: OrderPackageItem{
+ Amount: intLink(1),
+ WareKey: strLink("00078945"),
+ Cost: float64Link(5500),
+ Payment: float64Link(5500),
+ Weight: intLink(3),
+ Comment: strLink("female jacket"),
+ },
+ },
+ want: &OrderPackage{
+ Number: strLink("test number"),
+ BarCode: strLink("test barcode"),
+ Weight: intLink(4500),
+ Item: []*OrderPackageItem{
+ {
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ },
+ {
+ Amount: intLink(1),
+ WareKey: strLink("00078945"),
+ Cost: float64Link(5500),
+ Payment: float64Link(5500),
+ Weight: intLink(3),
+ Comment: strLink("female jacket"),
+ },
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ orderPackage := &OrderPackage{
+ Number: tt.fields.Number,
+ BarCode: tt.fields.BarCode,
+ Weight: tt.fields.Weight,
+ SizeA: tt.fields.SizeA,
+ SizeB: tt.fields.SizeB,
+ SizeC: tt.fields.SizeC,
+ Item: tt.fields.Item,
+ }
+ if got := orderPackage.AddItem(tt.args.item); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderPackage.AddItem() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNewOrderPackageItem(t *testing.T) {
+ type args struct {
+ amount int
+ wareKey string
+ cost float64
+ payment float64
+ weight int
+ comment string
+ }
+ tests := []struct {
+ name string
+ args args
+ want *OrderPackageItem
+ }{
+ {
+ name: "constructor",
+ args: args{
+ amount: 1,
+ wareKey: "00012345",
+ cost: 500,
+ payment: 500,
+ weight: 2,
+ comment: "wrap",
+ },
+ want: &OrderPackageItem{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := NewOrderPackageItem(
+ tt.args.amount,
+ tt.args.wareKey,
+ tt.args.cost,
+ tt.args.payment,
+ tt.args.weight,
+ tt.args.comment,
+ )
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewOrderPackageItem() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderPackageItem_SetPaymentVATRate(t *testing.T) {
+ type fields struct {
+ Amount *int
+ WareKey *string
+ Cost *float64
+ Payment *float64
+ PaymentVATRate *string
+ PaymentVATSum *float64
+ Weight *int
+ Comment *string
+ WeightBrutto *int
+ CommentEx *string
+ Link *string
+ }
+ type args struct {
+ paymentVATRate string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderPackageItem
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ PaymentVATRate: nil,
+ },
+ args: args{
+ paymentVATRate: "VATX",
+ },
+ want: &OrderPackageItem{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ PaymentVATRate: strLink("VATX"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ PaymentVATRate: strLink("VATY"),
+ },
+ args: args{
+ paymentVATRate: "VATX",
+ },
+ want: &OrderPackageItem{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ PaymentVATRate: strLink("VATX"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ item := &OrderPackageItem{
+ Amount: tt.fields.Amount,
+ WareKey: tt.fields.WareKey,
+ Cost: tt.fields.Cost,
+ Payment: tt.fields.Payment,
+ PaymentVATRate: tt.fields.PaymentVATRate,
+ PaymentVATSum: tt.fields.PaymentVATSum,
+ Weight: tt.fields.Weight,
+ Comment: tt.fields.Comment,
+ WeightBrutto: tt.fields.WeightBrutto,
+ CommentEx: tt.fields.CommentEx,
+ Link: tt.fields.Link,
+ }
+ if got := item.SetPaymentVATRate(tt.args.paymentVATRate); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderPackageItem.SetPaymentVATRate() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderPackageItem_SetPaymentVATSum(t *testing.T) {
+ type fields struct {
+ Amount *int
+ WareKey *string
+ Cost *float64
+ Payment *float64
+ PaymentVATRate *string
+ PaymentVATSum *float64
+ Weight *int
+ Comment *string
+ WeightBrutto *int
+ CommentEx *string
+ Link *string
+ }
+ type args struct {
+ paymentVATSum float64
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderPackageItem
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ PaymentVATSum: nil,
+ },
+ args: args{
+ paymentVATSum: 65.8,
+ },
+ want: &OrderPackageItem{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ PaymentVATSum: float64Link(65.8),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ PaymentVATSum: float64Link(35.1),
+ },
+ args: args{
+ paymentVATSum: 65.8,
+ },
+ want: &OrderPackageItem{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ PaymentVATSum: float64Link(65.8),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ item := &OrderPackageItem{
+ Amount: tt.fields.Amount,
+ WareKey: tt.fields.WareKey,
+ Cost: tt.fields.Cost,
+ Payment: tt.fields.Payment,
+ PaymentVATRate: tt.fields.PaymentVATRate,
+ PaymentVATSum: tt.fields.PaymentVATSum,
+ Weight: tt.fields.Weight,
+ Comment: tt.fields.Comment,
+ WeightBrutto: tt.fields.WeightBrutto,
+ CommentEx: tt.fields.CommentEx,
+ Link: tt.fields.Link,
+ }
+ if got := item.SetPaymentVATSum(tt.args.paymentVATSum); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderPackageItem.SetPaymentVATSum() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderPackageItem_SetWeightBrutto(t *testing.T) {
+ type fields struct {
+ Amount *int
+ WareKey *string
+ Cost *float64
+ Payment *float64
+ PaymentVATRate *string
+ PaymentVATSum *float64
+ Weight *int
+ Comment *string
+ WeightBrutto *int
+ CommentEx *string
+ Link *string
+ }
+ type args struct {
+ weightBrutto int
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderPackageItem
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ WeightBrutto: nil,
+ },
+ args: args{
+ weightBrutto: 1500,
+ },
+ want: &OrderPackageItem{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ WeightBrutto: intLink(1500),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ WeightBrutto: intLink(3000),
+ },
+ args: args{
+ weightBrutto: 1500,
+ },
+ want: &OrderPackageItem{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ WeightBrutto: intLink(1500),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ item := &OrderPackageItem{
+ Amount: tt.fields.Amount,
+ WareKey: tt.fields.WareKey,
+ Cost: tt.fields.Cost,
+ Payment: tt.fields.Payment,
+ PaymentVATRate: tt.fields.PaymentVATRate,
+ PaymentVATSum: tt.fields.PaymentVATSum,
+ Weight: tt.fields.Weight,
+ Comment: tt.fields.Comment,
+ WeightBrutto: tt.fields.WeightBrutto,
+ CommentEx: tt.fields.CommentEx,
+ Link: tt.fields.Link,
+ }
+ if got := item.SetWeightBrutto(tt.args.weightBrutto); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderPackageItem.SetWeightBrutto() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderPackageItem_SetCommentEx(t *testing.T) {
+ type fields struct {
+ Amount *int
+ WareKey *string
+ Cost *float64
+ Payment *float64
+ PaymentVATRate *string
+ PaymentVATSum *float64
+ Weight *int
+ Comment *string
+ WeightBrutto *int
+ CommentEx *string
+ Link *string
+ }
+ type args struct {
+ commentEx string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderPackageItem
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ CommentEx: nil,
+ },
+ args: args{
+ commentEx: "red hat",
+ },
+ want: &OrderPackageItem{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ CommentEx: strLink("red hat"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ CommentEx: strLink("blue hat"),
+ },
+ args: args{
+ commentEx: "red hat",
+ },
+ want: &OrderPackageItem{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ CommentEx: strLink("red hat"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ item := &OrderPackageItem{
+ Amount: tt.fields.Amount,
+ WareKey: tt.fields.WareKey,
+ Cost: tt.fields.Cost,
+ Payment: tt.fields.Payment,
+ PaymentVATRate: tt.fields.PaymentVATRate,
+ PaymentVATSum: tt.fields.PaymentVATSum,
+ Weight: tt.fields.Weight,
+ Comment: tt.fields.Comment,
+ WeightBrutto: tt.fields.WeightBrutto,
+ CommentEx: tt.fields.CommentEx,
+ Link: tt.fields.Link,
+ }
+ if got := item.SetCommentEx(tt.args.commentEx); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderPackageItem.SetCommentEx() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestOrderPackageItem_SetLink(t *testing.T) {
+ type fields struct {
+ Amount *int
+ WareKey *string
+ Cost *float64
+ Payment *float64
+ PaymentVATRate *string
+ PaymentVATSum *float64
+ Weight *int
+ Comment *string
+ WeightBrutto *int
+ CommentEx *string
+ Link *string
+ }
+ type args struct {
+ link string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *OrderPackageItem
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ Link: nil,
+ },
+ args: args{
+ link: "some://link",
+ },
+ want: &OrderPackageItem{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ Link: strLink("some://link"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ Link: strLink("other://link"),
+ },
+ args: args{
+ link: "some://link",
+ },
+ want: &OrderPackageItem{
+ Amount: intLink(1),
+ WareKey: strLink("00012345"),
+ Cost: float64Link(500),
+ Payment: float64Link(500),
+ Weight: intLink(2),
+ Comment: strLink("wrap"),
+ Link: strLink("some://link"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ item := &OrderPackageItem{
+ Amount: tt.fields.Amount,
+ WareKey: tt.fields.WareKey,
+ Cost: tt.fields.Cost,
+ Payment: tt.fields.Payment,
+ PaymentVATRate: tt.fields.PaymentVATRate,
+ PaymentVATSum: tt.fields.PaymentVATSum,
+ Weight: tt.fields.Weight,
+ Comment: tt.fields.Comment,
+ WeightBrutto: tt.fields.WeightBrutto,
+ CommentEx: tt.fields.CommentEx,
+ Link: tt.fields.Link,
+ }
+ if got := item.SetLink(tt.args.link); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("OrderPackageItem.SetLink() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNewDeliveryRecipientCostAdv(t *testing.T) {
+ type args struct {
+ threshold int
+ sum float64
+ }
+ tests := []struct {
+ name string
+ args args
+ want *DeliveryRecipientCostAdv
+ }{
+ {
+ name: "constructor",
+ args: args{
+ threshold: 999,
+ sum: 333.99,
+ },
+ want: &DeliveryRecipientCostAdv{
+ Threshold: intLink(999),
+ Sum: float64Link(333.99),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewDeliveryRecipientCostAdv(tt.args.threshold, tt.args.sum); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewDeliveryRecipientCostAdv() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestDeliveryRecipientCostAdv_SetVATRate(t *testing.T) {
+ type fields struct {
+ Threshold *int
+ Sum *float64
+ VATRate *string
+ VATSum *float64
+ }
+ type args struct {
+ vatRate string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *DeliveryRecipientCostAdv
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Threshold: intLink(999),
+ Sum: float64Link(333.99),
+ VATRate: nil,
+ },
+ args: args{
+ vatRate: "VATX",
+ },
+ want: &DeliveryRecipientCostAdv{
+ Threshold: intLink(999),
+ Sum: float64Link(333.99),
+ VATRate: strLink("VATX"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Threshold: intLink(999),
+ Sum: float64Link(333.99),
+ VATRate: strLink("VATY"),
+ },
+ args: args{
+ vatRate: "VATX",
+ },
+ want: &DeliveryRecipientCostAdv{
+ Threshold: intLink(999),
+ Sum: float64Link(333.99),
+ VATRate: strLink("VATX"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &DeliveryRecipientCostAdv{
+ Threshold: tt.fields.Threshold,
+ Sum: tt.fields.Sum,
+ VATRate: tt.fields.VATRate,
+ VATSum: tt.fields.VATSum,
+ }
+ if got := d.SetVATRate(tt.args.vatRate); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("DeliveryRecipientCostAdv.SetVATRate() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestDeliveryRecipientCostAdv_SetVATSum(t *testing.T) {
+ type fields struct {
+ Threshold *int
+ Sum *float64
+ VATRate *string
+ VATSum *float64
+ }
+ type args struct {
+ vatSum float64
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *DeliveryRecipientCostAdv
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Threshold: intLink(999),
+ Sum: float64Link(333.99),
+ VATSum: nil,
+ },
+ args: args{
+ vatSum: 54.3,
+ },
+ want: &DeliveryRecipientCostAdv{
+ Threshold: intLink(999),
+ Sum: float64Link(333.99),
+ VATSum: float64Link(54.3),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Threshold: intLink(999),
+ Sum: float64Link(333.99),
+ VATSum: float64Link(32.1),
+ },
+ args: args{
+ vatSum: 54.3,
+ },
+ want: &DeliveryRecipientCostAdv{
+ Threshold: intLink(999),
+ Sum: float64Link(333.99),
+ VATSum: float64Link(54.3),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &DeliveryRecipientCostAdv{
+ Threshold: tt.fields.Threshold,
+ Sum: tt.fields.Sum,
+ VATRate: tt.fields.VATRate,
+ VATSum: tt.fields.VATSum,
+ }
+ if got := d.SetVATSum(tt.args.vatSum); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("DeliveryRecipientCostAdv.SetVATSum() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNewAddService(t *testing.T) {
+ type args struct {
+ serviceCode int
+ }
+ tests := []struct {
+ name string
+ args args
+ want *AddService
+ }{
+ {
+ name: "constructor",
+ args: args{
+ serviceCode: 123,
+ },
+ want: &AddService{
+ ServiceCode: intLink(123),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewAddService(tt.args.serviceCode); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewAddService() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestAddService_SetCount(t *testing.T) {
+ type fields struct {
+ ServiceCode *int
+ Count *int
+ }
+ type args struct {
+ count int
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *AddService
+ }{
+ {
+ name: "add",
+ fields: fields{
+ ServiceCode: intLink(123),
+ Count: nil,
+ },
+ args: args{
+ count: 1,
+ },
+ want: &AddService{
+ ServiceCode: intLink(123),
+ Count: intLink(1),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ ServiceCode: intLink(123),
+ Count: intLink(3),
+ },
+ args: args{
+ count: 1,
+ },
+ want: &AddService{
+ ServiceCode: intLink(123),
+ Count: intLink(1),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ addService := &AddService{
+ ServiceCode: tt.fields.ServiceCode,
+ Count: tt.fields.Count,
+ }
+ if got := addService.SetCount(tt.args.count); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("AddService.SetCount() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNewSchedule(t *testing.T) {
+ tests := []struct {
+ name string
+ want *Schedule
+ }{
+ {
+ name: "constructor",
+ want: &Schedule{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewSchedule(); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewSchedule() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestSchedule_AddAttempt(t *testing.T) {
+ type fields struct {
+ Attempt []*ScheduleAttempt
+ }
+ type args struct {
+ attempt ScheduleAttempt
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *Schedule
+ }{
+ {
+ name: "add first",
+ fields: fields{
+ Attempt: nil,
+ },
+ args: args{
+ attempt: ScheduleAttempt{
+ ID: strLink("attempt id"),
+ Date: strLink("2019-07-17"),
+ },
+ },
+ want: &Schedule{
+ Attempt: []*ScheduleAttempt{
+ {
+ ID: strLink("attempt id"),
+ Date: strLink("2019-07-17"),
+ },
+ },
+ },
+ },
+ {
+ name: "add second",
+ fields: fields{
+ Attempt: []*ScheduleAttempt{
+ {
+ ID: strLink("attempt id"),
+ Date: strLink("2019-07-17"),
+ },
+ },
+ },
+ args: args{
+ attempt: ScheduleAttempt{
+ ID: strLink("attempt id 2"),
+ Date: strLink("2019-07-20"),
+ },
+ },
+ want: &Schedule{
+ Attempt: []*ScheduleAttempt{
+ {
+ ID: strLink("attempt id"),
+ Date: strLink("2019-07-17"),
+ },
+ {
+ ID: strLink("attempt id 2"),
+ Date: strLink("2019-07-20"),
+ },
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ schedule := &Schedule{
+ Attempt: tt.fields.Attempt,
+ }
+ if got := schedule.AddAttempt(tt.args.attempt); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Schedule.AddAttempt() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNewScheduleAttempt(t *testing.T) {
+ type args struct {
+ id string
+ date time.Time
+ }
+ tests := []struct {
+ name string
+ args args
+ want *ScheduleAttempt
+ }{
+ {
+ name: "constructor",
+ args: args{
+ id: "attempt_id",
+ date: time.Date(2019, 7, 17, 0, 0, 0, 0, time.UTC),
+ },
+ want: &ScheduleAttempt{
+ ID: strLink("attempt_id"),
+ Date: strLink("2019-07-17"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewScheduleAttempt(tt.args.id, tt.args.date); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewScheduleAttempt() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestScheduleAttempt_SetComment(t *testing.T) {
+ type fields struct {
+ ID *string
+ Date *string
+ Comment *string
+ TimeBeg *string
+ TimeEnd *string
+ Address *Address
+ }
+ type args struct {
+ comment string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *ScheduleAttempt
+ }{
+ {
+ name: "set",
+ fields: fields{
+ ID: strLink("attempt_id"),
+ Date: strLink("2019-07-17"),
+ Comment: nil,
+ },
+ args: args{
+ comment: "comment text",
+ },
+ want: &ScheduleAttempt{
+ ID: strLink("attempt_id"),
+ Date: strLink("2019-07-17"),
+ Comment: strLink("comment text"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ ID: strLink("attempt_id"),
+ Date: strLink("2019-07-17"),
+ Comment: strLink("previous comment text"),
+ },
+ args: args{
+ comment: "comment text",
+ },
+ want: &ScheduleAttempt{
+ ID: strLink("attempt_id"),
+ Date: strLink("2019-07-17"),
+ Comment: strLink("comment text"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ scheduleAttempt := &ScheduleAttempt{
+ ID: tt.fields.ID,
+ Date: tt.fields.Date,
+ Comment: tt.fields.Comment,
+ TimeBeg: tt.fields.TimeBeg,
+ TimeEnd: tt.fields.TimeEnd,
+ Address: tt.fields.Address,
+ }
+ if got := scheduleAttempt.SetComment(tt.args.comment); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("ScheduleAttempt.SetComment() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestScheduleAttempt_SetTimeBeg(t *testing.T) {
+ type fields struct {
+ ID *string
+ Date *string
+ Comment *string
+ TimeBeg *string
+ TimeEnd *string
+ Address *Address
+ }
+ type args struct {
+ timeBeg string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *ScheduleAttempt
+ }{
+ {
+ name: "set",
+ fields: fields{
+ ID: strLink("attempt_id"),
+ Date: strLink("2019-07-17"),
+ TimeBeg: nil,
+ },
+ args: args{
+ timeBeg: "20:14",
+ },
+ want: &ScheduleAttempt{
+ ID: strLink("attempt_id"),
+ Date: strLink("2019-07-17"),
+ TimeBeg: strLink("20:14"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ ID: strLink("attempt_id"),
+ Date: strLink("2019-07-17"),
+ TimeBeg: strLink("19:10"),
+ },
+ args: args{
+ timeBeg: "20:14",
+ },
+ want: &ScheduleAttempt{
+ ID: strLink("attempt_id"),
+ Date: strLink("2019-07-17"),
+ TimeBeg: strLink("20:14"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ scheduleAttempt := &ScheduleAttempt{
+ ID: tt.fields.ID,
+ Date: tt.fields.Date,
+ Comment: tt.fields.Comment,
+ TimeBeg: tt.fields.TimeBeg,
+ TimeEnd: tt.fields.TimeEnd,
+ Address: tt.fields.Address,
+ }
+ if got := scheduleAttempt.SetTimeBeg(tt.args.timeBeg); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("ScheduleAttempt.SetTimeBeg() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestScheduleAttempt_SetTimeEnd(t *testing.T) {
+ type fields struct {
+ ID *string
+ Date *string
+ Comment *string
+ TimeBeg *string
+ TimeEnd *string
+ Address *Address
+ }
+ type args struct {
+ timeEnd string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *ScheduleAttempt
+ }{
+ {
+ name: "set",
+ fields: fields{
+ ID: strLink("attempt_id"),
+ Date: strLink("2019-07-17"),
+ TimeEnd: nil,
+ },
+ args: args{
+ timeEnd: "20:14",
+ },
+ want: &ScheduleAttempt{
+ ID: strLink("attempt_id"),
+ Date: strLink("2019-07-17"),
+ TimeEnd: strLink("20:14"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ ID: strLink("attempt_id"),
+ Date: strLink("2019-07-17"),
+ TimeEnd: strLink("19:10"),
+ },
+ args: args{
+ timeEnd: "20:14",
+ },
+ want: &ScheduleAttempt{
+ ID: strLink("attempt_id"),
+ Date: strLink("2019-07-17"),
+ TimeEnd: strLink("20:14"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ scheduleAttempt := &ScheduleAttempt{
+ ID: tt.fields.ID,
+ Date: tt.fields.Date,
+ Comment: tt.fields.Comment,
+ TimeBeg: tt.fields.TimeBeg,
+ TimeEnd: tt.fields.TimeEnd,
+ Address: tt.fields.Address,
+ }
+ if got := scheduleAttempt.SetTimeEnd(tt.args.timeEnd); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("ScheduleAttempt.SetTimeEnd() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestScheduleAttempt_SetAddress(t *testing.T) {
+ type fields struct {
+ ID *string
+ Date *string
+ Comment *string
+ TimeBeg *string
+ TimeEnd *string
+ Address *Address
+ }
+ type args struct {
+ address Address
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *ScheduleAttempt
+ }{
+ {
+ name: "set",
+ fields: fields{
+ ID: strLink("attempt_id"),
+ Date: strLink("2019-07-17"),
+ Address: nil,
+ },
+ args: args{
+ address: Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ want: &ScheduleAttempt{
+ ID: strLink("attempt_id"),
+ Date: strLink("2019-07-17"),
+ Address: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ ID: strLink("attempt_id"),
+ Date: strLink("2019-07-17"),
+ Address: &Address{
+ Street: strLink("previous street"),
+ House: strLink("11/4"),
+ },
+ },
+ args: args{
+ address: Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ want: &ScheduleAttempt{
+ ID: strLink("attempt_id"),
+ Date: strLink("2019-07-17"),
+ Address: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ scheduleAttempt := &ScheduleAttempt{
+ ID: tt.fields.ID,
+ Date: tt.fields.Date,
+ Comment: tt.fields.Comment,
+ TimeBeg: tt.fields.TimeBeg,
+ TimeEnd: tt.fields.TimeEnd,
+ Address: tt.fields.Address,
+ }
+ if got := scheduleAttempt.SetAddress(tt.args.address); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("ScheduleAttempt.SetAddress() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNewCallCourier(t *testing.T) {
+ type args struct {
+ call CourierCallReq
+ }
+ tests := []struct {
+ name string
+ args args
+ want *CallCourier
+ }{
+ {
+ name: "constructor",
+ args: args{
+ call: CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ },
+ want: &CallCourier{
+ Call: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewCallCourier(tt.args.call); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewCallCourier() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNewCourierCall(t *testing.T) {
+ type args struct {
+ date time.Time
+ timeBeg string
+ timeEnd string
+ sendPhone string
+ senderName string
+ sendAddress Address
+ }
+ tests := []struct {
+ name string
+ args args
+ want *CourierCallReq
+ }{
+ {
+ name: "constructor",
+ args: args{
+ date: time.Date(2019, 7, 15, 0, 0, 0, 0, time.UTC),
+ timeBeg: "10:00",
+ timeEnd: "17:00",
+ sendPhone: "+79138739944",
+ senderName: "full name",
+ sendAddress: Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ want: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := NewCourierCall(
+ tt.args.date,
+ tt.args.timeBeg,
+ tt.args.timeEnd,
+ tt.args.sendPhone,
+ tt.args.senderName,
+ tt.args.sendAddress,
+ )
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewCourierCall() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestCourierCallReq_SetLunchBeg(t *testing.T) {
+ type fields struct {
+ Date *string
+ TimeBeg *string
+ TimeEnd *string
+ LunchBeg *string
+ LunchEnd *string
+ SendCityCode *int
+ SendCityPostCode *string
+ SendCountryCode *string
+ SendCityName *string
+ SendPhone *string
+ SenderName *string
+ Comment *string
+ SendAddress *Address
+ }
+ type args struct {
+ lunchBeg string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *CourierCallReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ LunchBeg: nil,
+ },
+ args: args{
+ lunchBeg: "12:00",
+ },
+ want: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ LunchBeg: strLink("12:00"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ LunchBeg: strLink("13:00"),
+ },
+ args: args{
+ lunchBeg: "12:00",
+ },
+ want: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ LunchBeg: strLink("12:00"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ call := &CourierCallReq{
+ Date: tt.fields.Date,
+ TimeBeg: tt.fields.TimeBeg,
+ TimeEnd: tt.fields.TimeEnd,
+ LunchBeg: tt.fields.LunchBeg,
+ LunchEnd: tt.fields.LunchEnd,
+ SendCityCode: tt.fields.SendCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ SendPhone: tt.fields.SendPhone,
+ SenderName: tt.fields.SenderName,
+ Comment: tt.fields.Comment,
+ SendAddress: tt.fields.SendAddress,
+ }
+ if got := call.SetLunchBeg(tt.args.lunchBeg); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("CourierCallReq.SetLunchBeg() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestCourierCallReq_SetLunchEnd(t *testing.T) {
+ type fields struct {
+ Date *string
+ TimeBeg *string
+ TimeEnd *string
+ LunchBeg *string
+ LunchEnd *string
+ SendCityCode *int
+ SendCityPostCode *string
+ SendCountryCode *string
+ SendCityName *string
+ SendPhone *string
+ SenderName *string
+ Comment *string
+ SendAddress *Address
+ }
+ type args struct {
+ lunchEnd string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *CourierCallReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ LunchEnd: nil,
+ },
+ args: args{
+ lunchEnd: "12:00",
+ },
+ want: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ LunchEnd: strLink("12:00"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ LunchEnd: strLink("14:00"),
+ },
+ args: args{
+ lunchEnd: "13:00",
+ },
+ want: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ LunchEnd: strLink("13:00"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ call := &CourierCallReq{
+ Date: tt.fields.Date,
+ TimeBeg: tt.fields.TimeBeg,
+ TimeEnd: tt.fields.TimeEnd,
+ LunchBeg: tt.fields.LunchBeg,
+ LunchEnd: tt.fields.LunchEnd,
+ SendCityCode: tt.fields.SendCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ SendPhone: tt.fields.SendPhone,
+ SenderName: tt.fields.SenderName,
+ Comment: tt.fields.Comment,
+ SendAddress: tt.fields.SendAddress,
+ }
+ if got := call.SetLunchEnd(tt.args.lunchEnd); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("CourierCallReq.SetLunchEnd() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestCourierCallReq_SetSendCityCode(t *testing.T) {
+ type fields struct {
+ Date *string
+ TimeBeg *string
+ TimeEnd *string
+ LunchBeg *string
+ LunchEnd *string
+ SendCityCode *int
+ SendCityPostCode *string
+ SendCountryCode *string
+ SendCityName *string
+ SendPhone *string
+ SenderName *string
+ Comment *string
+ SendAddress *Address
+ }
+ type args struct {
+ sendCityCode int
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *CourierCallReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ SendCityCode: nil,
+ },
+ args: args{
+ sendCityCode: 44,
+ },
+ want: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ SendCityCode: intLink(44),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ SendCityCode: intLink(55),
+ },
+ args: args{
+ sendCityCode: 44,
+ },
+ want: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ SendCityCode: intLink(44),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ call := &CourierCallReq{
+ Date: tt.fields.Date,
+ TimeBeg: tt.fields.TimeBeg,
+ TimeEnd: tt.fields.TimeEnd,
+ LunchBeg: tt.fields.LunchBeg,
+ LunchEnd: tt.fields.LunchEnd,
+ SendCityCode: tt.fields.SendCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ SendPhone: tt.fields.SendPhone,
+ SenderName: tt.fields.SenderName,
+ Comment: tt.fields.Comment,
+ SendAddress: tt.fields.SendAddress,
+ }
+ if got := call.SetSendCityCode(tt.args.sendCityCode); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("CourierCallReq.SetSendCityCode() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestCourierCallReq_SetSendCityPostCode(t *testing.T) {
+ type fields struct {
+ Date *string
+ TimeBeg *string
+ TimeEnd *string
+ LunchBeg *string
+ LunchEnd *string
+ SendCityCode *int
+ SendCityPostCode *string
+ SendCountryCode *string
+ SendCityName *string
+ SendPhone *string
+ SenderName *string
+ Comment *string
+ SendAddress *Address
+ }
+ type args struct {
+ sendCityPostCode string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *CourierCallReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ SendCityPostCode: nil,
+ },
+ args: args{
+ sendCityPostCode: "98690",
+ },
+ want: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ SendCityPostCode: strLink("98690"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ SendCityPostCode: strLink("98734"),
+ },
+ args: args{
+ sendCityPostCode: "98690",
+ },
+ want: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ SendCityPostCode: strLink("98690"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ call := &CourierCallReq{
+ Date: tt.fields.Date,
+ TimeBeg: tt.fields.TimeBeg,
+ TimeEnd: tt.fields.TimeEnd,
+ LunchBeg: tt.fields.LunchBeg,
+ LunchEnd: tt.fields.LunchEnd,
+ SendCityCode: tt.fields.SendCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ SendPhone: tt.fields.SendPhone,
+ SenderName: tt.fields.SenderName,
+ Comment: tt.fields.Comment,
+ SendAddress: tt.fields.SendAddress,
+ }
+ if got := call.SetSendCityPostCode(tt.args.sendCityPostCode); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("CourierCallReq.SetSendCityPostCode() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestCourierCallReq_SetSendCountryCode(t *testing.T) {
+ type fields struct {
+ Date *string
+ TimeBeg *string
+ TimeEnd *string
+ LunchBeg *string
+ LunchEnd *string
+ SendCityCode *int
+ SendCityPostCode *string
+ SendCountryCode *string
+ SendCityName *string
+ SendPhone *string
+ SenderName *string
+ Comment *string
+ SendAddress *Address
+ }
+ type args struct {
+ sendCountryCode string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *CourierCallReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ SendCountryCode: nil,
+ },
+ args: args{
+ sendCountryCode: "RU",
+ },
+ want: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ SendCountryCode: strLink("RU"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ SendCountryCode: strLink("UA"),
+ },
+ args: args{
+ sendCountryCode: "RU",
+ },
+ want: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ SendCountryCode: strLink("RU"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ call := &CourierCallReq{
+ Date: tt.fields.Date,
+ TimeBeg: tt.fields.TimeBeg,
+ TimeEnd: tt.fields.TimeEnd,
+ LunchBeg: tt.fields.LunchBeg,
+ LunchEnd: tt.fields.LunchEnd,
+ SendCityCode: tt.fields.SendCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ SendPhone: tt.fields.SendPhone,
+ SenderName: tt.fields.SenderName,
+ Comment: tt.fields.Comment,
+ SendAddress: tt.fields.SendAddress,
+ }
+ if got := call.SetSendCountryCode(tt.args.sendCountryCode); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("CourierCallReq.SetSendCountryCode() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestCourierCallReq_SetSendCityName(t *testing.T) {
+ type fields struct {
+ Date *string
+ TimeBeg *string
+ TimeEnd *string
+ LunchBeg *string
+ LunchEnd *string
+ SendCityCode *int
+ SendCityPostCode *string
+ SendCountryCode *string
+ SendCityName *string
+ SendPhone *string
+ SenderName *string
+ Comment *string
+ SendAddress *Address
+ }
+ type args struct {
+ sendCityName string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *CourierCallReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ SendCityName: nil,
+ },
+ args: args{
+ sendCityName: "Орел",
+ },
+ want: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ SendCityName: strLink("Орел"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ SendCityName: strLink("Саранск"),
+ },
+ args: args{
+ sendCityName: "Орел",
+ },
+ want: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ SendCityName: strLink("Орел"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ call := &CourierCallReq{
+ Date: tt.fields.Date,
+ TimeBeg: tt.fields.TimeBeg,
+ TimeEnd: tt.fields.TimeEnd,
+ LunchBeg: tt.fields.LunchBeg,
+ LunchEnd: tt.fields.LunchEnd,
+ SendCityCode: tt.fields.SendCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ SendPhone: tt.fields.SendPhone,
+ SenderName: tt.fields.SenderName,
+ Comment: tt.fields.Comment,
+ SendAddress: tt.fields.SendAddress,
+ }
+ if got := call.SetSendCityName(tt.args.sendCityName); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("CourierCallReq.SetSendCityName() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestCourierCallReq_SetComment(t *testing.T) {
+ type fields struct {
+ Date *string
+ TimeBeg *string
+ TimeEnd *string
+ LunchBeg *string
+ LunchEnd *string
+ SendCityCode *int
+ SendCityPostCode *string
+ SendCountryCode *string
+ SendCityName *string
+ SendPhone *string
+ SenderName *string
+ Comment *string
+ SendAddress *Address
+ }
+ type args struct {
+ comment string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *CourierCallReq
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ Comment: nil,
+ },
+ args: args{
+ comment: "comment",
+ },
+ want: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ Comment: strLink("comment"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ Comment: strLink("previous comment"),
+ },
+ args: args{
+ comment: "comment",
+ },
+ want: &CourierCallReq{
+ Date: strLink("2019-07-15"),
+ TimeBeg: strLink("10:00"),
+ TimeEnd: strLink("17:00"),
+ SendPhone: strLink("+79138739944"),
+ SenderName: strLink("full name"),
+ SendAddress: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ Comment: strLink("comment"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ call := &CourierCallReq{
+ Date: tt.fields.Date,
+ TimeBeg: tt.fields.TimeBeg,
+ TimeEnd: tt.fields.TimeEnd,
+ LunchBeg: tt.fields.LunchBeg,
+ LunchEnd: tt.fields.LunchEnd,
+ SendCityCode: tt.fields.SendCityCode,
+ SendCityPostCode: tt.fields.SendCityPostCode,
+ SendCountryCode: tt.fields.SendCountryCode,
+ SendCityName: tt.fields.SendCityName,
+ SendPhone: tt.fields.SendPhone,
+ SenderName: tt.fields.SenderName,
+ Comment: tt.fields.Comment,
+ SendAddress: tt.fields.SendAddress,
+ }
+ if got := call.SetComment(tt.args.comment); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("CourierCallReq.SetComment() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
diff --git a/register-order-service.go b/register-order-service.go
new file mode 100755
index 0000000..d726998
--- /dev/null
+++ b/register-order-service.go
@@ -0,0 +1,69 @@
+package cdek
+
+import (
+ "encoding/xml"
+ "io/ioutil"
+ "net/http"
+ "net/url"
+ "path"
+ "strings"
+
+ "github.com/hashicorp/go-multierror"
+)
+
+const registerOrderURL = "new_orders.php"
+
+//RegisterOrder This method is used to register orders to be delivered to clients.
+func (c Client) RegisterOrder(req RegisterOrderReq) (*RegisterOrderResp, error) {
+ req.setAuth(c.auth)
+ reqByte, err := xml.Marshal(req)
+
+ if err != nil {
+ return nil, err
+ }
+
+ data := make(url.Values)
+ data.Add("xml_request", string(reqByte))
+
+ serverURL, err := url.Parse(c.apiURL)
+ if err != nil {
+ return nil, err
+ }
+
+ serverURL.Path = path.Join(serverURL.Path, registerOrderURL)
+ reqURL := serverURL.String()
+
+ resp, err := http.Post(reqURL, urlFormEncoded, strings.NewReader(data.Encode()))
+ if err != nil {
+ return nil, err
+ }
+
+ defer func() {
+ _ = resp.Body.Close()
+ }()
+
+ body, _ := ioutil.ReadAll(resp.Body)
+
+ var registerOrderResp RegisterOrderResp
+ err = xml.Unmarshal(body, ®isterOrderResp)
+ if err != nil {
+ return nil, err
+ }
+
+ multiError := &multierror.Error{}
+ for _, o := range registerOrderResp.Order {
+ if o.IsErroneous() {
+ multiError = multierror.Append(o.GetError())
+ }
+ }
+ for _, c := range registerOrderResp.Call {
+ if c.IsErroneous() {
+ multiError = multierror.Append(c.Error)
+ }
+ }
+ if multiError.Len() > 0 {
+ return nil, multiError.ErrorOrNil()
+ }
+
+ return ®isterOrderResp, nil
+}
diff --git a/register-order-service_test.go b/register-order-service_test.go
new file mode 100644
index 0000000..c8acc46
--- /dev/null
+++ b/register-order-service_test.go
@@ -0,0 +1,254 @@
+package cdek
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "reflect"
+ "testing"
+ "time"
+)
+
+func TestClient_RegisterOrder(t *testing.T) {
+ mockServer := registerOrderMockServer()
+ defer mockServer.Close()
+
+ mockServerWithValidError := registerOrderMockServerWithValidError()
+ defer mockServerWithValidError.Close()
+
+ mockServerWithError := registerOrderMockServerWithError()
+ defer mockServerWithError.Close()
+
+ type fields struct {
+ client Client
+ }
+ type args struct {
+ req RegisterOrderReq
+ }
+ testOrder := NewOrderReq("number-soOEl0", "name-soOEl0", "+79138739944", 139).
+ SetSendCityCode(44).
+ SetRecCityCode(44).
+ SetComment("comment-soOEl0").
+ SetDeliveryRecipientCost(0).
+ SetDeliveryRecipientVATRate("VATX").
+ SetDeliveryRecipientVATSum(0).
+ SetRecipientEmail("no-reply@cdek.ru").
+ SetAddress(*NewAddress("street-soOEl0", "house-soOEl0").
+ SetFlat("flat-soOEl0"),
+ ).
+ SetSender(*NewSender().
+ SetCompany("company-soOEl0").
+ SetName("Отправителев").
+ SetAddress(*NewAddress("street-soOEl0", "house-soOEl0").
+ SetFlat("flat-soOEl0"),
+ ).
+ AddPhone("+79138739946").
+ AddPhone("+79138739945"),
+ ).
+ SetSeller(*NewSeller().
+ SetAddress("street_soOEl0 1").
+ SetName("seller-soOEl0").
+ SetINN("111111111111").
+ SetPhone("+79138739947").
+ SetOwnershipForm(249),
+ ).
+ AddPackage(*NewOrderPackage("soOEl00", "barcode-soOEl00", 100).
+ SetSize(2, 3, 4).
+ AddItem(*NewOrderPackageItem(2, "warekey-soOEl000", 8, 10, 1, "comment-soOEl000").
+ SetPaymentVATRate("VATX").
+ SetPaymentVATSum(0),
+ ),
+ ).
+ SetDeliveryRecipientCostAdv(*NewDeliveryRecipientCostAdv(2000, 150).
+ SetVATRate("vat10").
+ SetVATSum(13.64),
+ ).
+ SetAddService(*NewAddService(30)).
+ SetSchedule(*NewSchedule().
+ AddAttempt(*NewScheduleAttempt("soOEl00", time.Date(2019, 7, 19, 12, 0, 0, 0, time.UTC)).
+ SetAddress(*NewAddress("street-prozvon_adr", "house-prozvon_adr").
+ SetFlat("flat-prozvon_adr"),
+ ).
+ SetTimeBeg("11:00:00").
+ SetTimeEnd("13:00:00"),
+ ),
+ )
+
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *RegisterOrderResp
+ wantErr bool
+ }{
+ {
+ name: "creation",
+ fields: fields{
+ client: Client{
+ apiURL: mockServer.URL,
+ },
+ },
+ args: args{
+ req: *NewDeliveryRequest("soOEl", 1, testOrder),
+ },
+ want: &RegisterOrderResp{
+ Order: []*OrderResp{
+ {
+ DispatchNumber: intLink(1105068300),
+ Number: strLink("number-soOEl0"),
+ },
+ {
+ Error: Error{
+ Msg: strLink("Добавлено заказов 1"),
+ },
+ },
+ },
+ Call: nil,
+ },
+ wantErr: false,
+ },
+ {
+ name: "handle valid error",
+ fields: fields{
+ client: Client{
+ apiURL: mockServerWithValidError.URL,
+ },
+ },
+ args: args{},
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "uncompilable url",
+ fields: fields{
+ client: Client{
+ apiURL: " wrong://url ",
+ },
+ },
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "wrong url",
+ fields: fields{
+ client: Client{
+ apiURL: "wrong://url",
+ },
+ },
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "server error",
+ fields: fields{
+ client: Client{
+ apiURL: mockServerWithError.URL,
+ },
+ },
+ want: nil,
+ wantErr: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ cl := tt.fields.client
+ got, err := cl.RegisterOrder(tt.args.req)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("Client.RegisterOrder() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Client.RegisterOrder() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func registerOrderMockServer() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _, _ = res.Write([]byte(`
+
+
+
+
+ 4770a74ae95c3d19
+
+ `))
+ }))
+}
+
+func registerOrderMockServerWithValidError() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _, _ = res.Write([]byte(`
+
+
+
+
+ d5f71d55d760b9b7
+
+ `))
+ }))
+}
+
+func registerOrderMockServerWithError() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _, _ = res.Write([]byte("err"))
+ }))
+}
+
+func ExampleClient_RegisterOrder() {
+ client := NewClient("https://integration.edu.cdek.ru/")
+ client.SetAuth("z9GRRu7FxmO53CQ9cFfI6qiy32wpfTkd", "w24JTCv4MnAcuRTx0oHjHLDtyt3I6IBq")
+
+ exampleOrder := NewOrderReq("number-soOEl0", "name-soOEl0", "+79138739944", 139).
+ SetSendCityCode(44).
+ SetRecCityCode(44).
+ SetComment("comment-soOEl0").
+ SetDeliveryRecipientCost(0).
+ SetDeliveryRecipientVATRate("VATX").
+ SetDeliveryRecipientVATSum(0).
+ SetRecipientEmail("no-reply@cdek.ru").
+ SetAddress(*NewAddress("street-soOEl0", "house-soOEl0").
+ SetFlat("flat-soOEl0"),
+ ).
+ SetSender(*NewSender().
+ SetCompany("company-soOEl0").
+ SetName("Отправителев").
+ SetAddress(*NewAddress("street-soOEl0", "house-soOEl0").
+ SetFlat("flat-soOEl0"),
+ ).
+ AddPhone("+79138739946").
+ AddPhone("+79138739945"),
+ ).
+ SetSeller(*NewSeller().
+ SetAddress("street_soOEl0 1").
+ SetName("seller-soOEl0").
+ SetINN("111111111111").
+ SetPhone("+79138739947").
+ SetOwnershipForm(249),
+ ).
+ AddPackage(*NewOrderPackage("soOEl00", "barcode-soOEl00", 100).
+ SetSize(2, 3, 4).
+ AddItem(*NewOrderPackageItem(2, "warekey-soOEl000", 8, 10, 1, "comment-soOEl000").
+ SetPaymentVATRate("VATX").
+ SetPaymentVATSum(0),
+ ),
+ ).
+ SetDeliveryRecipientCostAdv(*NewDeliveryRecipientCostAdv(2000, 150).
+ SetVATRate("vat10").
+ SetVATSum(13.64),
+ ).
+ SetAddService(*NewAddService(30)).
+ SetSchedule(*NewSchedule().
+ AddAttempt(*NewScheduleAttempt("soOEl00", time.Date(2019, 7, 19, 12, 0, 0, 0, time.UTC)).
+ SetAddress(*NewAddress("street-prozvon_adr", "house-prozvon_adr").
+ SetFlat("flat-prozvon_adr"),
+ ).
+ SetTimeBeg("11:00:00").
+ SetTimeEnd("13:00:00"),
+ ),
+ )
+
+ result, err := client.RegisterOrder(*NewDeliveryRequest("soOEl", 1, exampleOrder))
+
+ _, _ = result, err
+}
diff --git a/secure.go b/secure.go
new file mode 100644
index 0000000..7309ceb
--- /dev/null
+++ b/secure.go
@@ -0,0 +1,42 @@
+package cdek
+
+type securableXML struct {
+ Account *string `xml:"Account,attr"`
+ Date *string `xml:"Date,attr"`
+ Secure *string `xml:"Secure,attr"`
+}
+
+type securableJSON struct {
+ AuthLogin *string `json:"authLogin,omitempty"`
+ Secure *string `json:"secure,omitempty"`
+ DateExecute *string `json:"dateExecute,omitempty"`
+}
+
+//TODO: there are some methods that MUST HAVE auth, need to handle this case
+func (s *securableXML) setAuth(auth *auth) *securableXML {
+ if auth == nil {
+ return s
+ }
+
+ s.Account = &auth.account
+
+ date, sec := auth.encodedSecure()
+ s.Date = &date
+ s.Secure = &sec
+
+ return s
+}
+
+func (s *securableJSON) setAuth(auth *auth) *securableJSON {
+ if auth == nil {
+ return s
+ }
+
+ s.AuthLogin = &auth.account
+
+ date, sec := auth.encodedSecure()
+ s.DateExecute = &date
+ s.Secure = &sec
+
+ return s
+}
diff --git a/secure_test.go b/secure_test.go
new file mode 100644
index 0000000..029f92a
--- /dev/null
+++ b/secure_test.go
@@ -0,0 +1,123 @@
+package cdek
+
+import (
+ "crypto/md5"
+ "encoding/hex"
+ "reflect"
+ "testing"
+ "time"
+)
+
+func Test_securableJSON_setAuth(t *testing.T) {
+ now := time.Now().Format("2006-01-02")
+ encoder := md5.New()
+ _, _ = encoder.Write([]byte(now + "&" + "testSecure"))
+ testSecureEncoded := hex.EncodeToString(encoder.Sum(nil))
+
+ type fields struct {
+ AuthLogin *string
+ Secure *string
+ DateExecute *string
+ }
+ type args struct {
+ auth *auth
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *securableJSON
+ }{
+ {
+ name: "secure fields pass correct",
+ fields: fields{},
+ args: args{
+ auth: &auth{
+ account: "testAccount",
+ secure: "testSecure",
+ },
+ },
+ want: &securableJSON{
+ AuthLogin: strLink("testAccount"),
+ Secure: &testSecureEncoded,
+ DateExecute: &now,
+ },
+ },
+ {
+ name: "empty auth",
+ fields: fields{},
+ args: args{},
+ want: &securableJSON{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ s := &securableJSON{
+ AuthLogin: tt.fields.AuthLogin,
+ Secure: tt.fields.Secure,
+ DateExecute: tt.fields.DateExecute,
+ }
+ if got := s.setAuth(tt.args.auth); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("setAuth() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func Test_securableXML_setAuth(t *testing.T) {
+ testAccount := "testAccount"
+ testSecure := "testSecure"
+ now := time.Now().Format("2006-01-02")
+ encoder := md5.New()
+ _, _ = encoder.Write([]byte(now + "&" + testSecure))
+ testSecureEncoded := hex.EncodeToString(encoder.Sum(nil))
+
+ type fields struct {
+ Account *string
+ Date *string
+ Secure *string
+ }
+ type args struct {
+ auth *auth
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *securableXML
+ }{
+ {
+ name: "secure fields pass correct",
+ fields: fields{},
+ args: args{
+ auth: &auth{
+ account: testAccount,
+ secure: testSecure,
+ },
+ },
+ want: &securableXML{
+ Account: &testAccount,
+ Date: &now,
+ Secure: &testSecureEncoded,
+ },
+ },
+ {
+ name: "empty auth",
+ fields: fields{},
+ args: args{},
+ want: &securableXML{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ s := &securableXML{
+ Account: tt.fields.Account,
+ Date: tt.fields.Date,
+ Secure: tt.fields.Secure,
+ }
+ if got := s.setAuth(tt.args.auth); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("setAuth() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
diff --git a/status-report-models.go b/status-report-models.go
new file mode 100644
index 0000000..1f8cb63
--- /dev/null
+++ b/status-report-models.go
@@ -0,0 +1,162 @@
+package cdek
+
+//StatusReport Order Status Report request
+type StatusReport struct {
+ securableXML
+ ShowHistory *bool `xml:"ShowHistory,attr"`
+ ShowReturnOrder *bool `xml:"ShowReturnOrder,attr"`
+ ShowReturnOrderHistory *bool `xml:"ShowReturnOrderHistory,attr"`
+ ChangePeriod *ChangePeriod `xml:"ChangePeriod"`
+ Order []*StatusReportOrderReq `xml:"Order"`
+}
+
+//StatusReportResp Order Status Report response
+type StatusReportResp struct {
+ Error
+ StatusReport *StatusReportContentForResp `xml:"StatusReport"`
+ Order []*StatusReportOrderResp `xml:"Order"`
+ ReturnOrder []*ReturnOrder `xml:"ReturnOrder,omitempty"`
+}
+
+//ChangePeriod The period during which the order status has changed.
+type ChangePeriod struct {
+ DateFirst *string `xml:"DateFirst,attr"`
+ DateLast *string `xml:"DateLast,attr"`
+}
+
+//StatusReportOrderReq Shipment (order)
+type StatusReportOrderReq struct {
+ DispatchNumber *int `xml:"DispatchNumber,attr"`
+ Number *string `xml:"Number,attr"`
+ Date *string `xml:"Date,attr"`
+}
+
+//StatusReportContentForResp The period during which the order status has changed.
+type StatusReportContentForResp struct {
+ DateFirst *string `xml:"DateFirst,attr"`
+ DateLast *string `xml:"DateLast,attr"`
+}
+
+//StatusReportOrderResp Shipment (order)
+type StatusReportOrderResp struct {
+ ActNumber *string `xml:"ActNumber,attr"`
+ Number *string `xml:"Number,attr"`
+ DispatchNumber *string `xml:"DispatchNumber,attr"`
+ DeliveryDate *string `xml:"DeliveryDate,attr"`
+ RecipientName *string `xml:"RecipientName,attr"`
+ ReturnDispatchNumber *int `xml:"ReturnDispatchNumber,attr"`
+ Status *Status `xml:"Status"`
+ Reason *Reason `xml:"Reason"`
+ DelayReason *DelayReason `xml:"DelayReason"`
+ Package *Package `xml:"Package"`
+ Attempt *Attempt `xml:"Attempt,omitempty"`
+ Call *Call `xml:"Call"`
+}
+
+//Status Current order status
+type Status struct {
+ Date *string `xml:"Date,attr"`
+ Code *string `xml:"Code,attr"`
+ Description *string `xml:"Description,attr"`
+ CityCode *string `xml:"CityCode,attr"`
+ CityName *string `xml:"CityName,attr"`
+ State []*State `xml:"State"`
+}
+
+//State Status change history
+type State struct {
+ Date *string `xml:"Date,attr"`
+ Code *string `xml:"Code,attr"`
+ Description *string `xml:"Description,attr"`
+ CityCode *string `xml:"CityCode,attr,omitempty"`
+ CityName *string `xml:"CityName,attr,omitempty"`
+}
+
+//Reason Current additional status
+type Reason struct {
+ Date *string `xml:"Date,attr"`
+ Code *string `xml:"Code,attr"`
+ Description *string `xml:"Description,attr"`
+}
+
+//DelayReason Current delay reason
+type DelayReason struct {
+ Date *string `xml:"Date,attr"`
+ Code *string `xml:"Code,attr"`
+ Description *string `xml:"Description,attr"`
+ State []State `xml:"State"`
+}
+
+//Package Package
+type Package struct {
+ Number *string `xml:"Number,attr"`
+ BarCode *string `xml:"BarCode,attr"`
+ Item []*Item `xml:"Item"`
+}
+
+//Item Items
+type Item struct {
+ WareKey *string `xml:"WareKey,attr"`
+ Amount *string `xml:"Amount,attr"`
+ DelivAmount *string `xml:"DelivAmount,attr"`
+}
+
+//Attempt Delivery time taken from the delivery schedule
+type Attempt struct {
+ ID *int `xml:"ID,attr"`
+ ScheduleCode *int `xml:"ScheduleCode,attr"`
+ ScheduleDescription *string `xml:"ScheduleDescription,attr"`
+}
+
+//Call History of notification calls to the receiver
+type Call struct {
+ CallGood *CallGood `xml:"CallGood"`
+ CallFail *CallFail `xml:"CallFail"`
+ CallDelay *CallDelay `xml:"CallDelay"`
+}
+
+//CallGood History of successful calls
+type CallGood struct {
+ Good []*CallGoodItem `xml:"Good"`
+}
+
+//CallGoodItem Successful call
+type CallGoodItem struct {
+ Date *string `xml:"Date,attr"`
+ DateDeliv *string `xml:"DateDeliv,attr"`
+}
+
+//CallFail History of failed calls
+type CallFail struct {
+ Fail []*CallFailItem `xml:"Fail"`
+}
+
+//CallFailItem Failed call
+type CallFailItem struct {
+ Date *string `xml:"Date,attr"`
+ ReasonCode *string `xml:"ReasonCode,attr"`
+ ReasonDescription *string `xml:"ReasonDescription,attr"`
+}
+
+//CallDelay History of call reschedules
+type CallDelay struct {
+ Delay []*CallDelayItem `xml:"Delay"`
+}
+
+//CallDelayItem Call reschedule
+type CallDelayItem struct {
+ Date *string `xml:"Date,attr"`
+ DateNext *string `xml:"DateNext,attr"`
+}
+
+//ReturnOrder Return shipment
+type ReturnOrder struct {
+ ActNumber *string `xml:"ActNumber,attr"`
+ Number *string `xml:"Number,attr"`
+ DispatchNumber *int `xml:"DispatchNumber,attr"`
+ DeliveryDate *string `xml:"DeliveryDate,attr"`
+ RecipientName *string `xml:"RecipientName,attr"`
+ Status *Status `xml:"Status"`
+ Reason *Reason `xml:"Reason"`
+ DelayReason *DelayReason `xml:"DelayReason"`
+}
diff --git a/status-report-req-builder.go b/status-report-req-builder.go
new file mode 100644
index 0000000..71c8037
--- /dev/null
+++ b/status-report-req-builder.go
@@ -0,0 +1,75 @@
+package cdek
+
+import "time"
+
+//NewStatusReportReq Order Status Report builder
+func NewStatusReportReq() *StatusReport {
+ return new(StatusReport)
+}
+
+//SetShowHistory The attribute indicating that the order history must be loaded (1 – yes, 0 – no)
+func (req *StatusReport) SetShowHistory(showHistory bool) *StatusReport {
+ req.ShowHistory = &showHistory
+
+ return req
+}
+
+//SetShowReturnOrder The attribute indicating that the list of return orders must be loaded (1 – yes, 0 – no)
+func (req *StatusReport) SetShowReturnOrder(showReturnOrder bool) *StatusReport {
+ req.ShowReturnOrder = &showReturnOrder
+
+ return req
+}
+
+//SetShowReturnOrderHistory The attribute indicating that the history of return orders must be loaded (1 – yes, 0 – no)
+func (req *StatusReport) SetShowReturnOrderHistory(showReturnOrderHistory bool) *StatusReport {
+ req.ShowReturnOrderHistory = &showReturnOrderHistory
+
+ return req
+}
+
+//SetChangePeriod The period during which the order status has changed.
+func (req *StatusReport) SetChangePeriod(changePeriod ChangePeriod) *StatusReport {
+ req.ChangePeriod = &changePeriod
+
+ return req
+}
+
+//AddOrder Add Shipment (order)
+func (req *StatusReport) AddOrder(order StatusReportOrderReq) *StatusReport {
+ req.Order = append(req.Order, &order)
+
+ return req
+}
+
+//NewChangePeriod ChangePeriod builder
+// dateFirst: start date of requested period
+func NewChangePeriod(dateFirst time.Time) *ChangePeriod {
+ dateFirstFormatted := dateFirst.Format("2006-01-02")
+
+ return &ChangePeriod{
+ DateFirst: &dateFirstFormatted,
+ }
+}
+
+//SetDateLast End date of requested period
+func (changePeriod *ChangePeriod) SetDateLast(date time.Time) *ChangePeriod {
+ dateFormatted := date.Format("2006-01-02")
+ changePeriod.DateLast = &dateFormatted
+
+ return changePeriod
+}
+
+//NewStatusReportOrderReq StatusReportOrderReq builder
+// dispatchNumber: CDEK shipment number (assigned when orders are imported). Order identifier in the CDEK IS.
+// number: Client's shipment number. Order identifier in the IS of the CDEK Client.
+// date: Date of an acceptance certificate, based on which the order has been transferred.
+func NewStatusReportOrderReq(dispatchNumber int, number string, date time.Time) *StatusReportOrderReq {
+ dateFormatted := date.Format("2006-01-02")
+
+ return &StatusReportOrderReq{
+ DispatchNumber: &dispatchNumber,
+ Number: &number,
+ Date: &dateFormatted,
+ }
+}
diff --git a/status-report-req-builder_test.go b/status-report-req-builder_test.go
new file mode 100644
index 0000000..205ca29
--- /dev/null
+++ b/status-report-req-builder_test.go
@@ -0,0 +1,505 @@
+package cdek
+
+import (
+ "encoding/json"
+ "reflect"
+ "testing"
+ "time"
+)
+
+func TestNewStatusReportReq(t *testing.T) {
+ tests := []struct {
+ name string
+ want *StatusReport
+ }{
+ {
+ name: "constructor",
+ want: &StatusReport{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewStatusReportReq(); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewStatusReportReq() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestStatusReportReq_SetShowHistory(t *testing.T) {
+ type fields struct {
+ ShowHistory *bool
+ ShowReturnOrder *bool
+ ShowReturnOrderHistory *bool
+ ChangePeriod *ChangePeriod
+ Order []*StatusReportOrderReq
+ }
+ type args struct {
+ showHistory bool
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *StatusReport
+ }{
+ {
+ name: "set",
+ fields: fields{
+ ShowHistory: nil,
+ ShowReturnOrder: boolLink(true),
+ },
+ args: args{
+ showHistory: true,
+ },
+ want: &StatusReport{
+ ShowHistory: boolLink(true),
+ ShowReturnOrder: boolLink(true),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ ShowHistory: boolLink(true),
+ ShowReturnOrder: boolLink(true),
+ },
+ args: args{
+ showHistory: false,
+ },
+ want: &StatusReport{
+ ShowHistory: boolLink(false),
+ ShowReturnOrder: boolLink(true),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ req := &StatusReport{
+ ShowHistory: tt.fields.ShowHistory,
+ ShowReturnOrder: tt.fields.ShowReturnOrder,
+ ShowReturnOrderHistory: tt.fields.ShowReturnOrderHistory,
+ ChangePeriod: tt.fields.ChangePeriod,
+ Order: tt.fields.Order,
+ }
+ if got := req.SetShowHistory(tt.args.showHistory); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("StatusReport.SetShowHistory() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestStatusReportReq_SetShowReturnOrder(t *testing.T) {
+ type fields struct {
+ ShowHistory *bool
+ ShowReturnOrder *bool
+ ShowReturnOrderHistory *bool
+ ChangePeriod *ChangePeriod
+ Order []*StatusReportOrderReq
+ }
+ type args struct {
+ showReturnOrder bool
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *StatusReport
+ }{
+ {
+ name: "set",
+ fields: fields{
+ ShowHistory: boolLink(true),
+ ShowReturnOrder: nil,
+ },
+ args: args{
+ showReturnOrder: true,
+ },
+ want: &StatusReport{
+ ShowHistory: boolLink(true),
+ ShowReturnOrder: boolLink(true),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ ShowHistory: boolLink(true),
+ ShowReturnOrder: boolLink(true),
+ },
+ args: args{
+ showReturnOrder: false,
+ },
+ want: &StatusReport{
+ ShowHistory: boolLink(true),
+ ShowReturnOrder: boolLink(false),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ req := &StatusReport{
+ ShowHistory: tt.fields.ShowHistory,
+ ShowReturnOrder: tt.fields.ShowReturnOrder,
+ ShowReturnOrderHistory: tt.fields.ShowReturnOrderHistory,
+ ChangePeriod: tt.fields.ChangePeriod,
+ Order: tt.fields.Order,
+ }
+ if got := req.SetShowReturnOrder(tt.args.showReturnOrder); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("StatusReport.SetShowReturnOrder() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestStatusReportReq_SetShowReturnOrderHistory(t *testing.T) {
+ type fields struct {
+ ShowHistory *bool
+ ShowReturnOrder *bool
+ ShowReturnOrderHistory *bool
+ ChangePeriod *ChangePeriod
+ Order []*StatusReportOrderReq
+ }
+ type args struct {
+ showReturnOrderHistory bool
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *StatusReport
+ }{
+ {
+ name: "set",
+ fields: fields{
+ ShowHistory: boolLink(true),
+ ShowReturnOrderHistory: nil,
+ },
+ args: args{
+ showReturnOrderHistory: true,
+ },
+ want: &StatusReport{
+ ShowHistory: boolLink(true),
+ ShowReturnOrderHistory: boolLink(true),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ ShowHistory: boolLink(true),
+ ShowReturnOrderHistory: boolLink(true),
+ },
+ args: args{
+ showReturnOrderHistory: false,
+ },
+ want: &StatusReport{
+ ShowHistory: boolLink(true),
+ ShowReturnOrderHistory: boolLink(false),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ req := &StatusReport{
+ ShowHistory: tt.fields.ShowHistory,
+ ShowReturnOrder: tt.fields.ShowReturnOrder,
+ ShowReturnOrderHistory: tt.fields.ShowReturnOrderHistory,
+ ChangePeriod: tt.fields.ChangePeriod,
+ Order: tt.fields.Order,
+ }
+ if got := req.SetShowReturnOrderHistory(tt.args.showReturnOrderHistory); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("StatusReport.SetShowReturnOrderHistory() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestStatusReportReq_SetChangePeriod(t *testing.T) {
+ type fields struct {
+ ShowHistory *bool
+ ShowReturnOrder *bool
+ ShowReturnOrderHistory *bool
+ ChangePeriod *ChangePeriod
+ Order []*StatusReportOrderReq
+ }
+ type args struct {
+ changePeriod ChangePeriod
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *StatusReport
+ }{
+ {
+ name: "set",
+ fields: fields{
+ ShowHistory: boolLink(true),
+ ChangePeriod: nil,
+ },
+ args: args{
+ changePeriod: ChangePeriod{
+ DateFirst: strLink("2019-07-15"),
+ DateLast: strLink("2019-07-16"),
+ },
+ },
+ want: &StatusReport{
+ ShowHistory: boolLink(true),
+ ChangePeriod: &ChangePeriod{
+ DateFirst: strLink("2019-07-15"),
+ DateLast: strLink("2019-07-16"),
+ },
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ ShowHistory: boolLink(true),
+ ChangePeriod: &ChangePeriod{
+ DateFirst: strLink("2019-07-15"),
+ DateLast: strLink("2019-07-16"),
+ },
+ },
+ args: args{
+ changePeriod: ChangePeriod{
+ DateFirst: strLink("2019-07-16"),
+ DateLast: strLink("2019-07-17"),
+ },
+ },
+ want: &StatusReport{
+ ShowHistory: boolLink(true),
+ ChangePeriod: &ChangePeriod{
+ DateFirst: strLink("2019-07-16"),
+ DateLast: strLink("2019-07-17"),
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ req := &StatusReport{
+ ShowHistory: tt.fields.ShowHistory,
+ ShowReturnOrder: tt.fields.ShowReturnOrder,
+ ShowReturnOrderHistory: tt.fields.ShowReturnOrderHistory,
+ ChangePeriod: tt.fields.ChangePeriod,
+ Order: tt.fields.Order,
+ }
+ if got := req.SetChangePeriod(tt.args.changePeriod); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("StatusReport.SetChangePeriod() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestStatusReportReq_AddOrder(t *testing.T) {
+ type fields struct {
+ ShowHistory *bool
+ ShowReturnOrder *bool
+ ShowReturnOrderHistory *bool
+ ChangePeriod *ChangePeriod
+ Order []*StatusReportOrderReq
+ }
+ type args struct {
+ order StatusReportOrderReq
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *StatusReport
+ }{
+ {
+ name: "add first",
+ fields: fields{
+ ShowHistory: boolLink(true),
+ Order: nil,
+ },
+ args: args{
+ order: StatusReportOrderReq{
+ DispatchNumber: intLink(1),
+ Number: strLink("test_number"),
+ Date: strLink("2019-07-15"),
+ },
+ },
+ want: &StatusReport{
+ ShowHistory: boolLink(true),
+ Order: []*StatusReportOrderReq{
+ {
+ DispatchNumber: intLink(1),
+ Number: strLink("test_number"),
+ Date: strLink("2019-07-15"),
+ },
+ },
+ },
+ },
+ {
+ name: "add second",
+ fields: fields{
+ ShowHistory: boolLink(true),
+ Order: []*StatusReportOrderReq{
+ {
+ DispatchNumber: intLink(1),
+ Number: strLink("test_number"),
+ Date: strLink("2019-07-15"),
+ },
+ },
+ },
+ args: args{
+ order: StatusReportOrderReq{
+ DispatchNumber: intLink(2),
+ Number: strLink("test_number_2"),
+ Date: strLink("2019-07-16"),
+ },
+ },
+ want: &StatusReport{
+ ShowHistory: boolLink(true),
+ Order: []*StatusReportOrderReq{
+ {
+ DispatchNumber: intLink(1),
+ Number: strLink("test_number"),
+ Date: strLink("2019-07-15"),
+ },
+ {
+ DispatchNumber: intLink(2),
+ Number: strLink("test_number_2"),
+ Date: strLink("2019-07-16"),
+ },
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ req := &StatusReport{
+ ShowHistory: tt.fields.ShowHistory,
+ ShowReturnOrder: tt.fields.ShowReturnOrder,
+ ShowReturnOrderHistory: tt.fields.ShowReturnOrderHistory,
+ ChangePeriod: tt.fields.ChangePeriod,
+ Order: tt.fields.Order,
+ }
+ if got := req.AddOrder(tt.args.order); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("StatusReport.AddOrder() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNewChangePeriod(t *testing.T) {
+ type args struct {
+ dateFirst time.Time
+ }
+
+ tests := []struct {
+ name string
+ args args
+ want *ChangePeriod
+ }{
+ {
+ name: "constructor",
+ args: args{
+ dateFirst: time.Date(2019, 7, 15, 0, 0, 0, 0, time.UTC),
+ },
+ want: &ChangePeriod{
+ DateFirst: strLink("2019-07-15"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewChangePeriod(tt.args.dateFirst); !reflect.DeepEqual(got, tt.want) {
+ g, _ := json.Marshal(got)
+ w, _ := json.Marshal(tt.want)
+ t.Errorf("NewChangePeriod() = %v, want %v", string(g), string(w))
+ }
+ })
+ }
+}
+
+func TestChangePeriod_SetDateLast(t *testing.T) {
+ type fields struct {
+ DateFirst *string
+ DateLast *string
+ }
+ type args struct {
+ date time.Time
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *ChangePeriod
+ }{
+ {
+ name: "set",
+ fields: fields{
+ DateFirst: strLink("2019-07-15"),
+ DateLast: nil,
+ },
+ args: args{
+ date: time.Date(2019, 7, 16, 0, 0, 0, 0, time.UTC),
+ },
+ want: &ChangePeriod{
+ DateFirst: strLink("2019-07-15"),
+ DateLast: strLink("2019-07-16"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ DateFirst: strLink("2019-07-15"),
+ DateLast: strLink("2019-07-16"),
+ },
+ args: args{
+ date: time.Date(2019, 7, 17, 0, 0, 0, 0, time.UTC),
+ },
+ want: &ChangePeriod{
+ DateFirst: strLink("2019-07-15"),
+ DateLast: strLink("2019-07-17"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ changePeriod := &ChangePeriod{
+ DateFirst: tt.fields.DateFirst,
+ DateLast: tt.fields.DateLast,
+ }
+ if got := changePeriod.SetDateLast(tt.args.date); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("ChangePeriod.SetDateLast() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNewStatusReportOrderReq(t *testing.T) {
+ type args struct {
+ dispatchNumber int
+ number string
+ date time.Time
+ }
+ tests := []struct {
+ name string
+ args args
+ want *StatusReportOrderReq
+ }{
+ {
+ name: "constructor",
+ args: args{
+ dispatchNumber: 1,
+ number: "test_number",
+ date: time.Date(2019, 7, 15, 0, 0, 0, 0, time.UTC),
+ },
+ want: &StatusReportOrderReq{
+ DispatchNumber: intLink(1),
+ Number: strLink("test_number"),
+ Date: strLink("2019-07-15"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := NewStatusReportOrderReq(tt.args.dispatchNumber, tt.args.number, tt.args.date)
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewStatusReportOrderReq() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
diff --git a/status-report-service.go b/status-report-service.go
new file mode 100644
index 0000000..3fedc70
--- /dev/null
+++ b/status-report-service.go
@@ -0,0 +1,51 @@
+package cdek
+
+import (
+ "bytes"
+ "encoding/xml"
+ "io/ioutil"
+ "net/http"
+ "net/url"
+ "path"
+)
+
+const statusReportURL = "/status_report_h.php"
+
+//GetStatusReport This method is used to generate an order status report, including order change history.
+func (c Client) GetStatusReport(statusReportReq StatusReport) (*StatusReportResp, error) {
+ statusReportReq.setAuth(c.auth)
+ reqByte, err := xml.Marshal(statusReportReq)
+ if err != nil {
+ return nil, err
+ }
+
+ serverURL, err := url.Parse(c.apiURL)
+ if err != nil {
+ return nil, err
+ }
+
+ serverURL.Path = path.Join(serverURL.Path, statusReportURL)
+ reqURL := serverURL.String()
+
+ resp, err := http.Post(reqURL, xmlContentType, bytes.NewReader(reqByte))
+ if err != nil {
+ return nil, err
+ }
+
+ defer func() {
+ _ = resp.Body.Close()
+ }()
+
+ body, _ := ioutil.ReadAll(resp.Body)
+
+ var statusReportResp StatusReportResp
+ err = xml.Unmarshal(body, &statusReportResp)
+ if err != nil {
+ return nil, err
+ }
+ if statusReportResp.IsErroneous() {
+ return nil, statusReportResp.Error
+ }
+
+ return &statusReportResp, nil
+}
diff --git a/status-report-service_test.go b/status-report-service_test.go
new file mode 100644
index 0000000..7c55b38
--- /dev/null
+++ b/status-report-service_test.go
@@ -0,0 +1,147 @@
+package cdek
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "reflect"
+ "testing"
+)
+
+func TestClient_GetStatusReport(t *testing.T) {
+ mockServer := getStatusReportMockServer()
+ defer mockServer.Close()
+
+ mockServerWithValidError := getStatusReportMockServerWithValidError()
+ defer mockServerWithValidError.Close()
+
+ mockServerWithError := getStatusReportMockServerWithError()
+ defer mockServerWithError.Close()
+
+ type fields struct {
+ client Client
+ }
+ type args struct {
+ statusReportReq StatusReport
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *StatusReportResp
+ wantErr bool
+ }{
+ {
+ name: "handle response",
+ fields: fields{
+ client: Client{
+ apiURL: mockServer.URL,
+ },
+ },
+ args: args{
+ statusReportReq: StatusReport{
+ ShowHistory: boolLink(true),
+ Order: []*StatusReportOrderReq{
+ {
+ DispatchNumber: intLink(1105256461),
+ },
+ },
+ },
+ },
+ // TODO: wait for the CDEK technical support answer and finish the test
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "handle valid error",
+ fields: fields{
+ client: Client{
+ apiURL: mockServerWithValidError.URL,
+ },
+ },
+ args: args{
+ statusReportReq: StatusReport{
+ ShowHistory: boolLink(true),
+ ChangePeriod: &ChangePeriod{
+ DateFirst: strLink("14-07-2019"),
+ },
+ },
+ },
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "uncompilable url",
+ fields: fields{
+ client: Client{
+ apiURL: " wrong://url ",
+ },
+ },
+ args: args{
+ statusReportReq: StatusReport{},
+ },
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "wrong url",
+ fields: fields{
+ client: Client{
+ apiURL: "wrong://url",
+ },
+ },
+ args: args{
+ statusReportReq: StatusReport{},
+ },
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "server error",
+ fields: fields{
+ client: Client{
+ apiURL: mockServerWithError.URL,
+ },
+ },
+ args: args{
+ statusReportReq: StatusReport{},
+ },
+ want: nil,
+ wantErr: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ cl := tt.fields.client
+ got, err := cl.GetStatusReport(tt.args.statusReportReq)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("Client.GetStatusReport() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Client.GetStatusReport() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func getStatusReportMockServer() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ // TODO: wait for the CDEK technical support answer and finish the test
+ _, _ = res.Write([]byte(``))
+ }))
+}
+
+func getStatusReportMockServerWithValidError() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _, _ = res.Write([]byte(`
+
+
+ `))
+ }))
+}
+
+func getStatusReportMockServerWithError() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _, _ = res.Write([]byte("err"))
+ }))
+}
diff --git a/test-helper.go b/test-helper.go
new file mode 100644
index 0000000..d9de866
--- /dev/null
+++ b/test-helper.go
@@ -0,0 +1,17 @@
+package cdek
+
+func strLink(s string) *string {
+ return &s
+}
+
+func intLink(i int) *int {
+ return &i
+}
+
+func float64Link(f float64) *float64 {
+ return &f
+}
+
+func boolLink(b bool) *bool {
+ return &b
+}
diff --git a/update-order-models.go b/update-order-models.go
new file mode 100644
index 0000000..ab41a78
--- /dev/null
+++ b/update-order-models.go
@@ -0,0 +1,34 @@
+package cdek
+
+import "encoding/xml"
+
+//UpdateOrderReq Order Change request structure
+type UpdateOrderReq struct {
+ securableXML
+ XMLName xml.Name `xml:"UpdateRequest"`
+ Number *string `xml:"Number,attr"`
+ OrderCount *int `xml:"OrderCount,attr"`
+ Order *UpdateOrder `xml:"Order"`
+}
+
+//UpdateOrder Order Change request
+type UpdateOrder struct {
+ Number *string `xml:"Number,attr"`
+ DispatchNumber *int `xml:"DispatchNumber,attr"`
+ DeliveryRecipientCost *float64 `xml:"DeliveryRecipientCost,attr"`
+ DeliveryRecipientVATRate *string `xml:"DeliveryRecipientVATRate,attr"`
+ DeliveryRecipientVATSum *float64 `xml:"DeliveryRecipientVATSum,attr"`
+ RecipientName *string `xml:"RecipientName,attr"`
+ Phone *string `xml:"Phone,attr"`
+ RecipientINN *string `xml:"RecipientINN,attr"`
+ DateInvoice *string `xml:"DateInvoice,attr"`
+ Passport *Passport `xml:"Passport"`
+ Address *Address `xml:"Address"`
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv `xml:"DeliveryRecipientCostAdv"`
+ Package *OrderPackage `xml:"Package"`
+}
+
+//UpdateOrderResp Order Change response
+type UpdateOrderResp struct {
+ Order []*OrderResp `xml:"Order"`
+}
diff --git a/update-order-req-builder.go b/update-order-req-builder.go
new file mode 100644
index 0000000..020cd23
--- /dev/null
+++ b/update-order-req-builder.go
@@ -0,0 +1,107 @@
+package cdek
+
+//NewUpdateOrderReq UpdateOrderReq builder
+func NewUpdateOrderReq(number string, orderCount int, order UpdateOrder) *UpdateOrderReq {
+ return &UpdateOrderReq{
+ Number: &number,
+ OrderCount: &orderCount,
+ Order: &order,
+ }
+}
+
+//NewUpdateOrder UpdateOrder builder
+func NewUpdateOrder() *UpdateOrder {
+ return new(UpdateOrder)
+}
+
+//SetNumber Client shipment number (unique for orders of a particular Client). Order identifier in the Client's IS.
+func (updateOrder *UpdateOrder) SetNumber(number string) *UpdateOrder {
+ updateOrder.Number = &number
+
+ return updateOrder
+}
+
+//SetDispatchNumber CDEK order number
+func (updateOrder *UpdateOrder) SetDispatchNumber(dispatchNumber int) *UpdateOrder {
+ updateOrder.DispatchNumber = &dispatchNumber
+
+ return updateOrder
+}
+
+//SetDeliveryRecipientCost Additional delivery charge collected by the online store from the receiver
+// (in the specified currency)
+func (updateOrder *UpdateOrder) SetDeliveryRecipientCost(deliveryRecipientCost float64) *UpdateOrder {
+ updateOrder.DeliveryRecipientCost = &deliveryRecipientCost
+
+ return updateOrder
+}
+
+//SetDeliveryRecipientVATRate VAT rate included in the extra delivery charge
+func (updateOrder *UpdateOrder) SetDeliveryRecipientVATRate(deliveryRecipientVATRate string) *UpdateOrder {
+ updateOrder.DeliveryRecipientVATRate = &deliveryRecipientVATRate
+
+ return updateOrder
+}
+
+//SetDeliveryRecipientVATSum VAT amount included in the extra. delivery charge
+func (updateOrder *UpdateOrder) SetDeliveryRecipientVATSum(deliveryRecipientVATSum float64) *UpdateOrder {
+ updateOrder.DeliveryRecipientVATSum = &deliveryRecipientVATSum
+
+ return updateOrder
+}
+
+//SetRecipientName Receiver (full name). At least 3 characters.
+func (updateOrder *UpdateOrder) SetRecipientName(recipientName string) *UpdateOrder {
+ updateOrder.RecipientName = &recipientName
+
+ return updateOrder
+}
+
+//SetPhone Receiver's phone
+func (updateOrder *UpdateOrder) SetPhone(phone string) *UpdateOrder {
+ updateOrder.Phone = &phone
+
+ return updateOrder
+}
+
+//SetRecipientINN TIN of the receiver. Only for international orders.
+func (updateOrder *UpdateOrder) SetRecipientINN(recipientINN string) *UpdateOrder {
+ updateOrder.RecipientINN = &recipientINN
+
+ return updateOrder
+}
+
+//SetDateInvoice Invoice date. Only for international orders.
+func (updateOrder *UpdateOrder) SetDateInvoice(dateInvoice string) *UpdateOrder {
+ updateOrder.DateInvoice = &dateInvoice
+
+ return updateOrder
+}
+
+//SetPassport Details of the receiver’s passport.
+func (updateOrder *UpdateOrder) SetPassport(passport Passport) *UpdateOrder {
+ updateOrder.Passport = &passport
+
+ return updateOrder
+}
+
+//SetAddress Delivery address.
+func (updateOrder *UpdateOrder) SetAddress(address Address) *UpdateOrder {
+ updateOrder.Address = &address
+
+ return updateOrder
+}
+
+//SetDeliveryRecipientCostAdv Additional charge for delivery
+func (updateOrder *UpdateOrder) SetDeliveryRecipientCostAdv(v DeliveryRecipientCostAdv) *UpdateOrder {
+ updateOrder.DeliveryRecipientCostAdv = &v
+
+ return updateOrder
+}
+
+//SetPackage Package
+func (updateOrder *UpdateOrder) SetPackage(pack OrderPackage) *UpdateOrder {
+ updateOrder.Package = &pack
+
+ return updateOrder
+}
diff --git a/update-order-req-builder_test.go b/update-order-req-builder_test.go
new file mode 100644
index 0000000..51e14ff
--- /dev/null
+++ b/update-order-req-builder_test.go
@@ -0,0 +1,1082 @@
+package cdek
+
+import (
+ "reflect"
+ "testing"
+)
+
+func TestNewUpdateOrderReq(t *testing.T) {
+ type args struct {
+ number string
+ orderCount int
+ order UpdateOrder
+ }
+ tests := []struct {
+ name string
+ args args
+ want *UpdateOrderReq
+ }{
+ {
+ name: "constructor",
+ args: args{
+ number: "test_number",
+ orderCount: 1,
+ order: UpdateOrder{},
+ },
+ want: &UpdateOrderReq{
+ Number: strLink("test_number"),
+ OrderCount: intLink(1),
+ Order: &UpdateOrder{},
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewUpdateOrderReq(tt.args.number, tt.args.orderCount, tt.args.order); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewUpdateOrderReq() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNewUpdateOrder(t *testing.T) {
+ tests := []struct {
+ name string
+ want *UpdateOrder
+ }{
+ {
+ name: "constructor",
+ want: &UpdateOrder{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewUpdateOrder(); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewUpdateOrder() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestUpdateOrder_SetNumber(t *testing.T) {
+ type fields struct {
+ Number *string
+ DispatchNumber *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientName *string
+ Phone *string
+ RecipientINN *string
+ DateInvoice *string
+ Passport *Passport
+ Address *Address
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ Package *OrderPackage
+ }
+ type args struct {
+ number string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *UpdateOrder
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Number: nil,
+ },
+ args: args{
+ number: "test_number",
+ },
+ want: &UpdateOrder{
+ Number: strLink("test_number"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Number: strLink("previous_number"),
+ },
+ args: args{
+ number: "test_number",
+ },
+ want: &UpdateOrder{
+ Number: strLink("test_number"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ updateOrder := &UpdateOrder{
+ Number: tt.fields.Number,
+ DispatchNumber: tt.fields.DispatchNumber,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientName: tt.fields.RecipientName,
+ Phone: tt.fields.Phone,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ Passport: tt.fields.Passport,
+ Address: tt.fields.Address,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ Package: tt.fields.Package,
+ }
+ if got := updateOrder.SetNumber(tt.args.number); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("UpdateOrder.SetNumber() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestUpdateOrder_SetDispatchNumber(t *testing.T) {
+ type fields struct {
+ Number *string
+ DispatchNumber *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientName *string
+ Phone *string
+ RecipientINN *string
+ DateInvoice *string
+ Passport *Passport
+ Address *Address
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ Package *OrderPackage
+ }
+ type args struct {
+ dispatchNumber int
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *UpdateOrder
+ }{
+ {
+ name: "set",
+ fields: fields{
+ DispatchNumber: nil,
+ },
+ args: args{
+ dispatchNumber: 183727812,
+ },
+ want: &UpdateOrder{
+ DispatchNumber: intLink(183727812),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ DispatchNumber: intLink(473623423),
+ },
+ args: args{
+ dispatchNumber: 183727812,
+ },
+ want: &UpdateOrder{
+ DispatchNumber: intLink(183727812),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ updateOrder := &UpdateOrder{
+ Number: tt.fields.Number,
+ DispatchNumber: tt.fields.DispatchNumber,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientName: tt.fields.RecipientName,
+ Phone: tt.fields.Phone,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ Passport: tt.fields.Passport,
+ Address: tt.fields.Address,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ Package: tt.fields.Package,
+ }
+ if got := updateOrder.SetDispatchNumber(tt.args.dispatchNumber); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("UpdateOrder.SetDispatchNumber() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestUpdateOrder_SetDeliveryRecipientCost(t *testing.T) {
+ type fields struct {
+ Number *string
+ DispatchNumber *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientName *string
+ Phone *string
+ RecipientINN *string
+ DateInvoice *string
+ Passport *Passport
+ Address *Address
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ Package *OrderPackage
+ }
+ type args struct {
+ deliveryRecipientCost float64
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *UpdateOrder
+ }{
+ {
+ name: "set",
+ fields: fields{
+ DeliveryRecipientCost: nil,
+ },
+ args: args{
+ deliveryRecipientCost: 188.99,
+ },
+ want: &UpdateOrder{
+ DeliveryRecipientCost: float64Link(188.99),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ DeliveryRecipientCost: float64Link(1773.99),
+ },
+ args: args{
+ deliveryRecipientCost: 188.99,
+ },
+ want: &UpdateOrder{
+ DeliveryRecipientCost: float64Link(188.99),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ updateOrder := &UpdateOrder{
+ Number: tt.fields.Number,
+ DispatchNumber: tt.fields.DispatchNumber,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientName: tt.fields.RecipientName,
+ Phone: tt.fields.Phone,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ Passport: tt.fields.Passport,
+ Address: tt.fields.Address,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ Package: tt.fields.Package,
+ }
+ if got := updateOrder.SetDeliveryRecipientCost(tt.args.deliveryRecipientCost); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("UpdateOrder.SetDeliveryRecipientCost() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestUpdateOrder_SetDeliveryRecipientVATRate(t *testing.T) {
+ type fields struct {
+ Number *string
+ DispatchNumber *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientName *string
+ Phone *string
+ RecipientINN *string
+ DateInvoice *string
+ Passport *Passport
+ Address *Address
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ Package *OrderPackage
+ }
+ type args struct {
+ deliveryRecipientVATRate string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *UpdateOrder
+ }{
+ {
+ name: "set",
+ fields: fields{
+ DeliveryRecipientVATRate: nil,
+ },
+ args: args{
+ deliveryRecipientVATRate: "VATX",
+ },
+ want: &UpdateOrder{
+ DeliveryRecipientVATRate: strLink("VATX"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ DeliveryRecipientVATRate: strLink("VATY"),
+ },
+ args: args{
+ deliveryRecipientVATRate: "VATX",
+ },
+ want: &UpdateOrder{
+ DeliveryRecipientVATRate: strLink("VATX"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ updateOrder := &UpdateOrder{
+ Number: tt.fields.Number,
+ DispatchNumber: tt.fields.DispatchNumber,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientName: tt.fields.RecipientName,
+ Phone: tt.fields.Phone,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ Passport: tt.fields.Passport,
+ Address: tt.fields.Address,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ Package: tt.fields.Package,
+ }
+ got := updateOrder.SetDeliveryRecipientVATRate(tt.args.deliveryRecipientVATRate)
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("UpdateOrder.SetDeliveryRecipientVATRate() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestUpdateOrder_SetDeliveryRecipientVATSum(t *testing.T) {
+ type fields struct {
+ Number *string
+ DispatchNumber *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientName *string
+ Phone *string
+ RecipientINN *string
+ DateInvoice *string
+ Passport *Passport
+ Address *Address
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ Package *OrderPackage
+ }
+ type args struct {
+ deliveryRecipientVATSum float64
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *UpdateOrder
+ }{
+ {
+ name: "set",
+ fields: fields{
+ DeliveryRecipientVATSum: nil,
+ },
+ args: args{
+ deliveryRecipientVATSum: 88.99,
+ },
+ want: &UpdateOrder{
+ DeliveryRecipientVATSum: float64Link(88.99),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ DeliveryRecipientVATSum: float64Link(73.99),
+ },
+ args: args{
+ deliveryRecipientVATSum: 88.99,
+ },
+ want: &UpdateOrder{
+ DeliveryRecipientVATSum: float64Link(88.99),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ updateOrder := &UpdateOrder{
+ Number: tt.fields.Number,
+ DispatchNumber: tt.fields.DispatchNumber,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientName: tt.fields.RecipientName,
+ Phone: tt.fields.Phone,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ Passport: tt.fields.Passport,
+ Address: tt.fields.Address,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ Package: tt.fields.Package,
+ }
+ if got := updateOrder.SetDeliveryRecipientVATSum(tt.args.deliveryRecipientVATSum); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("UpdateOrder.SetDeliveryRecipientVATSum() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestUpdateOrder_SetRecipientName(t *testing.T) {
+ type fields struct {
+ Number *string
+ DispatchNumber *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientName *string
+ Phone *string
+ RecipientINN *string
+ DateInvoice *string
+ Passport *Passport
+ Address *Address
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ Package *OrderPackage
+ }
+ type args struct {
+ recipientName string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *UpdateOrder
+ }{
+ {
+ name: "set",
+ fields: fields{
+ RecipientName: nil,
+ },
+ args: args{
+ recipientName: "Mr Bobby",
+ },
+ want: &UpdateOrder{
+ RecipientName: strLink("Mr Bobby"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ RecipientName: strLink("Mrs Sarah"),
+ },
+ args: args{
+ recipientName: "Mr Bobby",
+ },
+ want: &UpdateOrder{
+ RecipientName: strLink("Mr Bobby"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ updateOrder := &UpdateOrder{
+ Number: tt.fields.Number,
+ DispatchNumber: tt.fields.DispatchNumber,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientName: tt.fields.RecipientName,
+ Phone: tt.fields.Phone,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ Passport: tt.fields.Passport,
+ Address: tt.fields.Address,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ Package: tt.fields.Package,
+ }
+ if got := updateOrder.SetRecipientName(tt.args.recipientName); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("UpdateOrder.SetRecipientName() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestUpdateOrder_SetPhone(t *testing.T) {
+ type fields struct {
+ Number *string
+ DispatchNumber *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientName *string
+ Phone *string
+ RecipientINN *string
+ DateInvoice *string
+ Passport *Passport
+ Address *Address
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ Package *OrderPackage
+ }
+ type args struct {
+ phone string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *UpdateOrder
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Phone: nil,
+ },
+ args: args{
+ phone: "+79138739944",
+ },
+ want: &UpdateOrder{
+ Phone: strLink("+79138739944"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Phone: strLink("+89138875429"),
+ },
+ args: args{
+ phone: "+79138739944",
+ },
+ want: &UpdateOrder{
+ Phone: strLink("+79138739944"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ updateOrder := &UpdateOrder{
+ Number: tt.fields.Number,
+ DispatchNumber: tt.fields.DispatchNumber,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientName: tt.fields.RecipientName,
+ Phone: tt.fields.Phone,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ Passport: tt.fields.Passport,
+ Address: tt.fields.Address,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ Package: tt.fields.Package,
+ }
+ if got := updateOrder.SetPhone(tt.args.phone); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("UpdateOrder.SetPhone() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestUpdateOrder_SetRecipientINN(t *testing.T) {
+ type fields struct {
+ Number *string
+ DispatchNumber *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientName *string
+ Phone *string
+ RecipientINN *string
+ DateInvoice *string
+ Passport *Passport
+ Address *Address
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ Package *OrderPackage
+ }
+ type args struct {
+ recipientINN string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *UpdateOrder
+ }{
+ {
+ name: "set",
+ fields: fields{
+ RecipientINN: nil,
+ },
+ args: args{
+ recipientINN: "123432123432",
+ },
+ want: &UpdateOrder{
+ RecipientINN: strLink("123432123432"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ RecipientINN: strLink("986538673967"),
+ },
+ args: args{
+ recipientINN: "123432123432",
+ },
+ want: &UpdateOrder{
+ RecipientINN: strLink("123432123432"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ updateOrder := &UpdateOrder{
+ Number: tt.fields.Number,
+ DispatchNumber: tt.fields.DispatchNumber,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientName: tt.fields.RecipientName,
+ Phone: tt.fields.Phone,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ Passport: tt.fields.Passport,
+ Address: tt.fields.Address,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ Package: tt.fields.Package,
+ }
+ if got := updateOrder.SetRecipientINN(tt.args.recipientINN); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("UpdateOrder.SetRecipientINN() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestUpdateOrder_SetDateInvoice(t *testing.T) {
+ type fields struct {
+ Number *string
+ DispatchNumber *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientName *string
+ Phone *string
+ RecipientINN *string
+ DateInvoice *string
+ Passport *Passport
+ Address *Address
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ Package *OrderPackage
+ }
+ type args struct {
+ dateInvoice string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *UpdateOrder
+ }{
+ {
+ name: "set",
+ fields: fields{
+ DateInvoice: nil,
+ },
+ args: args{
+ dateInvoice: "2019-07-18",
+ },
+ want: &UpdateOrder{
+ DateInvoice: strLink("2019-07-18"),
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ DateInvoice: strLink("2017-06-13"),
+ },
+ args: args{
+ dateInvoice: "2019-07-18",
+ },
+ want: &UpdateOrder{
+ DateInvoice: strLink("2019-07-18"),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ updateOrder := &UpdateOrder{
+ Number: tt.fields.Number,
+ DispatchNumber: tt.fields.DispatchNumber,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientName: tt.fields.RecipientName,
+ Phone: tt.fields.Phone,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ Passport: tt.fields.Passport,
+ Address: tt.fields.Address,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ Package: tt.fields.Package,
+ }
+ if got := updateOrder.SetDateInvoice(tt.args.dateInvoice); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("UpdateOrder.SetDateInvoice() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestUpdateOrder_SetPassport(t *testing.T) {
+ type fields struct {
+ Number *string
+ DispatchNumber *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientName *string
+ Phone *string
+ RecipientINN *string
+ DateInvoice *string
+ Passport *Passport
+ Address *Address
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ Package *OrderPackage
+ }
+ type args struct {
+ passport Passport
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *UpdateOrder
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Passport: nil,
+ },
+ args: args{
+ passport: Passport{
+ Series: strLink("passportSeries"),
+ },
+ },
+ want: &UpdateOrder{
+ Passport: &Passport{
+ Series: strLink("passportSeries"),
+ },
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Passport: &Passport{
+ Series: strLink("previousPassportSeries"),
+ },
+ },
+ args: args{
+ passport: Passport{
+ Series: strLink("passportSeries"),
+ },
+ },
+ want: &UpdateOrder{
+ Passport: &Passport{
+ Series: strLink("passportSeries"),
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ updateOrder := &UpdateOrder{
+ Number: tt.fields.Number,
+ DispatchNumber: tt.fields.DispatchNumber,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientName: tt.fields.RecipientName,
+ Phone: tt.fields.Phone,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ Passport: tt.fields.Passport,
+ Address: tt.fields.Address,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ Package: tt.fields.Package,
+ }
+ if got := updateOrder.SetPassport(tt.args.passport); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("UpdateOrder.SetPassport() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestUpdateOrder_SetAddress(t *testing.T) {
+ type fields struct {
+ Number *string
+ DispatchNumber *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientName *string
+ Phone *string
+ RecipientINN *string
+ DateInvoice *string
+ Passport *Passport
+ Address *Address
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ Package *OrderPackage
+ }
+ type args struct {
+ address Address
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *UpdateOrder
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Address: nil,
+ },
+ args: args{
+ address: Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ want: &UpdateOrder{
+ Address: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Address: &Address{
+ Street: strLink("previous test street"),
+ House: strLink("11/4"),
+ },
+ },
+ args: args{
+ address: Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ want: &UpdateOrder{
+ Address: &Address{
+ Street: strLink("test street"),
+ House: strLink("10/3"),
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ updateOrder := &UpdateOrder{
+ Number: tt.fields.Number,
+ DispatchNumber: tt.fields.DispatchNumber,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientName: tt.fields.RecipientName,
+ Phone: tt.fields.Phone,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ Passport: tt.fields.Passport,
+ Address: tt.fields.Address,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ Package: tt.fields.Package,
+ }
+ if got := updateOrder.SetAddress(tt.args.address); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("UpdateOrder.SetAddress() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestUpdateOrder_SetDeliveryRecipientCostAdv(t *testing.T) {
+ type fields struct {
+ Number *string
+ DispatchNumber *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientName *string
+ Phone *string
+ RecipientINN *string
+ DateInvoice *string
+ Passport *Passport
+ Address *Address
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ Package *OrderPackage
+ }
+ type args struct {
+ v DeliveryRecipientCostAdv
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *UpdateOrder
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Address: nil,
+ },
+ args: args{
+ v: DeliveryRecipientCostAdv{
+ Threshold: intLink(1000),
+ Sum: float64Link(33.8),
+ },
+ },
+ want: &UpdateOrder{
+ DeliveryRecipientCostAdv: &DeliveryRecipientCostAdv{
+ Threshold: intLink(1000),
+ Sum: float64Link(33.8),
+ },
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ DeliveryRecipientCostAdv: &DeliveryRecipientCostAdv{
+ Threshold: intLink(1059),
+ Sum: float64Link(12.6),
+ },
+ },
+ args: args{
+ v: DeliveryRecipientCostAdv{
+ Threshold: intLink(1000),
+ Sum: float64Link(33.8),
+ },
+ },
+ want: &UpdateOrder{
+ DeliveryRecipientCostAdv: &DeliveryRecipientCostAdv{
+ Threshold: intLink(1000),
+ Sum: float64Link(33.8),
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ updateOrder := &UpdateOrder{
+ Number: tt.fields.Number,
+ DispatchNumber: tt.fields.DispatchNumber,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientName: tt.fields.RecipientName,
+ Phone: tt.fields.Phone,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ Passport: tt.fields.Passport,
+ Address: tt.fields.Address,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ Package: tt.fields.Package,
+ }
+ if got := updateOrder.SetDeliveryRecipientCostAdv(tt.args.v); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("UpdateOrder.SetDeliveryRecipientCostAdv() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestUpdateOrder_SetPackage(t *testing.T) {
+ type fields struct {
+ Number *string
+ DispatchNumber *int
+ DeliveryRecipientCost *float64
+ DeliveryRecipientVATRate *string
+ DeliveryRecipientVATSum *float64
+ RecipientName *string
+ Phone *string
+ RecipientINN *string
+ DateInvoice *string
+ Passport *Passport
+ Address *Address
+ DeliveryRecipientCostAdv *DeliveryRecipientCostAdv
+ Package *OrderPackage
+ }
+ type args struct {
+ pack OrderPackage
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *UpdateOrder
+ }{
+ {
+ name: "set",
+ fields: fields{
+ Address: nil,
+ },
+ args: args{
+ pack: OrderPackage{
+ Number: strLink("test number"),
+ BarCode: strLink("test barcode"),
+ Weight: intLink(1000),
+ },
+ },
+ want: &UpdateOrder{
+ Package: &OrderPackage{
+ Number: strLink("test number"),
+ BarCode: strLink("test barcode"),
+ Weight: intLink(1000),
+ },
+ },
+ },
+ {
+ name: "modify",
+ fields: fields{
+ Package: &OrderPackage{
+ Number: strLink("previous number"),
+ BarCode: strLink("previous barcode"),
+ Weight: intLink(1755),
+ },
+ },
+ args: args{
+ pack: OrderPackage{
+ Number: strLink("test number"),
+ BarCode: strLink("test barcode"),
+ Weight: intLink(1000),
+ },
+ },
+ want: &UpdateOrder{
+ Package: &OrderPackage{
+ Number: strLink("test number"),
+ BarCode: strLink("test barcode"),
+ Weight: intLink(1000),
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ updateOrder := &UpdateOrder{
+ Number: tt.fields.Number,
+ DispatchNumber: tt.fields.DispatchNumber,
+ DeliveryRecipientCost: tt.fields.DeliveryRecipientCost,
+ DeliveryRecipientVATRate: tt.fields.DeliveryRecipientVATRate,
+ DeliveryRecipientVATSum: tt.fields.DeliveryRecipientVATSum,
+ RecipientName: tt.fields.RecipientName,
+ Phone: tt.fields.Phone,
+ RecipientINN: tt.fields.RecipientINN,
+ DateInvoice: tt.fields.DateInvoice,
+ Passport: tt.fields.Passport,
+ Address: tt.fields.Address,
+ DeliveryRecipientCostAdv: tt.fields.DeliveryRecipientCostAdv,
+ Package: tt.fields.Package,
+ }
+ if got := updateOrder.SetPackage(tt.args.pack); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("UpdateOrder.SetPackage() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
diff --git a/update-order-service.go b/update-order-service.go
new file mode 100755
index 0000000..1c2a7fb
--- /dev/null
+++ b/update-order-service.go
@@ -0,0 +1,64 @@
+package cdek
+
+import (
+ "encoding/xml"
+ "io/ioutil"
+ "net/http"
+ "net/url"
+ "path"
+ "strings"
+
+ "github.com/hashicorp/go-multierror"
+)
+
+const updateOrderURL = "update"
+
+//UpdateOrder This method is used to change a created order.
+func (c Client) UpdateOrder(req UpdateOrderReq) (*UpdateOrderResp, error) {
+ req.setAuth(c.auth)
+ reqByte, err := xml.Marshal(req)
+
+ if err != nil {
+ return nil, err
+ }
+
+ data := make(url.Values)
+ data.Add("xml_request", string(reqByte))
+
+ serverURL, err := url.Parse(c.apiURL)
+ if err != nil {
+ return nil, err
+ }
+
+ serverURL.Path = path.Join(serverURL.Path, updateOrderURL)
+ reqURL := serverURL.String()
+
+ resp, err := http.Post(reqURL, urlFormEncoded, strings.NewReader(data.Encode()))
+ if err != nil {
+ return nil, err
+ }
+
+ defer func() {
+ _ = resp.Body.Close()
+ }()
+
+ body, _ := ioutil.ReadAll(resp.Body)
+
+ var updateOrderResp UpdateOrderResp
+ err = xml.Unmarshal(body, &updateOrderResp)
+ if err != nil {
+ return nil, err
+ }
+
+ multiError := &multierror.Error{}
+ for _, o := range updateOrderResp.Order {
+ if o.IsErroneous() {
+ multiError = multierror.Append(o.GetError())
+ }
+ }
+ if multiError.Len() > 0 {
+ return nil, multiError.ErrorOrNil()
+ }
+
+ return &updateOrderResp, nil
+}
diff --git a/update-order-service_test.go b/update-order-service_test.go
new file mode 100644
index 0000000..596c527
--- /dev/null
+++ b/update-order-service_test.go
@@ -0,0 +1,183 @@
+package cdek
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "reflect"
+ "testing"
+)
+
+func TestClient_UpdateOrder(t *testing.T) {
+ mockServer := updateOrderMockServer()
+ defer mockServer.Close()
+
+ mockServerWithValidError := updateOrderMockServerWithValidError()
+ defer mockServerWithValidError.Close()
+
+ mockServerWithError := updateOrderMockServerWithError()
+ defer mockServerWithError.Close()
+
+ type fields struct {
+ client Client
+ }
+ type args struct {
+ req UpdateOrderReq
+ }
+
+ testOrderToUpdate := NewUpdateOrder().
+ SetDeliveryRecipientCost(10.02).
+ SetDeliveryRecipientVATRate("VATX").
+ SetDeliveryRecipientVATSum(0.0).
+ SetNumber("number-s785558445").
+ SetPackage(*NewOrderPackage("soOEl00", "barcode-soOEl00", 100).
+ SetSize(2, 3, 4).
+ AddItem(*NewOrderPackageItem(2, "warekey-soOEl000", 8, 10, 1, "comment-soOEl000").
+ SetPaymentVATRate("VATX").
+ SetPaymentVATSum(0),
+ ),
+ )
+
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want *UpdateOrderResp
+ wantErr bool
+ }{
+ {
+ name: "creation",
+ fields: fields{
+ client: Client{
+ apiURL: mockServer.URL,
+ },
+ },
+ args: args{
+ req: *NewUpdateOrderReq("soOEl", 1, *testOrderToUpdate),
+ },
+ want: &UpdateOrderResp{
+ Order: []*OrderResp{
+ {
+ DispatchNumber: intLink(1105062403),
+ Number: strLink("number-s785558445"),
+ },
+ {
+ Error: Error{
+ Msg: strLink("Изменено заказов 1"),
+ },
+ },
+ },
+ },
+ wantErr: false,
+ },
+ {
+ name: "handle valid error",
+ fields: fields{
+ client: Client{
+ apiURL: mockServerWithValidError.URL,
+ },
+ },
+ args: args{
+ req: *NewUpdateOrderReq("soOEl", 1, *testOrderToUpdate.SetNumber("notFoundNumber")),
+ },
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "uncompilable url",
+ fields: fields{
+ client: Client{
+ apiURL: " wrong://url ",
+ },
+ },
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "wrong url",
+ fields: fields{
+ client: Client{
+ apiURL: "wrong://url",
+ },
+ },
+ want: nil,
+ wantErr: true,
+ },
+ {
+ name: "server error",
+ fields: fields{
+ client: Client{
+ apiURL: mockServerWithError.URL,
+ },
+ },
+ want: nil,
+ wantErr: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ cl := tt.fields.client
+ got, err := cl.UpdateOrder(tt.args.req)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("Client.UpdateOrder() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Client.UpdateOrder() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func updateOrderMockServer() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _, _ = res.Write([]byte(`
+
+
+
+
+ 6a02b7f9bfa85283
+
+ `))
+ }))
+}
+
+func updateOrderMockServerWithValidError() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _, _ = res.Write([]byte(`
+
+
+
+
+ 1e183b7496f3f3d2
+
+ `))
+ }))
+}
+
+func updateOrderMockServerWithError() *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
+ _, _ = res.Write([]byte("err"))
+ }))
+}
+
+func ExampleClient_UpdateOrder() {
+ client := NewClient("https://integration.edu.cdek.ru/")
+ client.SetAuth("z9GRRu7FxmO53CQ9cFfI6qiy32wpfTkd", "w24JTCv4MnAcuRTx0oHjHLDtyt3I6IBq")
+
+ exampleOrderToUpdate := NewUpdateOrder().
+ SetDeliveryRecipientCost(10.02).
+ SetDeliveryRecipientVATRate("VATX").
+ SetDeliveryRecipientVATSum(0.0).
+ SetNumber("number-s785558445").
+ SetPackage(*NewOrderPackage("soOEl00", "barcode-soOEl00", 100).
+ SetSize(2, 3, 4).
+ AddItem(*NewOrderPackageItem(2, "warekey-soOEl000", 8, 10, 1, "comment-soOEl000").
+ SetPaymentVATRate("VATX").
+ SetPaymentVATSum(0),
+ ),
+ )
+
+ result, err := client.UpdateOrder(*NewUpdateOrderReq("soOEl", 1, *exampleOrderToUpdate))
+
+ _, _ = result, err
+}