1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-12-26 23:42:29 -05:00

testing: Add session deletion test

This commit is contained in:
Aaron Lindsay 2017-10-11 05:49:41 -04:00
parent e781e9861b
commit 52ee17dae8
2 changed files with 41 additions and 3 deletions

View File

@ -162,7 +162,7 @@ func TestDeleteSecurity(t *testing.T) {
t.Fatalf("Expected error fetching deleted security") t.Fatalf("Expected error fetching deleted security")
} }
if herr, ok := err.(*handlers.Error); ok { if herr, ok := err.(*handlers.Error); ok {
if herr.ErrorId != 3 { if herr.ErrorId != 3 { // Invalid requeset
t.Fatalf("Unexpected API error fetching deleted security: %s", herr) t.Fatalf("Unexpected API error fetching deleted security: %s", herr)
} }
} else { } else {

View File

@ -27,8 +27,12 @@ func newSession(user *User) (*http.Client, error) {
func getSession(client *http.Client) (*handlers.Session, error) { func getSession(client *http.Client) (*handlers.Session, error) {
var s handlers.Session var s handlers.Session
read(client, &s, "/session/", "session") err := read(client, &s, "/session/", "session")
return &s, nil return &s, err
}
func deleteSession(client *http.Client) error {
return remove(client, "/session/", "session")
} }
func sessionExistsOrError(c *http.Client) error { func sessionExistsOrError(c *http.Client) error {
@ -79,3 +83,37 @@ func TestGetSession(t *testing.T) {
} }
}) })
} }
func TestDeleteSession(t *testing.T) {
RunWith(t, &data[0], func(t *testing.T, d *TestData) {
err := deleteSession(d.clients[0])
if err != nil {
t.Fatalf("Unexpected error removing session: %s\n", err)
}
err = deleteSession(d.clients[0])
if err != nil {
t.Fatalf("Unexpected error attempting to delete nonexistent session: %s\n", err)
}
_, err = getSession(d.clients[0])
if err == nil {
t.Fatalf("Expected error fetching deleted session")
}
if herr, ok := err.(*handlers.Error); ok {
if herr.ErrorId != 1 { // Not Signed in
t.Fatalf("Unexpected API error fetching deleted session: %s", herr)
}
} else {
t.Fatalf("Unexpected error fetching deleted session")
}
// Login again so we don't screw up the TestData teardown code
userWithPassword := d.users[0]
userWithPassword.Password = data[0].users[0].Password
client, err := newSession(&userWithPassword)
if err != nil {
t.Fatalf("Unexpected error re-creating session: %s\n", err)
}
d.clients[0] = client
})
}