Skip to content

Commit

Permalink
chore(allsrv): adding test for update foo API
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jsteenb2 committed Jul 5, 2024
1 parent 526c39c commit 1e34905
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions allsrv/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1e34905

Please sign in to comment.