-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #185 material services tests finished
- Loading branch information
1 parent
24f36f0
commit bec20f7
Showing
8 changed files
with
126 additions
and
8 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
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
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
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
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
1 change: 0 additions & 1 deletion
1
...backend/src/test/groovy/unit/infrastructure/module/material/MaterialControllerSpec.groovy
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
44 changes: 44 additions & 0 deletions
44
...kend/src/test/groovy/unit/infrastructure/module/material/MaterialStatusServiceSpec.groovy
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,44 @@ | ||
package unit.infrastructure.module.material | ||
|
||
import factory.MaterialFactory | ||
import io.vavr.Tuple2 | ||
import io.vavr.control.Try | ||
import org.spockframework.util.Assert | ||
import org.springframework.security.core.authority.SimpleGrantedAuthority | ||
import pl.sknikod.kodemybackend.infrastructure.database.Material | ||
import pl.sknikod.kodemybackend.infrastructure.module.material.MaterialStatusService | ||
import pl.sknikod.kodemybackend.infrastructure.store.MaterialStore | ||
import pl.sknikod.kodemycommons.security.UserPrincipal | ||
import pl.sknikod.kodemycommons.util.PrincipalUtil | ||
import spock.lang.Specification | ||
|
||
class MaterialStatusServiceSpec extends Specification { | ||
def materialStore = Mock(MaterialStore) | ||
def principalUtil = Mock(PrincipalUtil) | ||
|
||
def material = MaterialFactory.create() | ||
|
||
def materialStatusService = new MaterialStatusService(materialStore, principalUtil) | ||
|
||
def "shouldUpdate"() { | ||
given: | ||
material.status = Material.MaterialStatus.PENDING | ||
materialStore.findById(1L, true) | ||
>> Try.success(new MaterialStore.FindByIdObject( | ||
material, "user", 3.0D, new ArrayList<Long>() | ||
)) | ||
materialStore.changeStatus(1L, Material.MaterialStatus.APPROVED) | ||
>> Try.success(new Tuple2<>(1L, Material.MaterialStatus.APPROVED)) | ||
principalUtil.getPrincipal() >> Optional.of(new UserPrincipal( | ||
1L, "name", new ArrayList<SimpleGrantedAuthority>( | ||
List.of(new SimpleGrantedAuthority("CAN_APPROVED_MATERIAL")) | ||
) | ||
)) | ||
|
||
when: | ||
def result = materialStatusService.update(1L, Material.MaterialStatus.APPROVED) | ||
|
||
then: | ||
Assert.that(result == Material.MaterialStatus.APPROVED) | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...kend/src/test/groovy/unit/infrastructure/module/material/MaterialUpdateServiceSpec.groovy
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,75 @@ | ||
package unit.infrastructure.module.material | ||
|
||
import factory.MaterialFactory | ||
import io.vavr.control.Try | ||
import org.spockframework.util.Assert | ||
import org.springframework.security.core.authority.SimpleGrantedAuthority | ||
import pl.sknikod.kodemybackend.infrastructure.database.Material | ||
import pl.sknikod.kodemybackend.infrastructure.module.material.MaterialUpdateService | ||
import pl.sknikod.kodemybackend.infrastructure.store.CategoryStore | ||
import pl.sknikod.kodemybackend.infrastructure.store.MaterialStore | ||
import pl.sknikod.kodemybackend.infrastructure.store.TagStore | ||
import pl.sknikod.kodemybackend.infrastructure.store.TypeStore | ||
import pl.sknikod.kodemycommons.security.UserPrincipal | ||
import pl.sknikod.kodemycommons.util.PrincipalUtil | ||
import spock.lang.Specification | ||
|
||
class MaterialUpdateServiceSpec extends Specification { | ||
def updateMaterialMapper = Mock(MaterialUpdateService.MaterialUpdateMapper) | ||
def categoryStore = Mock(CategoryStore) | ||
def typeStore = Mock(TypeStore) | ||
def tagStore = Mock(TagStore) | ||
def materialStore = Mock(MaterialStore) | ||
def principalUtil = Mock(PrincipalUtil) | ||
|
||
def material = MaterialFactory.create() | ||
|
||
def materialUpdateService = new MaterialUpdateService( | ||
updateMaterialMapper, | ||
categoryStore, | ||
typeStore, | ||
tagStore, | ||
materialStore, | ||
principalUtil | ||
) | ||
|
||
def "shouldUpdate"() { | ||
given: | ||
materialStore.findById(1L, true) | ||
>> Try.success(new MaterialStore.FindByIdObject( | ||
material, "user", 3.0D, new ArrayList<Long>() | ||
)) | ||
categoryStore.findById(1L) >> Try.success(material.category) | ||
typeStore.findById(1L) >> Try.success(material.type) | ||
tagStore.findAllByIdIn(List.of(1L)) >> Try.success(material.tags) | ||
materialStore.update(_ as Material) >> Try.success(material) | ||
def response = new MaterialUpdateService.MaterialUpdateResponse( | ||
material.id, material.title, | ||
material.description, material.link, | ||
new MaterialUpdateService.MaterialUpdateResponse.BaseDetails( | ||
material.category.id, material.category.name | ||
), | ||
new MaterialUpdateService.MaterialUpdateResponse.BaseDetails( | ||
material.type.id, material.type.name | ||
), | ||
Set.of(new MaterialUpdateService.MaterialUpdateResponse.BaseDetails( | ||
1L, "name" | ||
))) | ||
updateMaterialMapper.map(_ as Material) | ||
>> response | ||
principalUtil.getPrincipal() >> Optional.of(new UserPrincipal( | ||
1L, "name", List.of(new SimpleGrantedAuthority( | ||
"CAN_AUTO_APPROVED_MATERIAL" | ||
))) | ||
) | ||
|
||
when: | ||
def result = materialUpdateService.update(1L, | ||
new MaterialUpdateService.MaterialUpdateRequest( | ||
"title", "desc", "link", 1L, 1L, List.of(1L) | ||
)) | ||
|
||
then: | ||
Assert.that(result == response) | ||
} | ||
} |