aboutsummaryrefslogtreecommitdiffstats
path: root/lulutest/lulutest.go
blob: 273128b5b6f47e46791b1d724129ae31fab96b7f (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
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
}