aboutsummaryrefslogtreecommitdiffstats
path: root/interior_test.go
blob: 59707b82d46c0762a1cdc27f8add9816b57abf03 (plain) (blame)
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
package lulu

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func TestMarshalValidateInteriorReq(t *testing.T) {
	t.Parallel()
	want := `{
	"source_url": "https://example.com/interior.pdf",
	"pod_package_id": "0850X1100.BW.STD.LW.060UW444.MNG"
}`
	req := validateInteriorReq{
		"https://example.com/interior.pdf",
		PkgId{
			UsLetter,
			Mono,
			Standard,
			LinenWrap,
			P60UncoatedWhite,
			Matte,
			NavyLinen,
			GoldFoil},
	}
	requireMarshalJsonEq(t, want, req)
}

func TestMarshalValidateInteriorBasicReq(t *testing.T) {
	t.Parallel()
	requireMarshalJsonEq(t,
		`{"source_url": "https://example.com/interior.pdf"}`,
		validateInteriorBasicReq{"https://example.com/interior.pdf"})
}

func TestUnmarshalInteriorValidationRecord(t *testing.T) {
	t.Parallel()
	data := `{
  "id": 1,
  "source_url": "https://www.dropbox.com/sh/p3zh22vzsaegiri/AACOUn3LFKsITDzylh13bQpsa/161025/thesis2.pdf?dl=1",
  "page_count": 210,
  "errors": null,
  "status": "VALIDATING",
  "valid_pod_package_ids": null
}`
	want := InteriorValidationRecord{
		1,
		"https://www.dropbox.com/sh/p3zh22vzsaegiri/AACOUn3LFKsITDzylh13bQpsa/161025/thesis2.pdf?dl=1",
		210,
		"",
		InteriorStatusValidating,
		nil,
	}
	requireUnmarshalJsonEq(t, want, data)
}

func TestValidateInterior(t *testing.T) {
	c := newClient(t)
	mfg := PkgId{
		UsTrade,
		Mono,
		Standard,
		Perfect,
		P60UncoatedWhite,
		Gloss,
		NoLinen,
		NoFoil,
	}
	id, err := c.ValidateInterior(interiorUrl, mfg)
	require.NoError(t, err)
	require.NotZero(t, id)
	// It seems the server doesn't populate most of the response
	// fields, but we just need the ID anyway.
}

func TestValidateInteriorBasic(t *testing.T) {
	c := newClient(t)
	id, err := c.ValidateInteriorBasic(interiorUrl)
	require.NoError(t, err)
	require.NotZero(t, id)
	// It seems the server doesn't populate most of the response
	// fields, but we just need the ID anyway.
}

func TestGetInteriorValidation(t *testing.T) {
	c := newClient(t)
	id, err := c.ValidateInteriorBasic(interiorUrl)
	require.NoError(t, err)
	poll(t, func() bool {
		rec, err := c.GetInteriorValidation(id)
		require.NoError(t, err)
		if rec.Status.IsFinal() {
			require.Equal(t, InteriorStatusValidated, rec.Status)

			require.Equal(t, id, rec.Id)
			require.Equal(t, interiorUrl, rec.SrcUrl)
			require.Equal(t, uint(210), rec.NPages)
			require.Empty(t, rec.Errors)
			require.NotEmpty(t, rec.ValidPkgIds)
			return true
		}
		return false
	})
}