mirror of
https://github.com/thomiceli/opengist.git
synced 2025-06-13 22:07:11 +02:00
Add topics for Gists (#413)
This commit is contained in:
@ -131,6 +131,7 @@ func TestAdminUser(t *testing.T) {
|
||||
},
|
||||
Name: []string{"gist1.txt"},
|
||||
Content: []string{"yeah"},
|
||||
Topics: "",
|
||||
}
|
||||
err := s.Request("POST", "/", gist1, 302)
|
||||
require.NoError(t, err)
|
||||
@ -170,6 +171,7 @@ func TestAdminGist(t *testing.T) {
|
||||
},
|
||||
Name: []string{"gist1.txt"},
|
||||
Content: []string{"yeah"},
|
||||
Topics: "",
|
||||
}
|
||||
err := s.Request("POST", "/", gist1, 302)
|
||||
require.NoError(t, err)
|
||||
|
@ -110,6 +110,7 @@ func TestAnonymous(t *testing.T) {
|
||||
},
|
||||
Name: []string{"gist1.txt", "gist2.txt", "gist3.txt"},
|
||||
Content: []string{"yeah", "yeah\ncool", "yeah\ncool gist actually"},
|
||||
Topics: "",
|
||||
}
|
||||
err = s.Request("POST", "/", gist1, 302)
|
||||
require.NoError(t, err)
|
||||
@ -165,6 +166,7 @@ func TestGitOperations(t *testing.T) {
|
||||
Content: []string{
|
||||
"yeah",
|
||||
},
|
||||
Topics: "",
|
||||
}
|
||||
err := s.Request("POST", "/", gist1, 302)
|
||||
require.NoError(t, err)
|
||||
@ -180,6 +182,7 @@ func TestGitOperations(t *testing.T) {
|
||||
Content: []string{
|
||||
"cool",
|
||||
},
|
||||
Topics: "",
|
||||
}
|
||||
err = s.Request("POST", "/", gist2, 302)
|
||||
require.NoError(t, err)
|
||||
@ -195,6 +198,7 @@ func TestGitOperations(t *testing.T) {
|
||||
Content: []string{
|
||||
"super",
|
||||
},
|
||||
Topics: "",
|
||||
}
|
||||
err = s.Request("POST", "/", gist3, 302)
|
||||
require.NoError(t, err)
|
||||
|
@ -21,7 +21,7 @@ func TestGists(t *testing.T) {
|
||||
err = s.Request("GET", "/all", nil, 200)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = s.Request("POST", "/", nil, 200)
|
||||
err = s.Request("POST", "/", nil, 400)
|
||||
require.NoError(t, err)
|
||||
|
||||
gist1 := db.GistDTO{
|
||||
@ -32,6 +32,7 @@ func TestGists(t *testing.T) {
|
||||
},
|
||||
Name: []string{"gist1.txt", "gist2.txt", "gist3.txt"},
|
||||
Content: []string{"yeah", "yeah\ncool", "yeah\ncool gist actually"},
|
||||
Topics: "",
|
||||
}
|
||||
err = s.Request("POST", "/", gist1, 302)
|
||||
require.NoError(t, err)
|
||||
@ -63,8 +64,9 @@ func TestGists(t *testing.T) {
|
||||
},
|
||||
Name: []string{"", "gist2.txt", "gist3.txt"},
|
||||
Content: []string{"", "yeah\ncool", "yeah\ncool gist actually"},
|
||||
Topics: "",
|
||||
}
|
||||
err = s.Request("POST", "/", gist2, 200)
|
||||
err = s.Request("POST", "/", gist2, 400)
|
||||
require.NoError(t, err)
|
||||
|
||||
gist3 := db.GistDTO{
|
||||
@ -75,6 +77,7 @@ func TestGists(t *testing.T) {
|
||||
},
|
||||
Name: []string{""},
|
||||
Content: []string{"yeah"},
|
||||
Topics: "",
|
||||
}
|
||||
err = s.Request("POST", "/", gist3, 302)
|
||||
require.NoError(t, err)
|
||||
@ -86,7 +89,7 @@ func TestGists(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "gistfile1.txt", gist3files[0])
|
||||
|
||||
err = s.Request("POST", "/"+gist1db.User.Username+"/"+gist1db.Uuid+"/edit", nil, 200)
|
||||
err = s.Request("POST", "/"+gist1db.User.Username+"/"+gist1db.Uuid+"/edit", nil, 400)
|
||||
require.NoError(t, err)
|
||||
|
||||
gist1.Name = []string{"gist1.txt"}
|
||||
@ -118,6 +121,7 @@ func TestVisibility(t *testing.T) {
|
||||
},
|
||||
Name: []string{""},
|
||||
Content: []string{"yeah"},
|
||||
Topics: "",
|
||||
}
|
||||
err := s.Request("POST", "/", gist1, 302)
|
||||
require.NoError(t, err)
|
||||
@ -160,6 +164,7 @@ func TestLikeFork(t *testing.T) {
|
||||
},
|
||||
Name: []string{""},
|
||||
Content: []string{"yeah"},
|
||||
Topics: "",
|
||||
}
|
||||
err := s.Request("POST", "/", gist1, 302)
|
||||
require.NoError(t, err)
|
||||
@ -220,6 +225,7 @@ func TestCustomUrl(t *testing.T) {
|
||||
},
|
||||
Name: []string{"gist1.txt", "gist2.txt", "gist3.txt"},
|
||||
Content: []string{"yeah", "yeah\ncool", "yeah\ncool gist actually"},
|
||||
Topics: "",
|
||||
}
|
||||
err := s.Request("POST", "/", gist1, 302)
|
||||
require.NoError(t, err)
|
||||
@ -251,6 +257,7 @@ func TestCustomUrl(t *testing.T) {
|
||||
},
|
||||
Name: []string{"gist1.txt", "gist2.txt", "gist3.txt"},
|
||||
Content: []string{"yeah", "yeah\ncool", "yeah\ncool gist actually"},
|
||||
Topics: "",
|
||||
}
|
||||
err = s.Request("POST", "/", gist2, 302)
|
||||
require.NoError(t, err)
|
||||
@ -261,3 +268,75 @@ func TestCustomUrl(t *testing.T) {
|
||||
require.Equal(t, gist2db.Uuid, gist2db.Identifier())
|
||||
require.NotEqual(t, gist2db.URL, gist2db.Identifier())
|
||||
}
|
||||
|
||||
func TestTopics(t *testing.T) {
|
||||
s := Setup(t)
|
||||
defer Teardown(t, s)
|
||||
|
||||
user1 := db.UserDTO{Username: "thomas", Password: "thomas"}
|
||||
register(t, s, user1)
|
||||
|
||||
gist1 := db.GistDTO{
|
||||
Title: "gist1",
|
||||
URL: "my-gist",
|
||||
Description: "my first gist",
|
||||
VisibilityDTO: db.VisibilityDTO{
|
||||
Private: 0,
|
||||
},
|
||||
Name: []string{"gist1.txt", "gist2.txt", "gist3.txt"},
|
||||
Content: []string{"yeah", "yeah\ncool", "yeah\ncool gist actually"},
|
||||
Topics: "topic1 topic2 topic3",
|
||||
}
|
||||
err := s.Request("POST", "/", gist1, 302)
|
||||
require.NoError(t, err)
|
||||
|
||||
gist1db, err := db.GetGistByID("1")
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, []db.GistTopic{
|
||||
{GistID: 1, Topic: "topic1"},
|
||||
{GistID: 1, Topic: "topic2"},
|
||||
{GistID: 1, Topic: "topic3"},
|
||||
}, gist1db.Topics)
|
||||
|
||||
gist2 := db.GistDTO{
|
||||
Title: "gist2",
|
||||
URL: "my-gist",
|
||||
Description: "my second gist",
|
||||
VisibilityDTO: db.VisibilityDTO{
|
||||
Private: 0,
|
||||
},
|
||||
Name: []string{"gist1.txt", "gist2.txt", "gist3.txt"},
|
||||
Content: []string{"yeah", "yeah\ncool", "yeah\ncool gist actually"},
|
||||
Topics: "topic1 topic2 topic3 topic2 topic4 topic1",
|
||||
}
|
||||
err = s.Request("POST", "/", gist2, 302)
|
||||
require.NoError(t, err)
|
||||
|
||||
gist2db, err := db.GetGistByID("2")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []db.GistTopic{
|
||||
{GistID: 2, Topic: "topic1"},
|
||||
{GistID: 2, Topic: "topic2"},
|
||||
{GistID: 2, Topic: "topic3"},
|
||||
{GistID: 2, Topic: "topic4"},
|
||||
}, gist2db.Topics)
|
||||
|
||||
gist3 := db.GistDTO{
|
||||
Title: "gist3",
|
||||
URL: "my-gist",
|
||||
Description: "my third gist",
|
||||
VisibilityDTO: db.VisibilityDTO{
|
||||
Private: 0,
|
||||
},
|
||||
Name: []string{"gist1.txt", "gist2.txt", "gist3.txt"},
|
||||
Content: []string{"yeah", "yeah\ncool", "yeah\ncool gist actually"},
|
||||
Topics: "topic1 topic2 topic3 topic4 topic5 topic6 topic7 topic8 topic9 topic10 topic11",
|
||||
}
|
||||
err = s.Request("POST", "/", gist3, 400)
|
||||
require.NoError(t, err)
|
||||
|
||||
gist3.Topics = "topictoolongggggggggggggggggggggggggggggggggggggggg"
|
||||
err = s.Request("POST", "/", gist3, 400)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user