Skip to content

Instantly share code, notes, and snippets.

@samaybar
Created December 12, 2018 17:24
Show Gist options
  • Save samaybar/a40590ace72b0a6bb40dfce8da0ef458 to your computer and use it in GitHub Desktop.
Save samaybar/a40590ace72b0a6bb40dfce8da0ef458 to your computer and use it in GitHub Desktop.
{
"name": "Create EventN Service - Runscope to Google Chat",
"version": "1.0",
"exported_at": 1542227101,
"steps": [
{
"body": "{\"email\":\"{{email}}\",\"password\":\"{{password}}\"}",
"skipped": false,
"form": {},
"url": "https://api.eventn.com/authentication",
"variables": [
{
"source": "response_json",
"property": "data.token",
"name": "eventnToken"
}
],
"multipart_form": [],
"step_type": "request",
"auth": {},
"note": "",
"headers": {
"Content-Type": [
"application/json"
]
},
"assertions": [
{
"comparison": "equal_number",
"value": 200,
"source": "response_status"
}
],
"scripts": [],
"before_scripts": [],
"method": "POST"
},
{
"body": "{\r\n\"description\": \"Runscope Advanced Webhook to Google Chat\",\r\n\"get_fn\": \"function onGet(context) {\\n return context.stores.default().table().count();\\n}\\n\\nmodule.exports = onGet;\\n\",\r\n\"post_fn\": \"const rp = require('request-promise');\\n\\nfunction onPost(context, request) {\\n \\n\\n \\n\\n const {test_name, test_url, test_run_url, result, environment_name, region, region_name, requests, variables} = request.payload;\\n \\n let my_test_name = test_name;\\n if (variables.chat_name) {\\n my_test_name = variables.chat_name;\\n }\\n let totalResponseTime = 0;\\n let assertionsTotal = 0;\\n let assertionsPassed = 0;\\n let scriptsTotal = 0;\\n let scriptsPassed = 0;\\n let requestCount = requests.length;\\n let thisResult = result;\\n let my_region_name = region_name.split(\\\" - \\\",1);\\n for (let i=0; i<requests.length; i++)\\n {\\n assertionsTotal += requests[i].assertions.total;\\n assertionsPassed += requests[i].assertions.pass;\\n scriptsTotal += requests[i][\\\"scripts\\\"].total;\\n scriptsPassed += requests[i][\\\"scripts\\\"].pass;\\n totalResponseTime += requests[i].response_time_ms;\\n }\\n\\n let thisIcon = \\\"https://www.runscope.com/static/img/press/logoicon-runscope-color.png\\\";\\n const failIcon = \\\"https://upload.wikimedia.org/wikipedia/commons/thumb/5/5e/Antu_task-reject.svg/200px-Antu_task-reject.svg.png\\\";\\n const passIcon = \\\"https://upload.wikimedia.org/wikipedia/commons/thumb/a/a1/Antu_vcs-normal.svg/200px-Antu_vcs-normal.svg.png\\\";\\n let blue = \\\"#0000ff\\\" // blue\\n let red = \\\"#ed0000\\\"; //\\\"#ff0000\\\";\\n let green = \\\"#2ecc71\\\";// \\\"#00ff00\\\";\\n let fontColor = blue;\\n if (result == \\\"pass\\\") {\\n thisIcon = passIcon;\\n thisResult = \\\"Passed\\\";\\n fontColor = green;\\n \\n } else if (result == \\\"fail\\\") {\\n thisIcon = failIcon;\\n thisResult = \\\"Failed\\\";\\n fontColor = red;\\n }\\n const cards = \\n [\\n {\\n \\\"header\\\": {\\n \\\"title\\\": \\\"API Test Run Completed\\\",\\n \\\"subtitle\\\": my_test_name,\\n \\\"imageUrl\\\" : thisIcon,\\n \\\"imageStyle\\\": \\\"IMAGE\\\"\\n },\\n \\\"sections\\\": [\\n {\\n \\\"widgets\\\": [\\n {\\n \\\"buttons\\\": [\\n {\\n \\\"textButton\\\": {\\n \\\"text\\\": \\\"View Result\\\",\\n \\\"onClick\\\": {\\n \\\"openLink\\\": {\\n \\\"url\\\": test_run_url\\n }\\n }\\n }\\n },\\n {\\n \\\"textButton\\\": {\\n \\\"text\\\": \\\"Edit Test\\\",\\n \\\"onClick\\\": {\\n \\\"openLink\\\": {\\n \\\"url\\\": test_url\\n }\\n }\\n }\\n }\\n ]\\n }\\n ]\\n },\\n {\\n \\\"widgets\\\": [\\n {\\n \\\"keyValue\\\": {\\n \\\"topLabel\\\": \\\"Status\\\",\\n \\\"content\\\": `<font color=\\\\\\\"${fontColor}\\\\\\\">${thisResult}</font>`\\n }\\n },\\n {\\n \\\"keyValue\\\": {\\n \\\"topLabel\\\": \\\"Environment\\\",\\n \\\"content\\\": environment_name\\n }\\n },\\n {\\n \\\"keyValue\\\": {\\n \\\"topLabel\\\": \\\"Location\\\",\\n \\\"content\\\": `${region}: ${my_region_name}`\\n }\\n },\\n {\\n \\\"keyValue\\\": {\\n \\\"topLabel\\\": \\\"Requests Executed\\\",\\n \\\"content\\\": `${requests.length}`\\n }\\n },\\n {\\n \\\"keyValue\\\": {\\n \\\"topLabel\\\": \\\"Assertions Passed\\\",\\n \\\"content\\\": `${assertionsPassed} of ${assertionsTotal}`\\n }\\n },\\n {\\n \\\"keyValue\\\": {\\n \\\"topLabel\\\": \\\"Scripts Passed\\\",\\n \\\"content\\\": `${scriptsPassed} of ${scriptsTotal}`\\n }\\n },\\n {\\n \\\"keyValue\\\": {\\n \\\"topLabel\\\": \\\"Total Response Time\\\",\\n \\\"content\\\": `${totalResponseTime}`\\n }\\n }\\n ]\\n }\\n ]\\n \\n }\\n ];\\n\\n \\n const options = {\\n method: 'POST',\\n uri: request.headers.chaturl,\\n //uri: url,\\n body: {\\n \\\"cards\\\": cards\\n },\\n json: true // Automatically parses the JSON string in the response\\n };\\n\\n return rp(options);\\n \\n \\n \\n\\n\\n}\\nmodule.exports = onPost;\"\r\n}",
"skipped": false,
"form": {},
"url": "https://api.eventn.com/service",
"variables": [
{
"source": "response_json",
"property": "data.id",
"name": "serviceId"
},
{
"source": "response_json",
"property": "data.token",
"name": "serviceToken"
}
],
"multipart_form": [],
"step_type": "request",
"auth": {},
"note": "",
"headers": {
"Content-Type": [
"application/json"
],
"Authorization": [
"Bearer {{eventnToken}}"
]
},
"assertions": [
{
"comparison": "equal_number",
"value": 200,
"source": "response_status"
}
],
"scripts": [
""
],
"before_scripts": [],
"method": "POST"
}
],
"description": "This test will create a service in EventN to take Runscope Webhook data and send it to Google Chat"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment