-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/edit put book #7
Conversation
This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation. |
.contentType("application/json") | ||
.content(""" | ||
{ | ||
"id": "1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to update (or change) the value of id
? If the id
is not changed after creation, do we need to add it as a payload for the PUT method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes id should not be part of payload
// GIVEN | ||
bookRepository.save(new Book("1", "author1", "title1", Genre.FANTASY, "description1", "12345678", "cover1", localDate)); | ||
|
||
Book updatedBook = new Book("1", "author2", "title2", Genre.HISTORY, "description2", "23456789", "cover2", localDate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable is not used in the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the hint, i change that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can also leave frontend as is and do that later
.contentType("application/json") | ||
.content(""" | ||
{ | ||
"id": "1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes id should not be part of payload
|
||
// When | ||
when(bookRepo.findById(id)).thenReturn(Optional.of(existingBook)); | ||
when(bookRepo.save(any(Book.class))).thenAnswer(invocation -> invocation.getArguments()[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would simplify it and just also have an updatedBook of type Book (and rename updatedBook to updatedBookDto)
when(bookRepo.save(any(Book.class))).thenAnswer(invocation -> invocation.getArguments()[0]); | |
when(bookRepo.save(updatedBook).thenAnswer(updatedBook); |
// Given | ||
String id = "1"; | ||
Book existingBook = new Book(id, "author1", "title1", Genre.THRILLER, "description1", "12345678", "cover1", localDate); | ||
BookDto updatedBook = new BookDto("author2", "title2", Genre.FICTION, "description2", "23456789", "cover2", localDate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BookDto updatedBook = new BookDto("author2", "title2", Genre.FICTION, "description2", "23456789", "cover2", localDate); | |
BookDto updatedBookDto = new BookDto("author2", "title2", Genre.FICTION, "description2", "23456789", "cover2", localDate); | |
Book updatedBook = new Book("1","author2", "title2", Genre.FICTION, "description2", "23456789", "cover2", localDate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment below
when(bookRepo.findById(id)).thenReturn(Optional.of(existingBook)); | ||
when(bookRepo.save(any(Book.class))).thenAnswer(invocation -> invocation.getArguments()[0]); | ||
|
||
Book result = bookService.updateBook(updatedBook, id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Book result = bookService.updateBook(updatedBook, id); | |
Book result = bookService.updateBook(updatedBookDto, id); |
|
||
// Then | ||
assertNotNull(result); | ||
assertEquals(updatedBook.title(), result.title()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then just here, instead of testing every property
assertEquals(updatedBook.title(), result.title()); | |
assertEquals(updatedBook, result); |
//Then | ||
BookNotFoundException thrown = assertThrows( | ||
BookNotFoundException.class, | ||
() -> bookService.updateBook(updatedBook, id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
() -> bookService.updateBook(updatedBook, id) | |
() -> bookService.updateBook(updatedBookDto, id) |
); | ||
assertEquals("No book found with id: " + id, thrown.getMessage()); | ||
verify(bookRepo).findById(id); | ||
verify(bookRepo, never()).save(any(Book.class)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verify(bookRepo, never()).save(any(Book.class)); | |
verify(bookRepo, never()).save(updatedBook); |
<label>Description: </label> | ||
<textarea rows={5} cols={30} placeholder={book.description} name="description" value={formData.description} | ||
onChange={handleChange}/> | ||
<label>Genre: <input placeholder={book.genre} type="text" name="genre" value={formData.genre} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be select with options to match addBook form, but we can also add that later
} | ||
|
||
function onCancel() { | ||
console.log("cancel") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add original book info back into the form?
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm :)
added a edit form to update books with integration and unit tests