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
// The brains to fill the fields. This uses the human brain of the user. | |
const usingCLI = (fields) => { | |
const fieldsWithValuesFromUser = await presentFieldNamesToUser(Object.keys(fields)); | |
return fieldsWithValuesFromUser; | |
}; | |
// The client uses the CLI to get the field values when the server asks for it | |
const runWithFieldsFromCLI = run(usingCLI); | |
// Initial trigger of the booking process |
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
// The brains to fill the fields. This can use AI, etc. | |
const fillFields = (fields) => fields; | |
const run = async (method = 'GET', url = 'https://clinic.example.com/start-booking', fields) => { | |
const response = await fetch(url, { method: method, body: JSON.stringify(fields) }); | |
const parsedResponseBody = await response.json(); | |
const requiredFieldsAction = queryAction('required-fields', parsedResponseBody); | |
if (requiredFieldsAction) { |
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
// Response for: | |
// GET /start-booking | |
{ | |
"data": [{ | |
"type": "action", | |
"id": "required-fields", | |
"attributes": { | |
"url": "/start-booking", | |
"method": "post", |
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
const response = await fetch('http://clinic.example.com/booking?intendedDoctor=jane', { | |
method: 'get' | |
}); | |
const availableTimeSlotsForTheWeek = await response.json(); | |
await fetch('http://clinic.example.com/booking', { | |
method: 'post', | |
body: JSON.stringify({ | |
username: 'mary.doe', |
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
await fetch('http://clinic.example.com/booking', { | |
method: 'post', | |
body: JSON.stringify({ | |
username: 'mary.doe', | |
dateTime: '2018-05-01T10:20:00Z' | |
intendedDoctor: 'jane', | |
booking: 'Consultation with Doctor Jane' | |
}), | |
}); |
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
const prefill = Prefill(StubbedProvider())(MappingLogic(forSimpleMatching)); | |
const prefilledFormFields = prefill(FormFields()); | |
expect(prefilledFormFields.toString()).toEqual('name: Anna'); |
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
const httpServerDataSource = HttpServerDataSource(getRequest); | |
const postsTitle = await httpServerDataSource.findPostsTitle(); | |
assert.deepEqual(postsTitle, ['How to bake a cake']); |
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
const renderedComponent = render(<Counter></Counter>); | |
renderedComponent.querySelector('.count-button').click(); | |
renderedComponent.querySelector('.count-button').click(); | |
const renderedCount = renderedComponent | |
.querySelector('.current-count') | |
.innerHTML; | |
expect(renderedCount).toEqual('2'); |
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
const instance = render(<Counter></Counter>).getInstance(); | |
instance.increment(); | |
instance.increment(); | |
expect(instance.getState()).toEqual({ count: 2 }); |
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
const interestToPayFor = (loanAmount) => { | |
const greaterThan2000 = { endOfRange: Money('$2000.00'), interestPerDollar: Money('$0.09'), previousInterestPerDollar: Money('$0.00') }; | |
const greaterThan5000 = { endOfRange: Money('$5000.00'), interestPerDollar: Money('$0.14'), previousInterestPerDollar: Money('$0.09') }; | |
const greaterThan10000 = { endOfRange: Money('$10000.00'), interestPerDollar: Money('$0.21'), previousInterestPerDollar: Money('$0.14') }; | |
// You can move this into a configuration file so that changes | |
// in the behavior doesn't require code changes | |
const ranges = [greaterThan2000, greaterThan5000, greaterThan10000]; | |
let interestAmount = Money('$0.00'); | |
for (range of ranges) { | |
if (loanAmount.greaterThan(range.endOfRange)) { |
NewerOlder