Skip to content

Commit

Permalink
Adding trigger dropdowns for List Appellations and Varietals
Browse files Browse the repository at this point in the history
  • Loading branch information
tech-consortium committed Nov 16, 2023
1 parent a58a099 commit ba729d8
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
28 changes: 28 additions & 0 deletions fields/list_appellations_dropdown.js
Original file line number Diff line number Diff line change
@@ -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,
},
};
28 changes: 28 additions & 0 deletions fields/list_varietals_dropdown.js
Original file line number Diff line number Diff line change
@@ -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,
},
};
24 changes: 24 additions & 0 deletions test/fields/list_appelations_dropdown.test.js
Original file line number Diff line number Diff line change
@@ -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'}]);
});
});
26 changes: 26 additions & 0 deletions test/fields/list_varietals_dropdown.test.js
Original file line number Diff line number Diff line change
@@ -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'}]);
});
});

0 comments on commit ba729d8

Please sign in to comment.