From bab8b96d6a48e301a9131436300327f123512313 Mon Sep 17 00:00:00 2001 From: tech-consortium <23320411+tech-consortium@users.noreply.github.com> Date: Mon, 18 Dec 2023 12:19:09 -0600 Subject: [PATCH] Update test bundle, environment variables and adjust code logic Updated test bundle config to use environment variables for flexibility and added relevant variables to .env.example for clear instructions. Enhanced 'get_case_goods_lotid' to exclude archived records and refactored 'create_case_goods_adjustment' to handle multiple items. Added or adjusted related tests accordingly. --- .env.example | 6 +++++ creates/create_casegoods_adjustment.js | 3 ++- searches/get_casegoods_lotid.js | 1 + test/_bundle.js | 9 +++++--- .../create_casegoods_adjustment.test.js | 22 +++++++++++++++++++ .../unit/searches/get_casegoods_lotid.test.js | 5 ++--- 6 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 test/integration/creates/create_casegoods_adjustment.test.js diff --git a/.env.example b/.env.example index c4627ac..b297fe1 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,9 @@ API_KEY=your_personal_access_token_here TEST_API_KEY=personal_access_token_for_tests +TEST_BASEURL=https://sutter.innovint.us +TEST_WINERYID=wnry_JEW56RPYQWERTYU234567 +TEST_CASEGOODSNAMES=AWINEGLASS,ACORKSCREW,CG-MYCASEGOODLOT1,CG-MYCASEGOODLOT2 +TEST_BOTTLEQUANTITIES=1,1,1,2 +TEST_COMPLIANCE=REMOVED_TAXPAID +TEST_EFFECTIVEAT=2023-12-17T16:44:25-06:00 \ No newline at end of file diff --git a/creates/create_casegoods_adjustment.js b/creates/create_casegoods_adjustment.js index 4683a1c..13ce09d 100644 --- a/creates/create_casegoods_adjustment.js +++ b/creates/create_casegoods_adjustment.js @@ -31,7 +31,7 @@ const perform = async (z, bundle) => { lotIdResponse); // Extract the lotId - const lotId = lotIdResponse.id; // Adjust based on the actual structure of lotIdResponse + const lotId = lotIdResponse[0].id; // Extract the lotId from the array // Log the extracted lotId z.console.log(`Extracted lotId for ${caseGoodsNames[i]}: `, lotId); @@ -73,6 +73,7 @@ const perform = async (z, bundle) => { referenceNumbers.push(results.data.referenceNumber); } } + z.console.log(`Received referenceNumbers `, referenceNumbers); return {referenceNumbers}; }; diff --git a/searches/get_casegoods_lotid.js b/searches/get_casegoods_lotid.js index d286099..0bfc58c 100644 --- a/searches/get_casegoods_lotid.js +++ b/searches/get_casegoods_lotid.js @@ -17,6 +17,7 @@ const getCaseGoodsLotId = async (z, bundle) => { const options = { params: { + archived: false, limit: 1, q: bundle.inputData.caseGoodsName, }, diff --git a/test/_bundle.js b/test/_bundle.js index b6fb132..4b84833 100644 --- a/test/_bundle.js +++ b/test/_bundle.js @@ -3,10 +3,13 @@ const bundle = { apiKey: process.env.TEST_API_KEY || '', }, inputData: { - wineryId: '123', // Common winery ID for tests - caseGoodsName: 'CG-2200RCVTOUROSE', // Common case goods name for tests + wineryId: process.env.TEST_WINERYID || '', + caseGoodsNames: process.env.TEST_CASEGOODSNAMES || '', + bottleQuantities: process.env.TEST_BOTTLEQUANTITIES || '', + compliance: process.env.TEST_COMPLIANCE || '', + effectiveAt: process.env.TEST_EFFECTIVEAT || '', }, - baseUrl: 'https://sutter.innovint.us', // Base URL for API + baseUrl: process.env.TEST_BASEURL || '', // Base URL for API }; module.exports = {bundle}; diff --git a/test/integration/creates/create_casegoods_adjustment.test.js b/test/integration/creates/create_casegoods_adjustment.test.js new file mode 100644 index 0000000..1015eaf --- /dev/null +++ b/test/integration/creates/create_casegoods_adjustment.test.js @@ -0,0 +1,22 @@ +const zapier = require('zapier-platform-core'); +const should = require('should'); +const App = require('../../../index'); // Adjust this path as necessary +const {bundle} = require('../../_bundle'); // Import the bundle from _bundle.js + +const appTester = zapier.createAppTester(App); + +describe('createCaseGoodsAdjustment Integration Test', function() { + this.timeout(10000); // Set timeout to 10000ms (10 seconds) + + it('should create case goods adjustment successfully', async () => { + // Assuming the bundle from _bundle.js has all the necessary inputData + const result = await appTester( + App.creates.createCaseGoodsAdjustment.operation.perform, bundle); + + should.exist(result.referenceNumbers); + result.referenceNumbers.should.be.an.Array(); + // Add more specific assertions based on expected outcomes + }); + + // Additional test cases as needed... +}); diff --git a/test/unit/searches/get_casegoods_lotid.test.js b/test/unit/searches/get_casegoods_lotid.test.js index 87a527f..77eb428 100644 --- a/test/unit/searches/get_casegoods_lotid.test.js +++ b/test/unit/searches/get_casegoods_lotid.test.js @@ -2,15 +2,14 @@ const zapier = require('zapier-platform-core'); const nock = require('nock'); const should = require('should'); const App = require('../../../index'); // Adjust this path as necessary +const appTester = zapier.createAppTester(App); +const {bundle} = require('../../_bundle'); /** * Creates a testing instance for the specified Zapier app. * * @param {Object} App - The Zapier app object. * @returns {Object} - The testing instance for the app. */ -const appTester = zapier.createAppTester(App); -const {bundle} = require('../../_bundle'); - describe('getCaseGoodsLotId', function() { afterEach(() => { nock.cleanAll();