Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added a test case
  • Loading branch information
temi committed Nov 12, 2021
1 parent 5339d3c commit a376a52
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package au.org.ala.biocollect

import au.org.ala.biocollect.merit.WebService
import grails.test.mixin.TestFor
import org.apache.http.HttpStatus
import spock.lang.Specification
Expand All @@ -17,6 +18,7 @@ class DownloadControllerSpec extends Specification {
File hubPath
File modelPath
File configPath
WebService webService

void setup() {

Expand All @@ -32,6 +34,7 @@ class DownloadControllerSpec extends Specification {
configPath.mkdir()

controller.grailsApplication.config.app.file.script.path = scriptsPath.getAbsolutePath()
controller.grailsApplication.config.ecodata.service.url = ""

// Setup three files, one that should be accessible, and others that should not
File validFile = new File(modelPath, "validFile.js")
Expand Down Expand Up @@ -145,4 +148,24 @@ class DownloadControllerSpec extends Specification {
new File("${scriptsPath}${File.separator}${params.hub}${File.separator}${params.model}", params.filename).exists()
response.status == HttpStatus.SC_NOT_FOUND
}

def "Data can be downloaded for a created file if id and file extension is provided"(String inputFormat, String expectedOutputFormat) {
setup:
String projectId = 'p1'
controller.webService = webService = Mock(WebService)

when:
params.id = projectId
params.fileExtension = inputFormat
Map result = controller.downloadProjectDataFile()

then:
1 * webService.proxyGetRequest(response, '/search/downloadProjectDataFile/'+projectId+'?fileExtension='+expectedOutputFormat, true, true)
result == null

where:
inputFormat | expectedOutputFormat
'zip' | 'zip'
'' | 'zip'
}
}

0 comments on commit a376a52

Please sign in to comment.