Skip to content

Instantly share code, notes, and snippets.

View samueljoli's full-sized avatar
🔒
lalilulelo

Samuel Joli samueljoli

🔒
lalilulelo
View GitHub Profile
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) {
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'
}
};
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');
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); }
});
});
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.
});
}
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.")
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);
const mockDoc = Felicity.example(schema);
console.log(mockDoc);
/*
{
id: ‘d254d580-c56e-43a8-8f3c-5db38d8061c3’,
name: {
first: ‘qgrbddy’,
last: ‘jdocnld’
}
}
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);
const docSchema = SchemaDictionary.docType;