-
-
Save krtek/20ced86512f9322651f07221f7274818 to your computer and use it in GitHub Desktop.
Promises vs. generators
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 co = require('bluebird').coroutine; | |
it('should create new banner', co(function* (done) { | |
//Inicializace dat | |
//Smažu všechny organizace | |
yield Organization.removeAsync(); | |
//Poté vytvořím jednu testovací | |
var organization = yield Organization.createAsync({ | |
name: 'Fragaria s.r.o.' | |
}); | |
//Smažu všechny kampaně | |
yield Campaign.removeAsync(); | |
//Poté vytvořím jednu testovací | |
var campaign = yield Campaign.createAsync({ | |
name: 'Summer flash sale' | |
}); | |
//Vytvořím nový banner | |
server | |
.post('/banner') | |
.send({ | |
name: 'Funny kitten #2', | |
organization: organization._id.toString(), | |
campaign: campaign._id.toString(), | |
}) | |
.set('Authorization', 'Bearer ' + adminAuthToken) | |
//A zkontroluju, že se podařilo | |
.expect(201) | |
.end(done); | |
})); |
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
it('should create new banner', function(done) { | |
var organization; | |
//Inicializace dat | |
//Smažu všechny organizace | |
Organization.removeAsync().then(function() { | |
//Poté vytvořím jednu testovací | |
return Organization.createAsync({ | |
name: 'Fragaria s.r.o.' | |
}); | |
}).then(function(org) { | |
organization = org; | |
//Smažu všechny kampaně | |
return Campaign.removeAsync(); | |
}).then(function() { | |
//Poté vytvořím jednu testovací | |
return Campaign.createAsync({ | |
name: 'Summer flash sale' | |
}); | |
}).then(function(campaign) { | |
//Vytvořím nový banner | |
server | |
.post('/banner') | |
.send({ | |
name: 'Funny kitten #2', | |
organization: organization._id.toString(), | |
campaign: campaign._id.toString(), | |
}) | |
.set('Authorization', 'Bearer ' + adminAuthToken) | |
//A zkontroluju, že se podařilo | |
.expect(201) | |
.end(done); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment