LaunchCodeLiftoffProjects / LaunchCodeLiftoffProjects/Collab-Blog
Writing a test for the /blog/update endpoint
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 8
- Forks
- 20
- PR merge metrics
- No merged PRs in 30d
Description
**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();
}
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with BlogTests.Java and the existing postBlogs_SavesBlogToDatabase test to understand the test setup and database cleanup. Confirm whether the intended target is /blog/update or the /blogs endpoint shown in the context, then cover updating existing database information and verify the updated result and persistence.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend, database, testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100