2017-12-09 19:55:34 -05:00
|
|
|
package integration_test
|
2017-10-05 08:06:08 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/aclindsa/moneygo/internal/handlers"
|
2017-12-03 06:38:22 -05:00
|
|
|
"github.com/aclindsa/moneygo/internal/models"
|
2017-10-05 08:06:08 -04:00
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSecurityTemplates(t *testing.T) {
|
2017-12-03 06:38:22 -05:00
|
|
|
var sl models.SecurityList
|
2017-11-11 08:05:09 -05:00
|
|
|
response, err := server.Client().Get(server.URL + "/v1/securitytemplates/?search=USD&type=currency")
|
2017-10-05 08:06:08 -04:00
|
|
|
if err != nil {
|
2017-10-05 08:42:19 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if response.StatusCode != 200 {
|
|
|
|
t.Fatalf("Unexpected HTTP status code: %d\n", response.StatusCode)
|
2017-10-05 08:06:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(response.Body)
|
|
|
|
response.Body.Close()
|
|
|
|
if err != nil {
|
2017-10-05 08:42:19 -04:00
|
|
|
t.Fatal(err)
|
2017-10-05 08:06:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
err = (&sl).Read(string(body))
|
|
|
|
if err != nil {
|
2017-10-05 08:42:19 -04:00
|
|
|
t.Fatal(err)
|
2017-10-05 08:06:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
num_usd := 0
|
2017-11-12 20:17:27 -05:00
|
|
|
if sl.Securities != nil {
|
|
|
|
for _, s := range *sl.Securities {
|
2017-12-03 06:38:22 -05:00
|
|
|
if s.Type != models.Currency {
|
2017-11-12 20:17:27 -05:00
|
|
|
t.Fatalf("Requested Currency-only security templates, received a non-Currency template for %s", s.Name)
|
|
|
|
}
|
2017-10-05 08:06:08 -04:00
|
|
|
|
2017-11-12 20:17:27 -05:00
|
|
|
if s.Name == "USD" && s.AlternateId == "840" {
|
|
|
|
num_usd++
|
|
|
|
}
|
2017-10-05 08:06:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if num_usd != 1 {
|
|
|
|
t.Fatalf("Expected one USD security template, found %d\n", num_usd)
|
|
|
|
}
|
|
|
|
}
|
2017-10-05 08:42:19 -04:00
|
|
|
|
|
|
|
func TestSecurityTemplateLimit(t *testing.T) {
|
2017-12-03 06:38:22 -05:00
|
|
|
var sl models.SecurityList
|
2017-11-11 08:05:09 -05:00
|
|
|
response, err := server.Client().Get(server.URL + "/v1/securitytemplates/?search=e&limit=5")
|
2017-10-05 08:42:19 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if response.StatusCode != 200 {
|
|
|
|
t.Fatalf("Unexpected HTTP status code: %d\n", response.StatusCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(response.Body)
|
|
|
|
response.Body.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = (&sl).Read(string(body))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2017-11-12 20:17:27 -05:00
|
|
|
if sl.Securities == nil {
|
|
|
|
t.Fatalf("Securities was unexpectedly nil\n")
|
|
|
|
}
|
|
|
|
|
2017-10-05 08:42:19 -04:00
|
|
|
if len(*sl.Securities) > 5 {
|
|
|
|
t.Fatalf("Requested only 5 securities, received %d\n", len(*sl.Securities))
|
|
|
|
}
|
|
|
|
}
|
2017-10-05 21:08:17 -04:00
|
|
|
|
|
|
|
func TestSecurityTemplateInvalidType(t *testing.T) {
|
|
|
|
var e handlers.Error
|
2017-11-11 08:05:09 -05:00
|
|
|
response, err := server.Client().Get(server.URL + "/v1/securitytemplates/?search=e&type=blah")
|
2017-10-05 21:08:17 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(response.Body)
|
|
|
|
response.Body.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = (&e).Read(string(body))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if e.ErrorId != 3 {
|
|
|
|
t.Fatal("Expected ErrorId 3, Invalid Request")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSecurityTemplateInvalidLimit(t *testing.T) {
|
|
|
|
var e handlers.Error
|
2017-11-11 08:05:09 -05:00
|
|
|
response, err := server.Client().Get(server.URL + "/v1/securitytemplates/?search=e&type=Currency&limit=foo")
|
2017-10-05 21:08:17 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(response.Body)
|
|
|
|
response.Body.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = (&e).Read(string(body))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if e.ErrorId != 3 {
|
|
|
|
t.Fatal("Expected ErrorId 3, Invalid Request")
|
|
|
|
}
|
|
|
|
}
|