diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2026-07-30 19:52:39 -0230 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2026-07-30 19:52:39 -0230 |
| commit | abd51689cef03fa3daecb9abbb54b762e3ab02ac (patch) | |
| tree | 624a65bff5fa98a23ea3006075e7cb4b6140dc5c | |
| parent | d29054bf2f4aa2eea54475a8f0f511fbdba11870 (diff) | |
| download | lulu-abd51689cef03fa3daecb9abbb54b762e3ab02ac.zip | |
lulutest: make dummy (re)printables
| -rw-r--r-- | lulutest/lulutest.go | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lulutest/lulutest.go b/lulutest/lulutest.go new file mode 100644 index 0000000..273128b --- /dev/null +++ b/lulutest/lulutest.go @@ -0,0 +1,62 @@ +package lulutest + +import ( + crand "crypto/rand" + "fmt" + mrand "math/rand/v2" + + "git.samanthony.xyz/lulu" +) + +var ( + DummyEmailAddr = lulu.MustParseEmailAddress("test@example.com") + DummyPkgId = lulu.PkgId{lulu.UsTrade, lulu.Mono, lulu.Standard, lulu.Perfect, lulu.P60UncoatedWhite, lulu.Matte, lulu.NoLinen, lulu.NoFoil} + DummyShipAddr = lulu.ShippingAddress{ + City: "Lübeck", + CountryCode: "DE", + Name: "Hans Dampf", + Phone: lulu.MustParsePhoneNumber("844-212-0689"), + PostCode: "23552", + Street1: "Holstenstr. 40", + } +) + +// MakeReprintables creates a slice of dummy [lulu.Printable]s. +func MakePrintables(c lulu.Client, n int) []lulu.Printable { + ps := make([]lulu.Printable, n) + for i := range ps { + ps[i] = lulu.Printable{ + ExternalId: "dummy-" + crand.Text(), + CoverUrl: "https://www.dropbox.com/sh/p3zh22vzsaegiri/AADP367j0bTWlt8fCu-_tm2ia/161025/139056_cover.pdf?dl=1", + InteriorUrl: "https://www.dropbox.com/sh/p3zh22vzsaegiri/AACOUn3LFKsITDzylh13bQpsa/161025/thesis2.pdf?dl=1", + Mfg: DummyPkgId, + Quantity: 1 + mrand.UintN(10), + Title: "The Tale of " + crand.Text(), + } + } + return ps +} + +// MakeReprintables is used to make a slice of dummy [lulu.Reprintable]s. +// It submits a print job of n books, cancels the order, and returns the books' printables. +func MakeReprintables(c lulu.Client, n int) ([]lulu.Reprintable, error) { + ptbs := MakePrintables(c, n) + job, err := c.Print(DummyEmailAddr, "dummy-"+crand.Text(), lulu.MaxProductionDelay, DummyShipAddr, lulu.Mail, ptbs) + if err != nil { + return nil, err + } + if len(job.Items) != n { + return nil, fmt.Errorf("expected %d line items, got %d", n, len(job.Items)) + } + + rpbs := make([]lulu.Reprintable, n) + for i, it := range job.Items { + rpbs[i] = lulu.Reprintable{ + it.ExternalId, + it.PrintableId, + it.Quantity, + it.Title, + } + } + return rpbs, nil +} |