예제 #1
0
func (database *Database) CreateTransaction(t *models.Transaction) *models.Transaction {
	t.Id = bson.NewObjectId()

	session := database.getSession()

	log.Println(t.Name)

	session.DB(database.databaseName).C("transactions").Insert(t)

	ct := models.Transaction{}
	session.DB(database.databaseName).C("transactions").FindId(t.Id).One(&ct)

	return &ct
}
예제 #2
0
func TestGetTransactions(t *testing.T) {
	mgoConn := getConnectionString()
	clearDatabase(mgoConn)
	database := NewDatabase(mgoConn, "house_test")

	tr := models.Transaction{}

	tr.Name = "Transaction Name"
	tr.Timestamp = time.Now()
	tr.Amount = 1.50
	tr.Buyer = "simon"
	tr.Type = "shared"

	database.CreateTransaction(&tr)

	transactions := database.GetTransactions()

	assert.Equal(t, tr.Name, (*transactions)[0].Name)
}