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
| const getFromXYZ = function(){ | |
| return Promise | |
| .resolve() | |
| //this was bound from the root promise chain. | |
| //because we are creating a new Promise chain, it needs to be rebound. | |
| .bind(this) | |
| .then(function() { | |
| return request.get(this.options.url); | |
| }) | |
| .then(function(response) { |
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
| const Promise = require('bluebird'); | |
| const helper = require('./helper'); | |
| //setup for the this context within the promise chain | |
| const context = { | |
| options : { | |
| url : 'http://xyz.com/endpoint' | |
| } | |
| }; |
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
| doSomething() | |
| .then(function () { | |
| return request.get('http://xyz.com/endpoint'); | |
| }) | |
| .then(function (response) { | |
| return response.status === 200 ? 'AWESOME' : 'FOOBAR' | |
| }) | |
| .then(function (mapped) { | |
| if (mapped === 'FOOBAR') { | |
| throw new Error('unexpected status'); |
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 someModule = require('some-module'); | |
| //Promise adaptor | |
| var someModulePromisified = function(param) { | |
| return new Promise((resolve, reject) => { | |
| someModule(param, (result, error) => { | |
| if (error) { reject(error); } | |
| else { resolve(result); } | |
| }); | |
| }); |
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 doSomething(param, cb) { | |
| request.get('http://xyz.com/endpoint' + param, function(response, error) { | |
| cb(response, error); | |
| // This can keep growing out as you need more chaining involved. | |
| }); | |
| } |
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
| feature 'the Guest can RSVP' do | |
| scenario 'they enter their names in the RSVP form' do | |
| find('span.rsvp-link').click | |
| find_field('first-name').set('1') | |
| find_field('last-name').set('1') | |
| click_button('find-invite') | |
| find('.rsvp-button', match: :first).click | |
| find('.next-guest').click | |
| find('#submit-rsvp').click | |
| expect(page).to have_content("Thanks, we've received your RSVP.") |
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
| const Document = Felicity.entityFor(SchemaDictionary.docType); | |
| const documentInstance = new Document(); | |
| // later in request handler | |
| documentInstance.id = Uuid.v4(); | |
| documentInstance.name.first = computedValues.firstName; | |
| documentInstance.name.last = computedValues.lastName; | |
| documentInstance.validate(function(err, value) { | |
| if (err) { | |
| throw new Error(err); |
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
| const mockDoc = Felicity.example(schema); | |
| console.log(mockDoc); | |
| /* | |
| { | |
| id: ‘d254d580-c56e-43a8-8f3c-5db38d8061c3’, | |
| name: { | |
| first: ‘qgrbddy’, | |
| last: ‘jdocnld’ | |
| } | |
| } |
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
| const schema = Joi.object().keys({ | |
| id: Joi.string().guid().required(), | |
| name: Joi.object.keys({ | |
| first: Joi.string().required(), | |
| last: Joi.string().required() | |
| }).required() | |
| }); | |
| const Document = Felicity.entityFor(schema); |
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
| const docSchema = SchemaDictionary.docType; |