1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
package lulu
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestMarshalCoverDimensionsReq(t *testing.T) {
t.Parallel()
requireMarshalJsonEq(t, `{
"pod_package_id": "0600X0900.BW.STD.PB.060UW444.MXX",
"interior_page_count": 210,
"unit": "pt"}`,
coverDimensionsReq{
PkgId{
UsTrade,
Mono,
Standard,
Perfect,
P60UncoatedWhite,
Matte,
NoLinen,
NoFoil},
210,
Points})
}
func TestUnmarshalCoverDimensions(t *testing.T) {
t.Parallel()
requireUnmarshalJsonEq(t,
CoverDimensions{123.4, 567.8, Points},
`{"width": "123.400", "height": "567.800", "unit": "pt"}`)
requireUnmarshalJsonEq(t,
CoverDimensions{123.4, 567.8, Millimeters},
`{"width": "123.400", "height": "567.800", "unit": "mm"}`)
requireUnmarshalJsonEq(t,
CoverDimensions{123.4, 567.8, Inches},
`{"width": "123.400", "height": "567.800", "unit": "inch"}`)
}
func TestCoverDimensions(t *testing.T) {
c := newClient(t)
mfg := PkgId{
UsTrade,
Mono,
Standard,
Perfect,
P60UncoatedWhite,
Matte,
NoLinen,
NoFoil,
}
dims, err := c.CoverDimensions(mfg, 210, Points)
require.NoError(t, err)
require.Equal(t, CoverDimensions{920, 666, Points}, dims)
}
func TestMarshalValidateCoverReq(t *testing.T) {
t.Parallel()
want := `{
"source_url": "https://www.dropbox.com/sh/p3zh22vzsaegiri/AADP367j0bTWlt8fCu-_tm2ia/161025/139056_cover.pdf?dl=1",
"pod_package_id": "0600X0900.BW.STD.PB.060UW444.MXX",
"interior_page_count": 210
}`
req := validateCoverReq{
"https://www.dropbox.com/sh/p3zh22vzsaegiri/AADP367j0bTWlt8fCu-_tm2ia/161025/139056_cover.pdf?dl=1",
PkgId{
UsTrade,
Mono,
Standard,
Perfect,
P60UncoatedWhite,
Matte,
NoLinen,
NoFoil,
},
210,
}
requireMarshalJsonEq(t, want, req)
}
func TestUnmarshalCoverValidationRecord(t *testing.T) {
t.Parallel()
data := `{
"id": 1,
"source_url": "https://www.dropbox.com/sh/p3zh22vzsaegiri/AADP367j0bTWlt8fCu-_tm2ia/161025/139056_cover.pdf?dl=1",
"page_count": 210,
"errors": null,
"status": "NORMALIZING"
}`
want := CoverValidationRecord{
1,
"https://www.dropbox.com/sh/p3zh22vzsaegiri/AADP367j0bTWlt8fCu-_tm2ia/161025/139056_cover.pdf?dl=1",
210,
"",
CoverStatusNormalizing,
}
requireUnmarshalJsonEq(t, want, data)
}
func TestValidateCover(t *testing.T) {
c := newClient(t)
mfg := PkgId{
UsTrade,
Mono,
Standard,
Perfect,
P60UncoatedWhite,
Gloss,
NoLinen,
NoFoil,
}
id, err := c.ValidateCover(coverUrl, mfg, 210)
require.NoError(t, err)
require.NotZero(t, id)
}
|