(t *testing.T)
| 258 | } |
| 259 | |
| 260 | func TestGetBookNonOwner(t *testing.T) { |
| 261 | db := testutils.InitMemoryDB(t) |
| 262 | |
| 263 | // Setup |
| 264 | a := app.NewTest() |
| 265 | a.DB = db |
| 266 | a.Clock = clock.NewMock() |
| 267 | server := MustNewServer(t, &a) |
| 268 | defer server.Close() |
| 269 | |
| 270 | user := testutils.SetupUserData(db, "alice@test.com", "pass1234") |
| 271 | nonOwner := testutils.SetupUserData(db, "bob@test.com", "pass1234") |
| 272 | |
| 273 | b1 := database.Book{ |
| 274 | UUID: testutils.MustUUID(t), |
| 275 | UserID: user.ID, |
| 276 | Label: "js", |
| 277 | } |
| 278 | testutils.MustExec(t, db.Save(&b1), "preparing b1") |
| 279 | |
| 280 | // Execute |
| 281 | endpoint := fmt.Sprintf("/api/v3/books/%s", b1.UUID) |
| 282 | req := testutils.MakeReq(server.URL, "GET", endpoint, "") |
| 283 | res := testutils.HTTPAuthDo(t, db, req, nonOwner) |
| 284 | |
| 285 | // Test |
| 286 | assert.StatusCodeEquals(t, res, http.StatusNotFound, "") |
| 287 | |
| 288 | body, err := io.ReadAll(res.Body) |
| 289 | if err != nil { |
| 290 | t.Fatal(errors.Wrap(err, "reading body")) |
| 291 | } |
| 292 | assert.DeepEqual(t, string(body), "", "payload mismatch") |
| 293 | } |
| 294 | |
| 295 | func TestCreateBook(t *testing.T) { |
| 296 | t.Run("success", func(t *testing.T) { |
nothing calls this directly
no test coverage detected