Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
Updating REST Hooks to the new version, with performList
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Bernardino committed Feb 20, 2017
1 parent 44747b6 commit 77f08ac
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -16,7 +16,7 @@
},
"dependencies": {
"lodash": "4.15.0",
"zapier-platform-core": "0.9.8"
"zapier-platform-core": "0.9.12"
},
"devDependencies": {
"babel": "6.5.2",
Expand Down
31 changes: 26 additions & 5 deletions test/triggers.js
Expand Up @@ -2,7 +2,8 @@ require('should');

const zapier = require('zapier-platform-core');

const appTester = zapier.createAppTester(require('../index'));
const App = require('../index');
const appTester = zapier.createAppTester(App);

describe('triggers', () => {

Expand All @@ -12,17 +13,14 @@ describe('triggers', () => {
inputData: {
style: 'mediterranean'
},
meta: {
frontend: false
},
cleanedRequest: {
id: 1,
name: 'name 1',
directions: 'directions 1'
}
};

appTester('triggers.recipe', bundle)
appTester(App.triggers.recipe.operation.perform, bundle)
.then(results => {
results.length.should.eql(1);

Expand All @@ -34,6 +32,29 @@ describe('triggers', () => {
})
.catch(done);
});

it('should load recipe from list', (done) => {
const bundle = {
inputData: {
style: 'mediterranean'
},
meta: {
frontend: true
}
};

appTester(App.triggers.recipe.operation.performList, bundle)
.then(results => {
results.length.should.be.greaterThan(1);

const firstRecipe = results[0];
firstRecipe.name.should.eql('name 1');
firstRecipe.directions.should.eql('directions 1');

done();
})
.catch(done);
});
});

});
34 changes: 22 additions & 12 deletions triggers/recipe.js
Expand Up @@ -37,17 +37,6 @@ const unsubscribeHook = (z, bundle) => {
};

const getRecipe = (z, bundle) => {
// For the test poll, you should get some real data, to aid the setup process.
if (bundle.meta.frontend) {
const promise = z.request({
url: 'http://57b20fb546b57d1100a3c405.mockapi.io/api/recipes/',
params: {
style: bundle.inputData.style
}
});
return promise.then((response) => JSON.parse(response.content));
}

// bundle.cleanedRequest will include the parsed JSON object (if it's not a
// test poll) and also a .querystring property with the URL's query string.
const recipe = {
Expand All @@ -62,6 +51,17 @@ const getRecipe = (z, bundle) => {
return [recipe];
};

const getSampleRecipe = (z, bundle) => {
// For the test poll, you should get some real data, to aid the setup process.
const promise = z.request({
url: 'http://57b20fb546b57d1100a3c405.mockapi.io/api/recipes/',
params: {
style: bundle.inputData.style
}
});
return promise.then((response) => JSON.parse(response.content));
};

// We recommend writing your triggers separate like this and rolling them
// into the App definition at the end.
module.exports = {
Expand Down Expand Up @@ -89,6 +89,16 @@ module.exports = {
performSubscribe: subscribeHook,
performUnsubscribe: unsubscribeHook,

perform: getRecipe
perform: getRecipe,
performList: getSampleRecipe,

sample: {
id: 1,
name: 'Example Name',
directions: 'Example Directions',
style: 'Example Style',
authorId: 1,
createdAt: 1471984229
}
}
};

0 comments on commit 77f08ac

Please sign in to comment.