44 "bytes"
55 "encoding/json"
66 "fmt"
7- "io"
87 "net/http"
98 "net/http/httptest"
109 "strings"
@@ -55,18 +54,7 @@ func journalServerWithReadBehavior(t *testing.T, readBehavior string) *httptest.
5554 json .NewEncoder (w ).Encode (resp )
5655 }
5756 case r .Method == "PATCH" && strings .Contains (r .URL .Path , "/calendar/days/" ) && (strings .HasSuffix (r .URL .Path , "/journal_entry" ) || strings .HasSuffix (r .URL .Path , "/journal_entry.json" )):
58- body , _ := io .ReadAll (r .Body )
59- var req map [string ]any
60- _ = json .Unmarshal (body , & req )
61- resp := map [string ]any {
62- "id" : 1 ,
63- "content" : req ["body" ],
64- "type" : "Calendar::JournalEntry" ,
65- "title" : "Journal Entry" ,
66- "starts_at" : "2024-01-15T00:00:00Z" ,
67- }
68- w .Header ().Set ("Content-Type" , "application/json" )
69- json .NewEncoder (w ).Encode (resp )
57+ w .WriteHeader (204 )
7058 default :
7159 w .WriteHeader (200 )
7260 }
@@ -106,12 +94,8 @@ func TestJournalWritePositionalContent(t *testing.T) {
10694 t .Fatalf ("execute: %v" , err )
10795 }
10896
109- data , ok := resp .Data .(map [string ]any )
110- if ! ok {
111- t .Fatalf ("data type = %T, want map[string]any" , resp .Data )
112- }
113- if got := data ["content" ]; got != "Today was great" {
114- t .Errorf ("content = %q, want %q" , got , "Today was great" )
97+ if ! strings .Contains (resp .Summary , "Journal entry" ) {
98+ t .Errorf ("summary = %q, want to contain %q" , resp .Summary , "Journal entry" )
11599 }
116100}
117101
@@ -124,12 +108,8 @@ func TestJournalWritePositionalDateAndContent(t *testing.T) {
124108 t .Fatalf ("execute: %v" , err )
125109 }
126110
127- data , ok := resp .Data .(map [string ]any )
128- if ! ok {
129- t .Fatalf ("data type = %T, want map[string]any" , resp .Data )
130- }
131- if got := data ["content" ]; got != "Retrospective" {
132- t .Errorf ("content = %q, want %q" , got , "Retrospective" )
111+ if ! strings .Contains (resp .Summary , "2024-01-15" ) {
112+ t .Errorf ("summary = %q, want to contain date" , resp .Summary )
133113 }
134114}
135115
@@ -142,12 +122,8 @@ func TestJournalWriteShortFlag(t *testing.T) {
142122 t .Fatalf ("execute: %v" , err )
143123 }
144124
145- data , ok := resp .Data .(map [string ]any )
146- if ! ok {
147- t .Fatalf ("data type = %T, want map[string]any" , resp .Data )
148- }
149- if got := data ["content" ]; got != "Content via short flag" {
150- t .Errorf ("content = %q, want %q" , got , "Content via short flag" )
125+ if ! strings .Contains (resp .Summary , "Journal entry" ) {
126+ t .Errorf ("summary = %q, want to contain %q" , resp .Summary , "Journal entry" )
151127 }
152128}
153129
0 commit comments