diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2026-05-13 18:28:09 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2026-05-13 18:28:09 -0400 |
| commit | 0865e2e03651dcc7be91846a6e52125e56bcde31 (patch) | |
| tree | c5abe0a595e1ad26db0e4e7195ad963ca845e202 /interior_test.go | |
| parent | 48f85453ffbe36f6c428a5d9a23b74122686b64c (diff) | |
| download | lulu-0865e2e03651dcc7be91846a6e52125e56bcde31.zip | |
poll for file validation status
Diffstat (limited to 'interior_test.go')
| -rw-r--r-- | interior_test.go | 74 |
1 files changed, 43 insertions, 31 deletions
diff --git a/interior_test.go b/interior_test.go index 59707b8..110afb2 100644 --- a/interior_test.go +++ b/interior_test.go @@ -1,6 +1,7 @@ package lulu import ( + "context" "testing" "github.com/stretchr/testify/require" @@ -34,7 +35,7 @@ func TestMarshalValidateInteriorBasicReq(t *testing.T) { validateInteriorBasicReq{"https://example.com/interior.pdf"}) } -func TestUnmarshalInteriorValidationRecord(t *testing.T) { +func TestUnmarshalInteriorValidation(t *testing.T) { t.Parallel() data := `{ "id": 1, @@ -44,7 +45,7 @@ func TestUnmarshalInteriorValidationRecord(t *testing.T) { "status": "VALIDATING", "valid_pod_package_ids": null }` - want := InteriorValidationRecord{ + want := InteriorValidation{ 1, "https://www.dropbox.com/sh/p3zh22vzsaegiri/AACOUn3LFKsITDzylh13bQpsa/161025/thesis2.pdf?dl=1", 210, @@ -55,51 +56,62 @@ func TestUnmarshalInteriorValidationRecord(t *testing.T) { requireUnmarshalJsonEq(t, want, data) } -func TestValidateInterior(t *testing.T) { +func TestStartInteriorValidation(t *testing.T) { c := newClient(t) - mfg := PkgId{ - UsTrade, - Mono, - Standard, - Perfect, - P60UncoatedWhite, - Gloss, - NoLinen, - NoFoil, - } - id, err := c.ValidateInterior(interiorUrl, mfg) + mfg := PkgId{UsTrade, Mono, Standard, Perfect, P60UncoatedWhite, Gloss, NoLinen, NoFoil} + id, err := c.StartInteriorValidation(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) { +func TestStartInteriorValidationBasic(t *testing.T) { c := newClient(t) - id, err := c.ValidateInteriorBasic(interiorUrl) + id, err := c.StartInteriorValidationBasic(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) + mfg := PkgId{UsTrade, Mono, Standard, Perfect, P60UncoatedWhite, Gloss, NoLinen, NoFoil} + id, err := c.StartInteriorValidation(interiorUrl, mfg) require.NoError(t, err) - poll(t, func() bool { - rec, err := c.GetInteriorValidation(id) + tpoll(t, func() bool { + val, 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) + if val.Status.IsFinal() { + require.Equal(t, id, val.Id) + validateInteriorValidation(t, val, InteriorStatusNormalized) return true } return false }) } + +func TestValidateInterior(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.ValidateInterior(ctx, interiorUrl, mfg) + require.NoError(t, err) + validateInteriorValidation(t, val, InteriorStatusNormalized) +} + +func TestValidateInteriorBasic(t *testing.T) { + c := newClient(t) + ctx, cancel := context.WithTimeout(t.Context(), timeout) + defer cancel() + val, err := c.ValidateInteriorBasic(ctx, interiorUrl) + require.NoError(t, err) + validateInteriorValidation(t, val, InteriorStatusValidated) +} + +func validateInteriorValidation(t *testing.T, val InteriorValidation, wantStatus InteriorValidationStatus) { + t.Helper() + require.Equal(t, wantStatus, val.Status) + require.Equal(t, interiorUrl, val.SrcUrl) + require.Equal(t, uint(210), val.NPages) + require.Empty(t, val.Errors) + require.NotEmpty(t, val.ValidPkgIds) +} |