diff --git a/fields/list_appellations_dropdown.js b/fields/list_appellations_dropdown.js new file mode 100644 index 0000000..0d8f94e --- /dev/null +++ b/fields/list_appellations_dropdown.js @@ -0,0 +1,28 @@ +const listAppellations = async (z, bundle) => { + const response = await z.request({ + url: 'https://sutter.innovint.us/api/v1/appellations', + method: 'GET', + headers: { + 'Accept': 'application/json', + 'Authorization': `Access-Token ${bundle.authData.accessToken}`, + }, + }); + + return response.json.map((appellation) => ({ + id: appellation.id, + name: appellation.name, + })); +}; + +module.exports = { + key: 'listAppellations', + noun: 'Appellation', + display: { + label: 'List Appellations', + description: 'Triggers when a new appellation is added.', + hidden: true, + }, + operation: { + perform: listAppellations, + }, +}; diff --git a/fields/list_varietals_dropdown.js b/fields/list_varietals_dropdown.js new file mode 100644 index 0000000..27ed274 --- /dev/null +++ b/fields/list_varietals_dropdown.js @@ -0,0 +1,28 @@ +const listVarietals = async (z, bundle) => { + const response = await z.request({ + url: 'https://sutter.innovint.us/api/v1/varietals', + method: 'GET', + headers: { + 'Accept': 'application/json', + 'Authorization': `Access-Token ${bundle.authData.accessToken}`, + }, + }); + + return response.json.map((appellation) => ({ + id: appellation.id, + name: appellation.name, + })); +}; + +module.exports = { + key: 'listVarietals', + noun: 'Varietals', + display: { + label: 'List Varietals', + description: 'Triggers when a new varietal is added.', + hidden: true, + }, + operation: { + perform: listVarietals, + }, +}; diff --git a/test/fields/list_appelations_dropdown.test.js b/test/fields/list_appelations_dropdown.test.js new file mode 100644 index 0000000..d461c3c --- /dev/null +++ b/test/fields/list_appelations_dropdown.test.js @@ -0,0 +1,24 @@ +const zapier = require('zapier-platform-core'); +const nock = require('nock'); +const App = require('../../index'); +const appTester = zapier.createAppTester(App); +const {bundle} = require('../_bundle'); +const listAppellations = require('../../fields/list_appellations_dropdown'); + +describe('List Appellations Trigger', () => { + zapier.tools.env.inject(); + + it('should load appellation data', async () => { + nock('https://sutter.innovint.us') + .get('/api/v1/appellations') + .reply(200, [ + {id: '1', name: 'Napa Valley'}, + {id: '2', name: 'Sonoma Coast'}, + ]); + + const results = await appTester(listAppellations.operation.perform, bundle); + + results.should.containDeep([{id: '1', name: 'Napa Valley'}]); + results.should.containDeep([{id: '2', name: 'Sonoma Coast'}]); + }); +}); diff --git a/test/fields/list_varietals_dropdown.test.js b/test/fields/list_varietals_dropdown.test.js new file mode 100644 index 0000000..2138f95 --- /dev/null +++ b/test/fields/list_varietals_dropdown.test.js @@ -0,0 +1,26 @@ +const zapier = require('zapier-platform-core'); +const nock = require('nock'); +const App = require('../../index'); +const appTester = zapier.createAppTester(App); +const {bundle} = require('../_bundle'); +const listVarietals = require('../../fields/list_varietals_dropdown'); + +describe('List Varietals Trigger', () => { + zapier.tools.env.inject(); + + it('should load varietals data', async () => { + nock('https://sutter.innovint.us') + .get('/api/v1/varietals') + .reply(200, [ + {id: 'vari_LZ4E0PWYDM8X8LGX6R92JK51', name: 'Acolon'}, + {id: 'vari_9P2VQ0D3NK7LZMZ6WROJ81E4', name: 'Agawam'}, + ]); + + const results = await appTester(listVarietals.operation.perform, bundle); + + results.should.containDeep( + [{id: 'vari_LZ4E0PWYDM8X8LGX6R92JK51', name: 'Acolon'}]); + results.should.containDeep( + [{id: 'vari_9P2VQ0D3NK7LZMZ6WROJ81E4', name: 'Agawam'}]); + }); +});