View package.json
{ | |
"name": "twilio-azure-functions-node", | |
"version": "1.0.0", | |
"description": "Receive SMS and calls with Azure Functions and Node.js", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Twilio and your-name", | |
"license": "MIT", |
View index.js
// We're using Twilio in this app, and getting ready to send a message response | |
const MessagingResponse = require('twilio').twiml.MessagingResponse; | |
// We're exporting our function from Azure | |
module.exports = function (context) { | |
// Logging what's happening in Azure | |
context.log('JavaScript HTTP trigger function processed a request.'); | |
// Create a new TwiML response | |
const response = new MessagingResponse(); |
View index.js
// Use Twilio in this app | |
const VoiceResponse = require('twilio').twiml.VoiceResponse; | |
// Export the function from Azure | |
module.exports = function (context) { | |
// Log the response in Azure | |
context.log('JavaScript HTTP trigger function processed a request.'); | |
// Create a new TwiML response, this time using voice | |
const twiml = new VoiceResponse(); |
View testing-exception-conditions.groovy
when: | |
stack.pop() | |
then: | |
thrown(EmptyStackException) | |
stack.empty |
View mocking-metaclass.groovy
void testSearch() { | |
registerMetaClass User | |
User.metaClass.static.search = { searchText -> | |
[results: [new User(username:'mari')], | |
total: 1, offset: 0, scores: [1]] | |
} | |
assertEquals 'mari', User.search('mari').results[0].username | |
} |
View integrations-test.groovy
package com.testguide | |
import com.testguide.CampaignController | |
import grails.core.GrailsApplication | |
import grails.gorm.transactions.Transactional | |
import grails.plugins.rest.client.RestBuilder | |
import grails.plugins.rest.client.RestResponse | |
import org.springframework.web.util.UriComponentsBuilder | |
import spock.lang.Specification | |
import spock.lang.Shared |
View controller-test.groovy
void "func successfully" () { | |
given: "a campaign object" | |
def campaign = createDomain(campaign) | |
when: | |
request.method = 'GET' | |
request.contentType = 'application/json' | |
params.uuid = beaconDefinition.uuid | |
params.startDate = new Date().format("yyyy-MM-dd") | |
params.endDate = new Date().plus(1).format("yyyy-MM-dd") |
View evolved-controllers.groovy
def controllerFunction() { | |
def (successObj, errorObj) = service.func(params) | |
if (errorObj) { | |
response.status = errorObj.status : 404 | |
render errorObj.message as JSON ?: WebserviceError.resourceNotFound as JSON | |
return | |
} | |
render(view: "list", model: [campaignList: successObj]) | |
View controllers.groovy
def controllerFunction() { | |
def user = User.get(params.userId) | |
if (!userPermissionService.hasPermissionToDoThis(user) { | |
response.status = 403 | |
render "User unauthorized" | |
return | |
} | |
def comments = commentsService.getByUser(user) | |
... | |
View testing-services.groovy
package com.testguide | |
import com.testguide.CampaignService | |
import com.testguide.User | |
import com.testguide.dataservice.UserDataService | |
import grails.testing.mixin.integration.Integration | |
import grails.web.servlet.mvc.GrailsParameterMap | |
import org.springframework.mock.web.MockHttpServletRequest | |
import org.springframework.test.annotation.Rollback | |
import org.springframework.transaction.annotation.Transactional |
OlderNewer