@@ -25,8 +25,8 @@ func createTestTransaction(t *testing.T, c models.TransactionCreate) controllers
2525 c .DestinationAccountID = createTestAccount (t , models.AccountCreate {Name : "Destination Account" }).Data .ID
2626 }
2727
28- if c .EnvelopeID == uuid .Nil {
29- c .EnvelopeID = createTestEnvelope (t , models.EnvelopeCreate {Name : "Transaction Test Envelope" }).Data .ID
28+ if c .EnvelopeID == & uuid .Nil {
29+ * c .EnvelopeID = createTestEnvelope (t , models.EnvelopeCreate {Name : "Transaction Test Envelope" }).Data .ID
3030 }
3131
3232 r := test .Request (t , http .MethodPost , "http://example.com/v1/transactions" , c )
@@ -104,7 +104,7 @@ func (suite *TestSuiteEnv) TestCreateTransactionMissingReference() {
104104 TransactionCreate : models.TransactionCreate {
105105 SourceAccountID : account .Data .ID ,
106106 DestinationAccountID : account .Data .ID ,
107- EnvelopeID : envelope .Data .ID ,
107+ EnvelopeID : & envelope .Data .ID ,
108108 },
109109 })
110110 test .AssertHTTPStatus (suite .T (), http .StatusBadRequest , & r )
@@ -124,7 +124,7 @@ func (suite *TestSuiteEnv) TestCreateTransactionMissingReference() {
124124 TransactionCreate : models.TransactionCreate {
125125 BudgetID : budget .Data .ID ,
126126 DestinationAccountID : account .Data .ID ,
127- EnvelopeID : envelope .Data .ID ,
127+ EnvelopeID : & envelope .Data .ID ,
128128 },
129129 })
130130 test .AssertHTTPStatus (suite .T (), http .StatusBadRequest , & r )
@@ -134,7 +134,7 @@ func (suite *TestSuiteEnv) TestCreateTransactionMissingReference() {
134134 TransactionCreate : models.TransactionCreate {
135135 BudgetID : budget .Data .ID ,
136136 SourceAccountID : account .Data .ID ,
137- EnvelopeID : envelope .Data .ID ,
137+ EnvelopeID : & envelope .Data .ID ,
138138 },
139139 })
140140 test .AssertHTTPStatus (suite .T (), http .StatusBadRequest , & r )
@@ -160,7 +160,7 @@ func (suite *TestSuiteEnv) TestCreateNegativeAmountTransaction() {
160160 BudgetID : budget .Data .ID ,
161161 SourceAccountID : account .Data .ID ,
162162 DestinationAccountID : account .Data .ID ,
163- EnvelopeID : envelope .Data .ID ,
163+ EnvelopeID : & envelope .Data .ID ,
164164 Amount : decimal .NewFromFloat (- 17.12 ),
165165 Note : "Negative amounts are not allowed, this must fail" ,
166166 })
@@ -173,6 +173,48 @@ func (suite *TestSuiteEnv) TestCreateNonExistingBudgetTransaction() {
173173 test .AssertHTTPStatus (suite .T (), http .StatusNotFound , & recorder )
174174}
175175
176+ func (suite * TestSuiteEnv ) TestCreateNoEnvelopeTransactionTransfer () {
177+ c := models.TransactionCreate {
178+ BudgetID : createTestBudget (suite .T (), models.BudgetCreate {Name : "Testing budget for transfer" }).Data .ID ,
179+ SourceAccountID : createTestAccount (suite .T (), models.AccountCreate {Name : "Internal Source Account" , External : false }).Data .ID ,
180+ DestinationAccountID : createTestAccount (suite .T (), models.AccountCreate {Name : "Internal destination account" , External : false }).Data .ID ,
181+ Amount : decimal .NewFromFloat (500 ),
182+ }
183+
184+ recorder := test .Request (suite .T (), http .MethodPost , "http://example.com/v1/transactions" , c )
185+ test .AssertHTTPStatus (suite .T (), http .StatusCreated , & recorder )
186+ }
187+
188+ func (suite * TestSuiteEnv ) TestCreateNoEnvelopeTransactionOutgoing () {
189+ c := models.TransactionCreate {
190+ BudgetID : createTestBudget (suite .T (), models.BudgetCreate {Name : "Testing budget for transfer" }).Data .ID ,
191+ SourceAccountID : createTestAccount (suite .T (), models.AccountCreate {Name : "Internal Source Account" , External : false }).Data .ID ,
192+ DestinationAccountID : createTestAccount (suite .T (), models.AccountCreate {Name : "External destination account" , External : true }).Data .ID ,
193+ Amount : decimal .NewFromFloat (350 ),
194+ }
195+
196+ recorder := test .Request (suite .T (), http .MethodPost , "http://example.com/v1/transactions" , c )
197+ test .AssertHTTPStatus (suite .T (), http .StatusBadRequest , & recorder )
198+
199+ err := test .DecodeError (suite .T (), recorder .Body .Bytes ())
200+ assert .Equal (suite .T (), "For incoming and outgoing transactions, an envelope is required" , err )
201+ }
202+
203+ func (suite * TestSuiteEnv ) TestCreateNonExistingEnvelopeTransactionTransfer () {
204+ id := uuid .New ()
205+
206+ c := models.TransactionCreate {
207+ BudgetID : createTestBudget (suite .T (), models.BudgetCreate {Name : "Testing budget for transfer" }).Data .ID ,
208+ SourceAccountID : createTestAccount (suite .T (), models.AccountCreate {Name : "Internal Source Account" , External : false }).Data .ID ,
209+ DestinationAccountID : createTestAccount (suite .T (), models.AccountCreate {Name : "External destination account" , External : true }).Data .ID ,
210+ Amount : decimal .NewFromFloat (350 ),
211+ EnvelopeID : & id ,
212+ }
213+
214+ recorder := test .Request (suite .T (), http .MethodPost , "http://example.com/v1/transactions" , c )
215+ test .AssertHTTPStatus (suite .T (), http .StatusNotFound , & recorder )
216+ }
217+
176218func (suite * TestSuiteEnv ) TestCreateTransactionNoBody () {
177219 recorder := test .Request (suite .T (), http .MethodPost , "http://example.com/v1/transactions" , "" )
178220 test .AssertHTTPStatus (suite .T (), http .StatusBadRequest , & recorder )
0 commit comments