Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Sep 12, 2024
1 parent c8a5aee commit e82424b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import spock.lang.Specification

class ManagementUnitControllerSpec extends Specification implements ControllerUnitTest<ManagementUnitController>, DataTest {
ManagementUnitService managementUnitService = Mock(ManagementUnitService)
ElasticSearchService elasticSearchService = Mock(ElasticSearchService)

def setup() {
controller.managementUnitService = managementUnitService
controller.elasticSearchService = elasticSearchService
mockDomain ManagementUnit
mockDomain GeographicInfo
}
Expand Down Expand Up @@ -167,10 +169,37 @@ class ManagementUnitControllerSpec extends Specification implements ControllerUn
}
}

def "Updating a MU will cause projects to be reindexed"() {
setup:
Map props = [
name:'Test',
description:'Test description',
url:'https://www.mu.org',
startDate:'2019-01-01T00:00:00Z',
endDate:'2023-06-30T14:00:00Z',
priorities:[[category:"Threatened species", priority:"Hibiscus brennanii"]],
outcomes:[[outcome:"outcome 1", priorities: [category:"Threatened species"]]],
managementUnitSiteId:'site1',
config:[config1:'1', config2:'2']
]

when:
request.method = 'POST'
request.json = [name:'Test 2']
controller.update('1')

then:
1 * managementUnitService.get(_) >> {new ManagementUnit(props)}
1 * managementUnitService.save(_) >> {new ManagementUnit(props+[name:'Test 2'])}
1 * elasticSearchService.reindexProjectsWithCriteriaAsync([managementUnitId:'1'])
}


def "to test GeographicInfo saving and conversion of it from map to an object"() {

setup:
Map props = [
managementUnitId: '1',
name:'Test',
description:'Test description',
url:'https://www.mu.org',
Expand Down
4 changes: 4 additions & 0 deletions src/test/groovy/au/org/ala/ecodata/ProgramServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import spock.lang.Specification
class ProgramServiceSpec extends MongoSpec implements ServiceUnitTest<ProgramService> {

CommonService commonService = new CommonService()
ElasticSearchService elasticSearchService = Mock(ElasticSearchService)

def setup() {
commonService.grailsApplication = grailsApplication
commonService.messageSource = Mock(MessageSource)
service.commonService = commonService
service.elasticSearchService = elasticSearchService


Program.findAll().each { it.delete(flush:true) }
}
Expand Down Expand Up @@ -56,6 +59,7 @@ class ProgramServiceSpec extends MongoSpec implements ServiceUnitTest<ProgramSer
program.externalIds.size() == 1
program.externalIds[0].idType == ExternalId.IdType.GRANT_AWARD
program.externalIds[0].externalId == "e1"
1 * elasticSearchService.reindexProjectsWithCriteriaAsync([programId:'1'])
}

void "update existing Parent with new parent program"(){
Expand Down

0 comments on commit e82424b

Please sign in to comment.