-
Notifications
You must be signed in to change notification settings - Fork 3
/
ITest.scala
75 lines (68 loc) · 2.39 KB
/
ITest.scala
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
package integration
import com.github.igorramazanov.chat.ResponseCode
import com.github.igorramazanov.chat.UtilsShared._
import com.github.igorramazanov.chat.domain.ChatMessage
import org.scalacheck.Gen
import org.scalatest.Matchers._
import util.DomainEntitiesGenerators
class ITest
extends ITestHarness
with DomainEntitiesGenerators
with TestContainers {
test(
"it should response with 'InvalidCredentials' if /signin for unexistent account"
) {
forAll(userGen) { user =>
val (status, _) = signIn(user)
status shouldBe ResponseCode.InvalidCredentials.value
}
}
test(
"it should response with 'ValidationErrors' if /signin with invalid credentials"
) {
forAll(invalidIdGen, invalidEmailGen, invalidPasswordGen) {
case ((invalidId, _), (invalidEmail, _), (invalidPassword, _)) =>
val (status, _) =
signIn(invalidId, invalidEmail, invalidPassword)
status shouldBe ResponseCode.ValidationErrors.value
}
}
test("it should response with 'Ok' if /signup with valid credentials") {
forAll(userGen) { user =>
val status = signUp(user)
status shouldBe ResponseCode.Ok.value
}
}
test(
"it should response with 'ValidationErrors' if /signup with invalid credentials"
) {
forAll(invalidIdGen, invalidEmailGen, invalidPasswordGen) {
case ((invalidId, _), (invalidEmail, _), (invalidPassword, _)) =>
val status =
signUp(invalidId, invalidEmail, invalidPassword)
status shouldBe ResponseCode.ValidationErrors.value
}
}
test("users should be able send messages to each other") {
forAll(userGen, userGen, Gen.listOf(Gen.alphaNumStr)) {
(userA, userB, payloads) =>
whenever(userA.id !== userB.id) {
signUp(userA)
signUp(userB)
val outgoingMessages =
payloads.map(ChatMessage.IncomingChatMessage.apply(userB.id, _))
sendAndReceiveMessages(from = userA, outgoingMessages).discard()
val receivedMessages = sendAndReceiveMessages(userB, Nil)._2
receivedMessages.size shouldBe outgoingMessages.size
receivedMessages
.zip(outgoingMessages)
.foreach {
case (received, sent) =>
received.from shouldBe userA.id
received.to shouldBe userB.id
received.payload shouldBe sent.payload
}
}
}
}
}