func TestBackingAlready(t *testing.T) { assert := assert.New(t) sess, db := utils.MakeDB("minikick") defer sess.Close() proj, err := models.NewProject("testproject", "123.45") //set up a new project err = proj.Save(db) assert.Nil(err) err = Back("faiq", "testproject", "4581237932741116", "123.32", db) //lets back this project err = Back("faiq", "testproject", "5119179016239088", "123.32", db) //should fail assert.NotNil(err) //check to see if it fails (should fail) db.DropDatabase() // drop the database to work on the next test }
// check to see if backing a project works or not // we should check the databases with queries to see if the appropriate stuff is created or not func TestBacking(t *testing.T) { assert := assert.New(t) sess, db := utils.MakeDB("minikick") defer sess.Close() proj, err := models.NewProject("testproject", "123.45") //set up a new project err = proj.Save(db) assert.Nil(err) card := "4581237932741116" amount := "123.32" err = Back("faiq", "testproject", card, amount, db) //lets back this project assert.Nil(err) // Now lets make some queries to make sure that everything checks out by querying the tables project, err := models.FindProjectByName("testproject", db) assert.Nil(err) assert.NotNil(project) //make sure its there assert.Contains(project.Cards, models.ParseCard(card)) // check to see if we saved the card parsedAmount, _ := strconv.ParseFloat(amount, 64) assert.Equal(project.AmountBacked, parsedAmount) //check to see if we backed it for that much cash db.DropDatabase() // drop the database to work on the next test }
func main() { app := cli.NewApp() app.Name = "minikick" app.Usage = "Create and back some awesome projects" app.Commands = []cli.Command{ { Name: "project", Aliases: []string{"p"}, Usage: "Create a new project! Just pass in a project name and target amount. (Dont use $ for the amount)", Action: func(c *cli.Context) { args := c.Args() proj, err := models.NewProject(args[0], args[1]) _, db := utils.MakeDB("minikick") err = proj.Save(db) if err != nil { panic(err) } fmt.Printf("We saved your project %s for %s", args[0], args[1]) }, }, { Name: "back", Aliases: []string{"b"}, Usage: "Back a project! The arguments are name, project name, credit card number, and an amount.", Action: func(c *cli.Context) { _, db := utils.MakeDB("minikick") args := c.Args() err := controllers.Back(args[0], args[1], args[2], args[3], db) if err != nil { fmt.Printf("%v", err) } else { fmt.Printf("you just backed %s for %s. thank you!", args[1], args[3]) } }, }, { Name: "list", Aliases: []string{"l"}, Usage: "Display a project the backers and the amount they backed for a project!", Action: func(c *cli.Context) { _, db := utils.MakeDB("minikick") args := c.Args() err := controllers.List(args[0], db) if err != nil { fmt.Printf("%v", err) } }, }, { Name: "backer", Aliases: []string{"br"}, Usage: "Display a list of projects that a backer has backed and the amounts backed", Action: func(c *cli.Context) { _, db := utils.MakeDB("minikick") err := controllers.Backer(c.Args().First(), db) if err != nil { fmt.Printf("%v", err) } }, }, } app.RunAndExitOnError() }