package api import ( "TheAdversary/database" "net/http" "net/http/httptest" "testing" "time" ) func TestDelete(t *testing.T) { if err := initTestDatabase("delete_test.sqlite3"); err != nil { t.Fatal(err) } database.GetDB().Table("article").Create([]map[string]interface{}{ { "title": "test", "summary": "test summary", "image": "https://upload.wikimedia.org/wikipedia/commons/0/05/Go_Logo_Blue.svg", "created": time.Now().Unix(), "modified": time.Now().Unix(), "link": "/article/test", "markdown": "# Title", "html": "

Title

", }, { "title": "owo", "created": time.Now().Unix(), "link": "/article/owo", "markdown": "owo", "html": "

owo

", }, }) database.GetDB().Table("author").Create(map[string]interface{}{ "name": "test", "password": "", }) database.GetDB().Table("article_author").Create([]map[string]interface{}{ { "article_id": 1, "author_id": 1, }, { "article_id": 2, "author_id": 1, }, }) server := httptest.NewServer(http.HandlerFunc(Delete)) checkTestInformation(t, server.URL, []testInformation{ { Method: http.MethodPost, Code: http.StatusUnauthorized, }, { Method: http.MethodPost, Body: deletePayload{ Id: 1, }, Code: http.StatusUnauthorized, }, { Method: http.MethodPost, Body: deletePayload{ Id: 1, }, Cookie: map[string]string{ "session_id": initSession(), }, Code: http.StatusOK, }, { Method: http.MethodPost, Body: deletePayload{ Id: 69, }, Cookie: map[string]string{ "session_id": initSession(), }, Code: http.StatusNotFound, }, }) }