fix regionId & cityId unmarshaling error

This commit is contained in:
Pavel 2025-01-31 11:38:47 +03:00
parent d101ddb097
commit 634ec386b1
3 changed files with 108 additions and 13 deletions

View File

@ -20,10 +20,10 @@ jobs:
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Set up Go 1.17
uses: actions/setup-go@v2
- name: Set up Go 1.23
uses: actions/setup-go@v3
with:
go-version: '1.17'
go-version: '1.23'
- name: Get dependencies
run: |
go mod tidy
@ -31,7 +31,7 @@ jobs:
- name: Lint code with golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.50.1
version: v1.62.2
only-new-issues: true
skip-pkg-cache: true
args: --build-tags=testutils
@ -40,13 +40,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.13', '1.14', '1.15', '1.16', '1.17']
go-version: ['1.19', '1.20', '1.21', '1.22', '1.23', 'stable']
include:
- go-version: '1.17'
- go-version: '1.23'
coverage: 1
steps:
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Check out code into the Go module directory
@ -59,17 +59,21 @@ jobs:
env:
COVERAGE: ${{ matrix.coverage }}
if: env.COVERAGE != 1
run: go test -tags=testutils ./...
run: |
go install gotest.tools/gotestsum@latest
gotestsum --format testdox ./... -tags=testutils-v -cpu 2 -timeout 60s -race
- name: Tests with coverage
env:
COVERAGE: ${{ matrix.coverage }}
if: env.COVERAGE == 1
run: |
go test -tags=testutils ./... -race -coverprofile=coverage.txt -covermode=atomic "$d"
go install gotest.tools/gotestsum@latest
gotestsum --format testdox ./... -tags=testutils-v -cpu 2 -timeout 60s -race -cover -coverprofile=coverage.txt -covermode=atomic "$d"
- name: Coverage
env:
COVERAGE: ${{ matrix.coverage }}
if: env.COVERAGE == 1
run: |
go install github.com/axw/gocov/gocov@latest
gocov convert ./coverage.txt | gocov report
bash <(curl -s https://codecov.io/bash)
rm coverage.txt

View File

@ -3822,7 +3822,95 @@ func TestClient_PriceTypes(t *testing.T) {
gock.New(crmURL).
Get("/reference/price-types").
Reply(200).
BodyString(`{"success": true}`)
BodyString(`
{
"success": true,
"priceTypes": [
{
"id": 1,
"code": "base",
"name": "Base",
"active": true,
"promo": false,
"default": true,
"geo": [],
"groups": [],
"ordering": 1,
"currency": "MXN"
},
{
"id": 4,
"code": "cop",
"name": "COP",
"active": false,
"promo": false,
"default": false,
"geo": [],
"groups": [
"manager_1"
],
"ordering": 990,
"currency": "MXN"
},
{
"id": 2,
"code": "promo_test",
"name": "Promotional",
"active": false,
"promo": true,
"default": false,
"geo": [
{
"country": "CO",
"regionId": "",
"region": "Todas las regiones",
"cityId": "",
"city": "All"
},
{
"country": "ES",
"regionId": "",
"region": "Todas las regiones",
"cityId": "",
"city": "All"
},
{
"country": "MX",
"regionId": "",
"region": "Todas las regiones",
"cityId": "",
"city": "All"
}
],
"groups": [],
"ordering": 990,
"currency": "MXN"
},
{
"id": 3,
"code": "wholesale",
"name": "Wholesale",
"active": false,
"promo": true,
"default": false,
"description": "Solo para ventas al mayoreo con mas de 10 articulos.",
"filterExpression": "order.quantity >= 1",
"geo": [
{
"country": "MX",
"regionId": "",
"region": "Todas las regiones",
"cityId": "",
"city": "All"
}
],
"groups": [],
"ordering": 990,
"currency": "MXN"
}
]
}
`)
data, st, err := c.PriceTypes()
if err != nil {

View File

@ -53,13 +53,16 @@ type Address struct {
Text string `json:"text,omitempty"`
}
// GeoID type. Can be empty string.
type GeoID json.Number
// GeoHierarchyRow type.
type GeoHierarchyRow struct {
Country string `json:"country,omitempty"`
Region string `json:"region,omitempty"`
RegionID int `json:"regionId,omitempty"`
RegionID GeoID `json:"regionId,omitempty"`
City string `json:"city,omitempty"`
CityID int `json:"cityId,omitempty"`
CityID GeoID `json:"cityId,omitempty"`
}
// Source type.