Skip to content

Writing a test for the /blog/update endpoint #29

Description

@jwoolbright23

Is your feature request related to a problem? Please describe.
The /blog/update endpoint is in need of a unit test.

Describe the solution you'd like
Write a test that successfully updates already existing information inside of the database to something new.

Additional context
This is a test written inside of BlogTests.Java to test the @PostMapping /blogs endpoint.

@Test
	public void postBlogs_SavesBlogToDatabase() throws Exception {
		blogTestsUtil.tearDown();
		Blog blog1 = new Blog("Our Very First Blog Post", "This is an actual Subheader", "An Actual Image", "This body has things we actually care about");
		MockMultipartFile firstFile = new MockMultipartFile("image", "filename.txt", "text/plain", "some xml".getBytes());
		MvcResult result = mockMvc.perform(multipart("/blogs").file(firstFile).param("blogData", objectMapper.writeValueAsString(blog1)))
				.andDo(print())
				.andExpect(status().isOk())
				.andExpect(jsonPath("$.header").value("Our Very First Blog Post"))
				.andReturn();
		assertEquals(1, blogRepository.findAll().size());
		blogTestsUtil.tearDown();
	}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    JUnitWriting tests for new end points

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions