aboutsummaryrefslogtreecommitdiffstats
path: root/cover_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'cover_test.go')
-rw-r--r--cover_test.go65
1 files changed, 35 insertions, 30 deletions
diff --git a/cover_test.go b/cover_test.go
index 140bf84..d94e2f0 100644
--- a/cover_test.go
+++ b/cover_test.go
@@ -1,6 +1,7 @@
package lulu
import (
+ "context"
"testing"
"github.com/stretchr/testify/require"
@@ -80,7 +81,7 @@ func TestMarshalValidateCoverReq(t *testing.T) {
requireMarshalJsonEq(t, want, req)
}
-func TestUnmarshalCoverValidationRecord(t *testing.T) {
+func TestUnmarshalCoverValidation(t *testing.T) {
t.Parallel()
data := `{
"id": 1,
@@ -89,7 +90,7 @@ func TestUnmarshalCoverValidationRecord(t *testing.T) {
"errors": null,
"status": "NORMALIZING"
}`
- want := CoverValidationRecord{
+ want := CoverValidation{
1,
"https://www.dropbox.com/sh/p3zh22vzsaegiri/AADP367j0bTWlt8fCu-_tm2ia/161025/139056_cover.pdf?dl=1",
210,
@@ -99,7 +100,7 @@ func TestUnmarshalCoverValidationRecord(t *testing.T) {
requireUnmarshalJsonEq(t, want, data)
}
-func TestValidateCover(t *testing.T) {
+func TestStartCoverValidation(t *testing.T) {
c := newClient(t)
mfg := PkgId{
UsTrade,
@@ -111,43 +112,47 @@ func TestValidateCover(t *testing.T) {
NoLinen,
NoFoil,
}
- id, err := c.ValidateCover(coverUrl, mfg, 210)
+ id, err := c.StartCoverValidation(coverUrl, mfg, 210)
require.NoError(t, err)
require.NotZero(t, id)
}
func TestGetCoverValidation(t *testing.T) {
c := newClient(t)
-
- mfg := PkgId{
- UsTrade,
- Mono,
- Standard,
- Perfect,
- P60UncoatedWhite,
- Gloss,
- NoLinen,
- NoFoil,
- }
- id, err := c.ValidateCover(coverUrl, mfg, 210)
+ mfg := PkgId{UsTrade, Mono, Standard, Perfect, P60UncoatedWhite, Gloss, NoLinen, NoFoil}
+ id, err := c.StartCoverValidation(coverUrl, mfg, 210)
require.NoError(t, err)
-
- poll(t, func() bool {
- rec, err := c.GetCoverValidation(id)
+ tpoll(t, func() bool {
+ val, err := c.GetCoverValidation(id)
require.NoError(t, err)
- if rec.Status.IsFinal() {
- require.Equal(t, CoverStatusNormalized, rec.Status)
- require.Equal(t, id, rec.Id)
- require.Equal(t, coverUrl, rec.SrcUrl)
-
- //require.Equal(t, uint(210), rec.NPages)
- // The server doesn't seem to set the page_count
- // field, but that's OK because we already know
- // the page count.
-
- require.Empty(t, rec.Errors)
+ if val.Status.IsFinal() {
+ require.Equal(t, id, val.Id)
+ validateCoverValidation(t, val)
return true
}
return false
})
}
+
+func TestValidateCover(t *testing.T) {
+ c := newClient(t)
+ ctx, cancel := context.WithTimeout(t.Context(), timeout)
+ defer cancel()
+ mfg := PkgId{UsTrade, Mono, Standard, Perfect, P60UncoatedWhite, Gloss, NoLinen, NoFoil}
+ val, err := c.ValidateCover(ctx, coverUrl, mfg, 210)
+ require.NoError(t, err)
+ validateCoverValidation(t, val)
+}
+
+func validateCoverValidation(t *testing.T, val CoverValidation) {
+ t.Helper()
+ require.Equal(t, CoverStatusNormalized, val.Status)
+ require.Equal(t, coverUrl, val.SrcUrl)
+
+ //require.Equal(t, uint(210), val.NPages)
+ // The server doesn't seem to set the page_count
+ // field, but that's OK because we already know
+ // the page count.
+
+ require.Empty(t, val.Errors)
+}