@@ -12,9 +12,10 @@ import (
1212func TestConvertPostNotification (t * testing.T ) {
1313 relatesTo := & event.RelatesTo {}
1414 tests := []struct {
15- name string
16- metadata map [string ]string
17- expected string
15+ name string
16+ metadata map [string ]string
17+ expected string
18+ expectedHTML string
1819 }{
1920 {
2021 name : "note with multiline preview and link" ,
@@ -25,16 +26,22 @@ func TestConvertPostNotification(t *testing.T) {
2526 },
2627 expected : "You received a LINE note.\n \n Preview:\n First line\n Second line\n \n " +
2728 "Open in LINE: https://line.me/R/group/home/posts/post?example=1" ,
29+ expectedHTML : "You received a LINE note.<br><br>Preview:<br>First line<br>Second line<br><br>" +
30+ `Open in LINE: <a href="https://line.me/R/group/home/posts/post?example=1">` +
31+ "https://line.me/R/group/home/posts/post?example=1</a>" ,
2832 },
2933 {
30- name : "album with name and deep link" ,
34+ name : "album with escaped name and deep link" ,
3135 metadata : map [string ]string {
3236 "serviceType" : "AB" ,
33- "albumName" : "Summer photos" ,
34- "postEndUrl" : "line://group/home/albums/album?example=1" ,
37+ "albumName" : "Summer < photos> " ,
38+ "postEndUrl" : "line://group/home/albums/album?example=1&source=chat " ,
3539 },
36- expected : "LINE album update: Summer photos\n \n " +
37- "Open in LINE: line://group/home/albums/album?example=1" ,
40+ expected : "LINE album update: Summer <photos>\n \n " +
41+ "Open in LINE: line://group/home/albums/album?example=1&source=chat" ,
42+ expectedHTML : "LINE album update: Summer <photos><br><br>" +
43+ `Open in LINE: <a href="line://group/home/albums/album?example=1&source=chat">` +
44+ "line://group/home/albums/album?example=1&source=chat</a>" ,
3845 },
3946 {
4047 name : "missing metadata" ,
@@ -60,12 +67,12 @@ func TestConvertPostNotification(t *testing.T) {
6067 if err != nil {
6168 t .Fatalf ("ConvertPostNotification returned error: %v" , err )
6269 }
63- assertPostNotificationContent (t , converted , test .expected , relatesTo )
70+ assertPostNotificationContent (t , converted , test .expected , test . expectedHTML , relatesTo )
6471 })
6572 }
6673}
6774
68- func assertPostNotificationContent (t * testing.T , converted * bridgev2.ConvertedMessage , expectedBody string , relatesTo * event.RelatesTo ) {
75+ func assertPostNotificationContent (t * testing.T , converted * bridgev2.ConvertedMessage , expectedBody , expectedHTML string , relatesTo * event.RelatesTo ) {
6976 t .Helper ()
7077 if converted == nil || len (converted .Parts ) != 1 || converted .Parts [0 ].Content == nil {
7178 t .Fatalf ("converted = %#v, want one message part" , converted )
@@ -80,6 +87,18 @@ func assertPostNotificationContent(t *testing.T, converted *bridgev2.ConvertedMe
8087 if part .Content .Body != expectedBody {
8188 t .Fatalf ("body = %q, want %q" , part .Content .Body , expectedBody )
8289 }
90+ if expectedHTML == "" {
91+ if part .Content .Format != "" || part .Content .FormattedBody != "" {
92+ t .Fatalf ("formatted message = %q / %q, want plain text only" , part .Content .Format , part .Content .FormattedBody )
93+ }
94+ } else {
95+ if part .Content .Format != event .FormatHTML {
96+ t .Fatalf ("format = %q, want %q" , part .Content .Format , event .FormatHTML )
97+ }
98+ if part .Content .FormattedBody != expectedHTML {
99+ t .Fatalf ("formatted body = %q, want %q" , part .Content .FormattedBody , expectedHTML )
100+ }
101+ }
83102 if part .Content .RelatesTo != relatesTo {
84103 t .Fatalf ("relates_to = %#v, want original pointer %#v" , part .Content .RelatesTo , relatesTo )
85104 }
0 commit comments