-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Mapper test - category package complete now
- Loading branch information
1 parent
fc2da66
commit 3919746
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
server/src/test/java/org/hyperskill/community/flashcards/category/CategoryMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.hyperskill.community.flashcards.category; | ||
|
||
import org.hyperskill.community.flashcards.category.mapper.CategoryMapper; | ||
import org.hyperskill.community.flashcards.category.model.Category; | ||
import org.hyperskill.community.flashcards.category.model.CategoryAccess; | ||
import org.hyperskill.community.flashcards.common.response.ActionType; | ||
import org.hyperskill.community.flashcards.common.response.PermittedAction; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Set; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class CategoryMapperTest { | ||
|
||
CategoryMapper mapper; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
mapper = new CategoryMapper("user"); | ||
} | ||
|
||
@Test | ||
void permittedUser_mapsCorrectly() { | ||
var category = createCategory("user", "rwd"); | ||
var dto = mapper.categoryToCategoryDto(category); | ||
assertEquals(category.id(), dto.id()); | ||
assertEquals(category.name(), dto.name()); | ||
var expectedPermissions = Set.of( | ||
new PermittedAction(ActionType.READ, "/api/categories/12345"), | ||
new PermittedAction(ActionType.WRITE, "/api/categories/12345"), | ||
new PermittedAction(ActionType.DELETE, "/api/categories/12345")); | ||
assertEquals(expectedPermissions, dto.actions()); | ||
} | ||
|
||
@Test | ||
void notPermittedUser_mapThrows() { | ||
var category = createCategory("other", "rw"); | ||
assertThrows(IllegalStateException.class, () -> mapper.categoryToCategoryDto(category)); | ||
} | ||
|
||
private Category createCategory( String username, String permissions) { | ||
return new Category("12345", "test", Set.of(new CategoryAccess(username, permissions))); | ||
} | ||
|
||
} |