diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2026-05-07 11:53:51 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2026-05-07 11:53:51 -0400 |
| commit | f2ee817ba1423b10b382f6b759a19184db8eeacc (patch) | |
| tree | 57d7660024b9b21d2a9ac80c351b2911b5c573e7 /lulu_test.go | |
| parent | 09c91d21b083abc976a4cc6439899fb00438a630 (diff) | |
| download | lulu-f2ee817ba1423b10b382f6b759a19184db8eeacc.zip | |
refactor
Diffstat (limited to 'lulu_test.go')
| -rw-r--r-- | lulu_test.go | 165 |
1 files changed, 0 insertions, 165 deletions
diff --git a/lulu_test.go b/lulu_test.go index 513d590..05d37ad 100644 --- a/lulu_test.go +++ b/lulu_test.go @@ -1,13 +1,11 @@ package lulu import ( - "context" "encoding/json" "fmt" "os" "strings" "testing" - "time" "github.com/stretchr/testify/require" ) @@ -44,169 +42,6 @@ func TestMain(m *testing.M) { m.Run() } -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, - "", - StatusValidating, - 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) - - // Start validation job - id, err := c.ValidateInteriorBasic(interiorUrl) - require.NoError(t, err) - - // Poll until done - timeout := 15 * time.Second - period := time.Second - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - timer := time.NewTimer(period) - for { - select { - case <-timer.C: - rec, err := c.GetInteriorValidation(id) - require.NoError(t, err) - if rec.Status.IsFinal() { - require.Equal(t, StatusValidated, 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 - } - timer.Reset(period) - case <-ctx.Done(): - t.Errorf("status still not finalized after %v", timeout) - return - } - } -} - -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 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 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 newClient(t *testing.T) *Client { t.Helper() c, err := NewClient(t.Context(), clientKey, clientSecret) |