. "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/sporto/kic/api/models" "github.com/sporto/kic/api/services/accounts" "github.com/sporto/kic/api/services/transactions" "time" // "os" "log" ) var _ = Describe("CreateServ", func() { var ( createAccountServ accounts.CreateServ updateAccountServ accounts.UpdateServ service transactions.CreateServ account models.Account transaction *models.Transaction err error ) BeforeEach(func() { // log.Println("---- BeforeEach -------") // log.Println("dbSession", dbSession) accountIn := *&models.Account{CurrentBalance: 100, LastInterestPaid: time.Now()} account, err = createAccountServ.Run(dbSession, accountIn) // log.Println("Account created ", account) if err != nil { log.Println("Account not created because ", err) } transaction = &models.Transaction{AccountId: account.Id, Debit: 50, Credit: 100} })
package accounts_test import ( "fmt" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/sporto/kic/api/models" "github.com/sporto/kic/api/services/accounts" ) var _ = Describe("GetServ", func() { var ( service accounts.GetServ accountId string createAccountServ accounts.CreateServ ) BeforeEach(func() { accountIn := new(models.Account) accountIn.Name = "X" accountOut, err := createAccountServ.Run(dbSession, *accountIn) if err != nil { fmt.Println("Account not created") } accountId = accountOut.Id }) It("Saved the account", func() { Expect(accountId).NotTo(BeEmpty()) })
"fmt" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/sporto/kic/api/lib/matchers" "github.com/sporto/kic/api/models" "github.com/sporto/kic/api/services/account_balances" "github.com/sporto/kic/api/services/accounts" "time" ) var _ = Describe("AdjustServ", func() { var ( service account_balances.AdjustServ createServ accounts.CreateServ getRateServ accounts.GetInterestRateServ account models.Account err error rate float64 ) BeforeEach(func() { // create an empty accountIn for testing accountIn := &models.Account{ CurrentBalance: 100, LastInterestPaid: time.Now().AddDate(-1, 0, 0), } // create the account and get a ref account, err = createServ.Run(dbSession, *accountIn) if err != nil { fmt.Println(err) }
package accounts_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/sporto/kic/api/models" "github.com/sporto/kic/api/services/accounts" ) var _ = Describe("CreateServ", func() { var ( service accounts.CreateServ ) It("Saves the account", func() { accountIn := &models.Account{Name: "Sam"} accountOut, err := service.Run(dbSession, *accountIn) Expect(err).To(BeNil()) Expect(accountOut.Id).NotTo(BeEmpty()) }) It("fails if the account is already saved", func() { account := &models.Account{Id: "aaaaa"} _, err := service.Run(dbSession, *account) Expect(err).NotTo(BeNil()) }) })