1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2025-07-03 12:48:38 -04:00

Add initial OFX import test

So far, this only checks to ensure that the import doesn't return an
error code.
This commit is contained in:
2017-11-26 14:42:05 -05:00
parent 7a23739a0b
commit aa8924243e
6 changed files with 345 additions and 46 deletions

View File

@ -1,57 +1,13 @@
package handlers_test
import (
"bytes"
"github.com/aclindsa/moneygo/internal/handlers"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"os"
"testing"
)
func importGnucash(client *http.Client, filename string) error {
var buf bytes.Buffer
mw := multipart.NewWriter(&buf)
file, err := os.Open(filename)
if err != nil {
return err
}
defer file.Close()
filewriter, err := mw.CreateFormFile("gnucash", filename)
if err != nil {
return err
}
if _, err := io.Copy(filewriter, file); err != nil {
return err
}
mw.Close()
response, err := client.Post(server.URL+"/v1/imports/gnucash", mw.FormDataContentType(), &buf)
if err != nil {
return err
}
body, err := ioutil.ReadAll(response.Body)
response.Body.Close()
if err != nil {
return err
}
var e handlers.Error
err = (&e).Read(string(body))
if err != nil {
return err
}
if e.ErrorId != 0 || len(e.ErrorString) != 0 {
return &e
}
return nil
return uploadFile(client, filename, "/v1/imports/gnucash")
}
func gnucashAccountBalanceHelper(t *testing.T, client *http.Client, account *handlers.Account, balance string) {