diff options
author | Debanshu Kundu <debanshu.kundu@joshtechnologygroup.com> | 2017-01-20 23:11:13 +0530 |
---|---|---|
committer | enahum <nahumhbl@gmail.com> | 2017-01-20 14:41:13 -0300 |
commit | 3aaf71fdea914af1a7f2b2fb97bb6ae44132fcc4 (patch) | |
tree | b954407a03a6c0ed9836d8b14d910fc52c8dc1dc /api/post_test.go | |
parent | fefe4b70d9e69910a8e3acd6890497553b5eff2f (diff) | |
download | chat-3aaf71fdea914af1a7f2b2fb97bb6ae44132fcc4.tar.gz chat-3aaf71fdea914af1a7f2b2fb97bb6ae44132fcc4.tar.bz2 chat-3aaf71fdea914af1a7f2b2fb97bb6ae44132fcc4.zip |
#4257 Added functionality to create previews for post links using open graph data from those links. (#4890)
Diffstat (limited to 'api/post_test.go')
-rw-r--r-- | api/post_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/api/post_test.go b/api/post_test.go index 4d3ee80b5..d382786cc 100644 --- a/api/post_test.go +++ b/api/post_test.go @@ -5,6 +5,7 @@ package api import ( "encoding/json" + "fmt" "net/http" "net/http/httptest" "net/url" @@ -1298,3 +1299,33 @@ func TestGetPermalinkTmp(t *testing.T) { t.Fatal("should not be empty") } } + +func TestGetOpenGraphMetadata(t *testing.T) { + th := Setup().InitBasic() + Client := th.BasicClient + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path == "/og-data/" { + fmt.Fprintln(w, ` + <html><head><meta property="og:type" content="article" /> + <meta property="og:title" content="Test Title" /> + <meta property="og:url" content="http://example.com/" /> + </head><body></body></html> + `) + } else if r.URL.Path == "/no-og-data/" { + fmt.Fprintln(w, `<html><head></head><body></body></html>`) + } + })) + + for _, data := range [](map[string]string){{"path": "/og-data/", "title": "Test Title"}, {"path": "/no-og-data/", "title": ""}} { + res, err := Client.DoApiPost("/get_opengraph_metadata", fmt.Sprintf("{\"url\":\"%s\"}", ts.URL+data["path"])) + if err != nil { + t.Fatal(err) + } + + ogData := model.StringInterfaceFromJson(res.Body) + if strings.Compare(ogData["title"].(string), data["title"]) != 0 { + t.Fatal(fmt.Sprintf("OG data title mismatch for path \"%s\". Expected title: \"%s\". Actual title: \"%s\"", data["path"], data["title"], ogData["title"])) + } + } +} |