This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Let's say you have a function that does some async operation inside setTimeout (think of polling for data) | |
function runInterval(callback, interval = 1000) { | |
setInterval(async () => { | |
const results = await Promise.resolve(42) // this might fetch some data from server | |
callback(results) | |
}, interval) | |
} | |
// Goal: We want to test that function - make sure our callback was called |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('A sample that waits till a request is posted', () => { | |
before(() => { | |
cy.visit('/'); | |
}) | |
beforeEach(() => { | |
cy.server(); | |
cy.route('POST', '/api/v1/requests').as('requestData'); | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doPost(e){ | |
var req = null; | |
try { | |
req = queryStringToJSON(e.postData.contents); | |
/* Extract the action from the request text */ | |
var action = getAction(req); | |
if (!actionIsValid(action)) throw 'Hi. You sent an invalid command'; | |
/* Extract the action arguments from the request text */ | |
var args = getActionArgs(req); | |
args.forEach(function(arg, index) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var EMAIL_COL = 0; // 0 is the index of the email column in the data range | |
var NUM_COL = 1; | |
/* This function finds a value in a sheet and returns that value */ | |
function findValueInSheet(key, keyColumn, valueColumn, _sheet) { | |
var sheet = _sheet; | |
var dataRange = sheet.getDataRange(); | |
var values = dataRange.getValues(); | |
var selectedRow = null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doPost(e){ | |
var req = null; | |
try { | |
req = queryStringToJSON(e.postData.contents); | |
/* Extract the action from the request text */ | |
var action = getAction(req); | |
if (!actionIsValid(action)) throw 'Hi. You sent an invalid command'; | |
/* Extract the action arguments from the request text */ | |
var args = getActionArgs(req); | |
args.forEach(function(arg, index) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var actions = { | |
'check': { | |
'requiredArgsCount': 1, | |
'helpText': [{ 'text': 'Type `/listbot check <youremail>` to check your status' }], | |
'args': { | |
0: [/\w+@\w+\.com$/, 'Oops. It appears you did not supply an email. Please check'] | |
}, | |
'execute': getUserWaitStatus | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Each action has a required number of arguments which will be parsed | |
* from the text sent by the user | |
* Each action has a helpText which can be used later with a help action | |
* Each action has an argument list starting with 0 | |
* Each argument in the argument list has a regex validator and | |
* a validation error message | |
* The regex used for email in this example does not cover all | |
* cases as it's mostly for demo purposes | |
* Each action has a core execution function that handles the main job of the task |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
token: 'gIkuvaNzQIHg97ATvDxqgjtO', | |
team_id: 'T0001', | |
team_domain: 'example', | |
enterprise_id: 'E0001', | |
enterprise_name: 'Globular%20Construct%20Inc', | |
channel_id: 'C2147483705', | |
channel_name: 'test' | |
user_id: 'U2147483697', | |
user_name: 'Steve', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doPost(e){ | |
var req = null; | |
try { | |
/* Slack's request comes in a query string format. We convert | |
it to a javascript object to make it easy to use */ | |
req = queryStringToJSON(e.postData.contents); | |
} catch (error) { | |
} | |
} |