From 1e3490587a9a8b204bfe4b3b5c41193ba5eb09ab Mon Sep 17 00:00:00 2001 From: Johnny Steenbergen Date: Sat, 13 Jan 2024 19:11:07 -0600 Subject: [PATCH] chore(allsrv): adding test for update foo API The key takeaway here is the response is a nothing burger. We can only ever test the status code atm. These leaves a lot to be desired. As a service evolves to cover a broader domain, these types tend to grow. We don't see anything in an empty response however. At the moment we're kind of stuck though. We don't have a means to add a new API that is distinguished from the existing. We'll come back to this. --- allsrv/server_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/allsrv/server_test.go b/allsrv/server_test.go index e50054e..99f930b 100644 --- a/allsrv/server_test.go +++ b/allsrv/server_test.go @@ -72,6 +72,33 @@ func TestServer(t *testing.T) { }) }) }) + + t.Run("foo update", func(t *testing.T) { + t.Run("when updating an existing foo with valid changes should pass", func(t *testing.T) { + db := new(allsrv.InmemDB) + err := db.CreateFoo(allsrv.Foo{ + ID: "id1", + Name: "first_name", + Note: "first note", + }) + require.NoError(t, err) + + svr := allsrv.NewServer(db, "dodgers@stink.com", "PaSsWoRd") + + req := httptest.NewRequest("PUT", "/foo", newJSONBody(t, allsrv.Foo{ + ID: "id1", + Name: "second_name", + Note: "second note", + })) + req.SetBasicAuth("dodgers@stink.com", "PaSsWoRd") + rec := httptest.NewRecorder() + + svr.ServeHTTP(rec, req) + + // note: lame we don't get the updated foo back + assert.Equal(t, http.StatusOK, rec.Code) + }) + }) } func newJSONBody(t *testing.T, v any) *bytes.Buffer {