Last active
August 29, 2015 14:06
-
-
Save justinvdm/04101f5733526ea8b397 to your computer and use it in GitHub Desktop.
This file contains 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 _ = require('lodash'); | |
var vumigo = require('vumigo_v02'); | |
var App = vumigo.App; | |
var Choice = vumigo.states.Choice; | |
var ChoiceState = vumigo.states.ChoiceState; | |
var FreeText = vumigo.states.FreeText; | |
var EndState = vumigo.states.EndState; | |
var WhyYouNoWorkApp = App.extend(function(self) { | |
App.call(self, 'states:start'); | |
self.init = function() { | |
return self.im | |
.contacts.for_user() | |
.then(function(user_contact) { | |
self.contact = user_contact; | |
_.defaults(self.contact.extra, {enters: '0'}); | |
return self.im.contacts.save(self.contact); | |
}); | |
}; | |
self.states.add('states:start', function(name) { | |
return new FreeText(name, { | |
question: 'states:end enters: ' + self.contact.extra.enters, | |
next: 'states:end' | |
}); | |
}); | |
self.states.add('states:end', function(name) { | |
return new EndState(name, { | |
text: 'bye', | |
next: 'states:start', | |
events: { | |
'state:enter': function() { | |
var n = parseInt(self.contact.extra.enters); | |
self.contact.extra.enters = (n + 1) + ''; | |
return self.im.contacts.save(self.contact); | |
} | |
} | |
}); | |
}); | |
}); | |
vumigo.interact(this.api, WhyYouNoWorkApp); | |
this.WhyYouNoWorkApp = WhyYouNoWorkApp; |
This file contains 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 vumigo = require('vumigo_v02'); | |
var app = require('./app'); | |
var WhyYouNoWorkApp = app.WhyYouNoWorkApp; | |
var AppTester = vumigo.AppTester; | |
describe("WhyYouNoWorkApp", function() { | |
var app; | |
var tester; | |
beforeEach(function() { | |
app = new WhyYouNoWorkApp(); | |
tester = new AppTester(app); | |
tester.setup.config.app({name: 'some_app'}); | |
}); | |
it("should tell them the number of enters so far", function() { | |
return tester | |
.inputs( | |
null, 'foo', | |
null, 'bar', | |
null, 'baz', | |
null) | |
.check.reply('states:end enters: 3') | |
.run(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment