func TestWriteUnauthorized(t *testing.T) { var response = httptest.NewRecorder() var request = postRequest(t, "/someFile", "") var store = mockstore.New() var sut = createSut(store) sut.ServeHTTP(response, request) assertResponseBodyNotEmpty(t, response) assertResponseCode(t, response, http.StatusUnauthorized) }
func TestCreateUIMissingWritePermission(t *testing.T) { var response = httptest.NewRecorder() var request = getRequest(t, "/someFile?create") var store = mockstore.New() var sut = createSut(store) store.GivenNotExists() sut.ServeHTTP(response, request) assertResponseBodyNotEmpty(t, response) assertResponseCode(t, response, http.StatusUnauthorized) }
func TestCreateUIAlreadyExists(t *testing.T) { var response = httptest.NewRecorder() var request = getRequest(t, "/someFile?create") var store = mockstore.New() var sut = createSut(store) store.GivenWriteAccess() store.GivenMimeType("text/plain") sut.ServeHTTP(response, request) assertResponseBodyNotEmpty(t, response) assertResponseCode(t, response, http.StatusConflict) }
func TestCreateUISuccess(t *testing.T) { var response = httptest.NewRecorder() var request = getRequest(t, "/someFile?create") var store = mockstore.New() var sut = createSut(store) store.GivenWriteAccess() store.GivenNotExists() sut.ServeHTTP(response, request) assertResponseBodyNotEmpty(t, response) assertResponseCode(t, response, http.StatusOK) }
func TestEditUIMissingWritePermission(t *testing.T) { var response = httptest.NewRecorder() var request = getRequest(t, "/someFile?edit") var store = mockstore.New() var sut = createSut(store) store.GivenReadAccess() store.GivenMimeType("text/plain") sut.ServeHTTP(response, request) assertResponseBodyNotEmpty(t, response) assertResponseCode(t, response, http.StatusUnauthorized) }
func TestWriteSuccess(t *testing.T) { var response = httptest.NewRecorder() var request = postRequest(t, "/someFile", "") var store = mockstore.New() var sut = createSut(store) request.PostForm.Set("content", "content") store.GivenWriteAccess() sut.ServeHTTP(response, request) assertResponseBody(t, response, "") assertResponseCode(t, response, http.StatusFound) assertResponseHeader(t, response, "Location", "/someFile?edit") }