Skip to content

Instantly share code, notes, and snippets.

@mpj
Created January 15, 2017 21:14
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save mpj/c55dc66bc2cfd389dbbd25ab5092d4f3 to your computer and use it in GitHub Desktop.
Save mpj/c55dc66bc2cfd389dbbd25ab5092d4f3 to your computer and use it in GitHub Desktop.
Code from the "Dependency Injection Basics" episode of Fun Fun Function
const assert = require('assert')
function getAnimals(fetch, id) {
return fetch('http://api.animalfarmgame.com/animals/' + id)
.then(response => response.json())
.then(data => data.results[0])
}
describe('getAnimals', () => {
it('calls fetch with the correct url', () => {
const fakeFetch = url => {
assert(
url ===
'http://api.animalfarmgame.com/animals/123'
)
return new Promise(function(resolve) {
})
}
getAnimals(fakeFetch, 123)
})
it('parses the response of fetch correctly', (done) => {
const fakeFetch = () => {
return Promise.resolve({
json: () => Promise.resolve({
results: [
{ name: 'fluffykins' }
]
})
})
}
getAnimals(fakeFetch, 12345)
.then(result => {
assert(result.name === 'fluffykins')
done()
})
})
})
@Neppord
Copy link

Neppord commented Jan 29, 2017

I did some more thingking and this fileStorage.save(fileStream, {user, folder}) strikes me as a bit odd. why do the filesStorage need the user and folder. Is it somehow part of the location that the fileStreamwill bes saved at?

Also there is some asymmetri here. storeDocument gets raw data as arguments, except for the stream object. but the access method userAccess.canWrite(user, folder) takes full-blown object. there might be some answers hidden in this odd relationship.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment