-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNegativeTests.groovy
105 lines (82 loc) · 3.06 KB
/
NegativeTests.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package org.doogie
import groovy.json.JsonBuilder
import groovy.util.logging.Slf4j
import io.micronaut.context.annotation.Value
import io.micronaut.http.HttpRequest
import io.micronaut.http.HttpResponse
import io.micronaut.http.client.BlockingHttpClient
import io.micronaut.http.client.HttpClient
import io.micronaut.http.client.annotation.Client
import io.micronaut.http.client.exceptions.HttpClientResponseException
import io.micronaut.http.uri.UriBuilder
import io.micronaut.runtime.server.EmbeddedServer
import io.micronaut.test.annotation.MicronautTest
import spock.lang.Shared
import spock.lang.Specification
import javax.inject.Inject
/**
* Negative test cases that test for expected Exceptions or expected error codes in responses.
*/
@MicronautTest //(application = org.doogie.Application.class, packages = "org.doogie" /* environments = ["test", "test-happy-case"] */)
@Slf4j
class NegativeTests extends Specification {
@Inject
EmbeddedServer embeddedServer
/** Inject the shared reactive RxHttpClient */
@Inject
@Shared
@Client("/")
HttpClient rxClient
/** We only need a BlockingHttpClient in our tests. This field MUST be static */
static BlockingHttpClient client
/** We can simply inject the MongoDatastore that has already been initialized by micronaut-mongo-gorm */
//@Inject
//@AutoCleanup BUGFIX: No autocleanup. Otherwise mongo client will be closed too soon.
//MongoDatastore mongoDatastore
@Value('${mongodb.uri}')
String mongoDbUri
def setupSpec() {
log.info "=================================================================="
log.info "================= RUNNING NEGATIVE TESTs ======================="
log.info "=================================================================="
client = rxClient.toBlocking()
}
@Shared
long now = System.currentTimeMillis() % 100000;
static String teamName
static String adminEmail
static String adminJwt
static String userEmail
static String userJwt
static String inviteCode
void "create Team should return 400 when teamName is too short"() {
given:
def newTeamJson = [
teamName: "1", // <== too short teamname
adminName: "Admin Name_"+now,
adminEmail: "admin" + now + "@liquido.me"
]
when:
HttpResponse res = client.exchange(HttpRequest.POST('/team', newTeamJson), String.class)
then:
HttpClientResponseException e = thrown(HttpClientResponseException)
e.status.code == 400
}
void "join Team - with invalid inviteCode should return 400"() {
given:
JsonBuilder joinTeamRequest = new JsonBuilder()
joinTeamRequest(
inviteCode: "WRONG_INVITE_CODE",
userName: "Admin Name_"+now,
userEmail: "admin" + now + "@liquido.me"
)
when:
HttpResponse res = client.exchange(HttpRequest.PUT('/joinTeam', joinTeamRequest.toString()), String.class)
then:
HttpClientResponseException e = thrown(HttpClientResponseException)
e.status.code == 400
}
//TODO: create poll with too short title should fail! NEEDS FIX!
//TODO: add proposal must not be allowed, if poll is not in status ELABORATION
//TODO: start voting phase when there is only one proposal => fail
}