func TestAddOrder(t *testing.T) {
	b := cmdtest.NewTestRecorder(t)
	defer b.CleanUp()
	cart := NewCartCmd(b)
	add := newAddOrderCmd(b)
	tests.Check(add.Run(add.Cmd(), []string{"testing"}))
	if b.Out.String() != "" {
		t.Errorf("wrong output: should have no output: '%s'", b.Out.String())
	}
	b.Out.Reset()
	cart.Cmd().ParseFlags([]string{"-d"})
	tests.Check(cart.Run(cart.Cmd(), []string{"testing"}))
	b.Out.Reset()
}
func testAddOrder(t *testing.T, buf *bytes.Buffer, cmds ...cli.CliCommand) {
package commands
import (
	"bytes"
	"fmt"
	"strings"
	"testing"
	"github.com/harrybrwn/apizza/cmd/cli"
	"github.com/harrybrwn/apizza/cmd/internal/cmdtest"
	"github.com/harrybrwn/apizza/cmd/internal/obj"
	"github.com/harrybrwn/apizza/pkg/errs"
	"github.com/harrybrwn/apizza/pkg/tests"
)
func init() {
	Color = false
}
func addTestOrder(b cli.Builder) {
	new := newAddOrderCmd(b).Cmd()
	if err := errs.Pair(
		new.ParseFlags([]string{"--name=testorder", "--product=14SCREEN", "--toppings=P,K"}),
		new.RunE(new, []string{}),
	); err != nil {
		panic("could not add a test order: " + err.Error())
	}
}
func newTestCart(b cli.Builder) *cartCmd {
	cart := NewCartCmd(b)
	addTestOrder(b)
	return cart.(*cartCmd)
}
func TestCartCommand(t *testing.T) {
	b := cmdtest.NewTestRecorder(t)
	defer b.CleanUp()
	cart := newTestCart(b)
	tests.Check(cart.Run(cart.Cmd(), []string{"testorder"}))
	if !strings.Contains(b.Out.String(), "testorder") {
		t.Error("cart output did not have the right name")
	}
	if !strings.Contains(b.Out.String(), "14SCREEN") {
		t.Error("does not have the correct product")
	}
	b.Conf.Address = obj.Address{
		Street:   "600 Mountain Ave bldg 5",
		CityName: "New Providence",
		State:    "NJ",
		Zipcode:  "07974",
	}
	tests.Check(cart.Run(cart.Cmd(), []string{"testorder"}))
	cart.Cmd().ParseFlags([]string{"--validate"})
	tests.Check(cart.Run(cart.Cmd(), []string{"testorder"}))
	tests.Exp(cart.Cmd().PreRunE(cart.Cmd(), []string{"testorder", "another"}))
	tests.Check(cart.Cmd().PreRunE(cart.Cmd(), []string{"testorder"}))
	b.Out.Reset()
	cart.validate = false
	cart.Cmd().ParseFlags([]string{"--add=K"})
	tests.Exp(cart.Run(cart.Cmd(), []string{"testorder"}))
	fmt.Println(b.Out.String())
}
func TestCartToppings(t *testing.T) {
	b := cmdtest.NewTestRecorder(t)
	defer b.CleanUp()
	cart := newTestCart(b)
	tests.Check(cart.Cmd().ParseFlags([]string{"-a=P:left:1.5", "-p=14SCREEN"}))
	tests.Check(cart.Run(cart.Cmd(), []string{"testorder"}))
}
func TestCartToppings_Err(t *testing.T) {
	b := cmdtest.NewTestRecorder(t)
	defer b.CleanUp()
	cart := newTestCart(b)
	tests.Check(cart.Cmd().ParseFlags([]string{"-a=P:badinput:1.5", "-p=14SCREEN"}))
	tests.Exp(cart.Run(cart.Cmd(), []string{"testorder"}))
}
func testOrderNew(t *testing.T, buf *bytes.Buffer, cmds ...cli.CliCommand) {
	cart, add := cmds[0], cmds[1]
	add.Cmd().ParseFlags([]string{"--name=testorder", "--product=12SCMEATZA"})
	err := add.Run(add.Cmd(), []string{})
	if err != nil {
		t.Error(err)
	}
	buf.Reset()
	if err := cart.Run(cart.Cmd(), []string{"testorder"}); err != nil {
		t.Error(err)
	}
	expected := `testorder
  products:
    Medium (12") Hand Tossed MeatZZa
      code:     12SCMEATZA
      options:
         B: 1/1 1
         C: 1/1 1.5
         H: 1/1 1
         P: 1/1 1
         S: 1/1 1
         X: 1/1 1
      quantity: 1
  storeID: 4336
  method:  Carryout
  address: 1600 Pennsylvania Ave NW
  	       Washington, DC 20500
`
	tests.Compare(t, buf.String(), strings.Replace(expected, "\t", "  ", -1))
}