-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDownloadControllerSpec.groovy
71 lines (55 loc) · 2.13 KB
/
DownloadControllerSpec.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package au.org.ala.merit
import org.apache.http.HttpStatus
import org.h2.engine.User
import org.springframework.mock.web.MockMultipartFile
import spock.lang.Specification
import grails.testing.web.controllers.ControllerUnitTest
class DownloadControllerSpec extends Specification implements ControllerUnitTest<DownloadController>{
WebService webService = Mock(WebService)
UserService userService = Mock(UserService)
def setup() {
controller.userService = userService
controller.webService = webService
}
def "The download controller proxies requests to ecodata"() {
when:
params.id = "uuid1234"
def resp = controller.get()
then:
1 * userService.userIsSiteAdmin() >> true
1 * webService.proxyGetRequest(_, {it.endsWith('download/uuid1234')}, true, true, _) >> [status:HttpStatus.SC_OK]
and: "We return null to inform grails to not attempt to process a view as we are proxying a response from ecodata"
resp == null
}
def "if no uuid is supplied, an error is returned"() {
when:
controller.get()
then:
1 * userService.userIsSiteAdmin() >> true
response.status == HttpStatus.SC_BAD_REQUEST
}
def "Only some file formats are supported"(String format, boolean expectedFormatToBePassedToEcodata) {
setup:
boolean formatPassedToEcodata
when:
params.id = "file"
params.format = format
controller.get()
then:
1 * userService.userIsSiteAdmin() >> true
1 * webService.proxyGetRequest(_, {it.contains('download/file')}, true, true, _) >> {
resp, url, userId, apiKey, timeout ->
formatPassedToEcodata = url.endsWith(format)
[status:HttpStatus.SC_OK]
}
formatPassedToEcodata == expectedFormatToBePassedToEcodata
where:
format | expectedFormatToBePassedToEcodata
'xlsx' | true // Most downloads
'zip' | true // Shapefiles
'json' | true // not used but potentially useful
'exe' | false
'doc' | false
'html' | false
}
}