Merge pull request #95 from Neur0toxine/fix-regionId-cityId

fix regionId & cityId unmarshaling error
This commit is contained in:
Pavel 2025-01-31 11:50:00 +03:00 committed by GitHub
commit 2859073353
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 139 additions and 42 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

@ -1,11 +1,37 @@
run:
skip-dirs-use-default: true
allow-parallel-runners: true
skip-files:
issues:
exclude-files:
- testutils.go
exclude-rules:
- path: _test\.go
linters:
- lll
- errcheck
- misspell
- ineffassign
- whitespace
- makezero
- errcheck
- funlen
- goconst
- gocognit
- gocyclo
- godot
- unused
- errchkjson
- varnamelen
exclude-use-default: true
exclude-case-sensitive: false
max-issues-per-linter: 0
max-same-issues: 0
fix: true
output:
format: colored-line-number
formats:
- format: colored-line-number
sort-results: true
# Linters below do not support go1.18 yet because of generics.
@ -38,6 +64,7 @@ linters:
- errorlint
- exhaustive
- exportloopref
- copyloopvar
- funlen
- gocognit
- goconst
@ -53,7 +80,6 @@ linters:
- nestif
- prealloc
- predeclared
- exportloopref
- unconvert
- whitespace
@ -178,34 +204,10 @@ linters-settings:
- t *testing.T
- e error
- i int
issues:
exclude-rules:
- path: _test\.go
linters:
- lll
- errcheck
- misspell
- ineffassign
- whitespace
- makezero
- errcheck
- funlen
- goconst
- gocognit
- gocyclo
- godot
- unused
- errchkjson
- varnamelen
exclude-use-default: true
exclude-case-sensitive: false
max-issues-per-linter: 0
max-same-issues: 0
fix: true
severity:
default-severity: error
case-sensitive: false
service:
golangci-lint-version: 1.50.x
golangci-lint-version: 1.62.x

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

@ -23,7 +23,7 @@ func (st SystemTime) MarshalJSON() ([]byte, error) {
return []byte(st.String()), nil
}
// String returns the time in the custom format
// String returns the time in the custom format.
func (st *SystemTime) String() string {
t := time.Time(*st)
return fmt.Sprintf("%q", t.Format(systemTimeLayout))

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.