Skip to content

Instantly share code, notes, and snippets.

View haingdc's full-sized avatar

Hai.Nguyen Github haingdc

View GitHub Profile
@haingdc
haingdc / flickr-fetcher.js
Created April 4, 2018 08:08
Gửi các request tới server thông qua TDD
// flickr-fetcher.js
fetchFlickrData: function(apiKey, fetch) {
var url = 'https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key='
+ apiKey + '&text=pugs&format=json&nojsoncallback=1'
return fetch(url).then(function(data) {
return data;
});
}
@haingdc
haingdc / flickr-fetcher-spec.js
Created April 4, 2018 08:05
Gửi các request tới server thông qua TDD
// flickr-fetcher-spec.js
describe("#fetchFlickrData()", function() {
it("should take an API key and fetcher function argument and return a promise for JSON data.", function(done) {
var apiKey = "does not matter much what this is right now",
fakeData = {
photos: {
page: 1,
pages: 2872,
perpage: 100,
total: "287170",
@haingdc
haingdc / fetchFlickrData.js
Created April 4, 2018 08:02
Gửi các request tới server thông qua TDD
fetchFlickrData: function(apiKey, fetch) {

// ...
}
@haingdc
haingdc / flickr-fetcher5.js
Created March 27, 2018 10:05
get start with tdd
// flickr-fetcher.js
//… lược bớt cho ngắn gọn …
transformPhotoObj: function(photoObj) {
return {
title: photoObj.title,
url: FlickrFetcher.photoObjToURL(photoObj)
};
}
@haingdc
haingdc / flickr-fetcher-spec5.js
Created March 27, 2018 10:03
get start with tdd
describe('#transformPhotoObj()', function() {
it('should take a photo object and return an object with just title and URL', function() {
var input = {
id: '25373736106',
owner: '99117316@N03',
secret: '146731fcb7',
server: '1669',
farm: 2,
title: 'Dog goes to desperate measure to avoid walking on a leash',
ispublic: 1,
@haingdc
haingdc / flickr-fetcher4.js
Created March 27, 2018 10:02
get start with tdd
transformPhotoObj: function() {
return {
title: 'Dog goes to desperate measure to avoid walking on a leash',
url: 'https://farm2.staticflickr.com/1669/25373736106_146731fcb7_b.jpg'
};
}
@haingdc
haingdc / flickr-fetcher-spec3.js
Created March 27, 2018 10:00
get start with tdd
// flickr-fetcher-spec.js
describe('#transformPhotoObj()', function() {
it('should take a photo object and return an object with just title and URL', function() {
var input = {
id: '25373736106',
owner: '99117316@N03',
secret: '146731fcb7',
server: '1669',
farm: 2,
title: 'Dog goes to desperate measure to avoid walking on a leash',
@haingdc
haingdc / flickr-fetcher3.js
Created March 27, 2018 09:58
get start with tdd
FlickrFetcher = {
photoObjToURL: function(photoObj) {
return [ 'https://farm',
photoObj.farm, '.staticflickr.com/',
photoObj.server, '/',
photoObj.id, '_',
photoObj.secret, '_b.jpg'
].join('');
}
};
@haingdc
haingdc / flickr-fetcher2.js
Created March 27, 2018 09:56
get start with tdd
// flickr-fetcher.js
FlickrFetcher = {
photoObjToURL: function(photoObj) {
return 'https://farm' + photoObj.farm + '.staticflickr.com/' + photoObj.server + '/' + photoObj.id + '_' +
photoObj.secret + '_b.jpg';
}
};
@haingdc
haingdc / flickr-fetcher-spec2.js
Created March 27, 2018 09:55
get start with tdd
// flickr-fetcher-spec.js
describe('#photoObjToURL()', function() {
it('should take a photo object from Flickr and return a string', function() {
var input = {
id: '24770505034',
owner: '97248275@N03',
secret: '31a9986429',
server: '1577',
farm: 2,
title: '20160229090898',