· 7 years ago · Mar 01, 2018, 10:28 AM
1 def "Test webhook creation"() {
2 given:
3 def webhookKey = '1153AFBD-6E69-4C8A-B78B-E3828C6AFD99'.toLowerCase();
4 def secretKey = 'ece9c236';
5 def webhookSubscription = [
6 "type" : "message_allow",
7 "object" : [
8 "user_id": testAccountId,
9 "key" : webhookKey
10 ],
11 "groupId": testGroupId,
12 "secret" : secretKey
13 ]
14 when:
15 def response = vkSrvClient.post(
16 path : '/webhook/' + webhookKey,
17 body : webhookSubscription,
18 requestContentType: ContentType.JSON
19 )
20
21 then: "vk sent a webhook to server"
22 def receivedMessageEnvelope = commandsListener.receiveMessage(3) {
23 def body = new JsonSlurper().parse(it.body);
24 return body.name == "processMessageAllow"
25 }
26
27 receivedMessageEnvelope != null
28 with(receivedMessageEnvelope.customProperties) {
29 TB_CHANNEL == 'vk'
30 TB_CHANNEL_ID as Integer == -1
31 TB_ACCOUNT_ID as String == 22
32 }
33
34 def receivedMessage = new JsonSlurper().parse(receivedMessageEnvelope.body);
35 receivedMessage.accountId == 22
36 receivedMessage.channel == "vk"
37 receivedMessage.channelId == -1
38 receivedMessage.text == webhookSubscription
39 then: "webhook controller worked correctly"
40
41 vkSql.firstRow("SELECT count(1) c FROM vk_srv_db.webhookKey WHERE accountId =?", testAccountId).c == 1
42
43 response.status == 200
44 response.body.$error == null
45 response.body.$value.accountId == testAccountId
46 !(response.body.$value.remoteContact.empty)
47 response.body.$value.active == true
48 }