Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* This file is part of the Ingram Micro Cloud Blue Connect SDK.
*
* @copyright (c) 2019. Ingram Micro. All Rights Reserved.
*/
/* globals describe it */
const should = require('should');
const sinon = require('sinon');
const zapier = require('zapier-platform-core');
const { HubResource } = require('@cloudblueconnect/connect-javascript-sdk/lib/connect/api');
// Use this to make test calls into your app:
const App = require('../../index');
const appTester = zapier.createAppTester(App);
zapier.tools.env.inject();
const responses = require('../responses');
describe('Connect Fulfillment Zapier App - List hubs', () => {
let sandbox;
before(() => { sandbox = sinon.createSandbox(); });
afterEach(done => { sandbox.restore(); done(); });
it('should return a list of hubs', done => {
const bundle = {
authData: {
api_key: process.env.CONNECT_API_KEY,
endpoint: process.env.CONNECT_ENDPOINT
},
inputData: {}
};
require('should');
const zapier = require('zapier-platform-core');
const App = require('../index');
const nock = require('nock');
const {
CLIENT_ID,
BASE_URL,
OAUTH_AUTHORIZE_ENDPOINT,
OAUTH_TOKEN_ENDPOINT,
OAUTH_TEST_ENDPOINT,
} = require('../constants');
const appTester = zapier.createAppTester(App);
zapier.tools.env.inject();
describe('oAuth', () => {
before(() => {
// Run `source test/.env` before running `zapier test`.
// It's a good idea to store your Client ID and Secret in the environment rather than in code.
// This works locally via the `export` shell command and in production by using `zapier env`
});
it('generates an authorize URL', () => {
const bundle = {
// In production, these will be generated by Zapier and set automatically
inputData: {
state: '4444',
redirect_uri: process.env.REDIRECT_URI,
},
};
/**
* This file is part of the Ingram Micro Cloud Blue Connect SDK.
*
* @copyright (c) 2019. Ingram Micro. All Rights Reserved.
*/
const should = require('should');
const { Fulfillment } = require('@cloudblueconnect/connect-javascript-sdk');
const sinon = require('sinon');
const zapier = require('zapier-platform-core');
const responses = require('../responses');
// Use this to make test calls into your app:
const App = require('../../index');
const appTester = zapier.createAppTester(App);
zapier.tools.env.inject();
describe('Connect Fulfillment Zapier App - Fill Fulfillment Parameters', () => {
let sandbox;
before(() => { sandbox = sinon.createSandbox(); });
afterEach(done => { sandbox.restore(); done(); });
it('should return a request with fulfillment parameter filled', done => {
const bundle = {
authData: {
api_key: process.env.CONNECT_API_KEY,
endpoint: process.env.CONNECT_ENDPOINT
},
inputData: {
request_id: 'PR-0000-0000-0000-000',
params: [
{
id: 'param_a',
/**
* This file is part of the Ingram Micro Cloud Blue Connect SDK.
*
* @copyright (c) 2019. Ingram Micro. All Rights Reserved.
*/
const should = require('should');
const { Fulfillment } = require('@cloudblueconnect/connect-javascript-sdk');
const sinon = require('sinon');
const zapier = require('zapier-platform-core');
const responses = require('../responses');
// Use this to make test calls into your app:
const App = require('../../index');
const appTester = zapier.createAppTester(App);
zapier.tools.env.inject();
describe('Connect Fulfillment Zapier App - Create Asset Request (purchase)', () => {
let sandbox;
before(() => { sandbox = sinon.createSandbox(); });
afterEach(done => { sandbox.restore(); done(); });
it('should create a new purchase request', done => {
const bundle = {
authData: {
api_key: process.env.CONNECT_API_KEY,
endpoint: process.env.CONNECT_ENDPOINT
},
inputData: {
request_type: 'purchase',
reseller_tiers: 't1',
hub_id: 'HB-0000-0000',
// connection_id: 'CT-0000-0000-0000',
it('should delete the email open hook', (done) => {
zapier.tools.env.inject();
const bundle = {
targetUrl: 'http://provided.by?zapier',
subscribeData: subscribeData,
authData: {
baseUrl: process.env.TEST_BASE_URL,
username: process.env.TEST_BASIC_AUTH_USERNAME,
password: process.env.TEST_BASIC_AUTH_PASSWORD
}
};
// Delete the created hook to clean up after previous test and to test delete too
appTester(App.triggers.emailOpened.operation.performUnsubscribe, bundle)
.then(response => {
should.exist(response.hook);
response.hook.webhookUrl.should.eql(bundle.targetUrl);
response.hook.name.should.eql('Trigger Zapier about email open events');
*
* @copyright (c) 2019. Ingram Micro. All Rights Reserved.
*/
/* globals describe it */
const should = require('should');
const sinon = require('sinon');
const zapier = require('zapier-platform-core');
const { Fulfillment } = require('@cloudblueconnect/connect-javascript-sdk');
const BaseResource = require('@cloudblueconnect/connect-javascript-sdk/lib/connect/api/base');
const { RequestResource } = require('@cloudblueconnect/connect-javascript-sdk/lib/connect/api');
// Use this to make test calls into your app:
const App = require('../../index');
const appTester = zapier.createAppTester(App);
zapier.tools.env.inject();
const responses = require('../responses');
describe('Connect Fulfillment Zapier App - Search Requests', () => {
let sandbox;
before(() => { sandbox = sinon.createSandbox(); });
afterEach(done => { sandbox.restore(); done(); });
it('should return a list of requests filtered by status', done => {
const bundle = {
authData: {
api_key: process.env.CONNECT_API_KEY,
endpoint: process.env.CONNECT_ENDPOINT
},
inputData: {
status: ['pending', 'inquiring']
it('should delete the page hit hook', (done) => {
zapier.tools.env.inject();
const bundle = {
targetUrl: 'http://provided.by?zapier',
subscribeData: subscribeData,
authData: {
baseUrl: process.env.TEST_BASE_URL,
username: process.env.TEST_BASIC_AUTH_USERNAME,
password: process.env.TEST_BASIC_AUTH_PASSWORD
}
};
// Delete the created hook to clean up after previous test and to test delete too
appTester(App.triggers.pageHit.operation.performUnsubscribe, bundle)
.then(response => {
should.exist(response.hook);
response.hook.webhookUrl.should.eql(bundle.targetUrl);
response.hook.name.should.eql('Trigger Zapier about page hit events');
it('auth succcessfully', (done) => {
zapier.tools.env.inject();
const bundle = {
authData: {
baseUrl: process.env.TEST_BASE_URL,
username: process.env.TEST_BASIC_AUTH_USERNAME,
password: process.env.TEST_BASIC_AUTH_PASSWORD
}
};
appTester(App.authentication.test, bundle)
.then((response) => {
response.status.should.eql(200);
should.exist(response.json.total);
should.not.exist(response.json.error);
done();
})
.catch(done);
it('fails auth on bad username', (done) => {
zapier.tools.env.inject();
const bundle = {
authData: {
baseUrl: process.env.TEST_BASE_URL,
username: 'badpwd',
password: process.env.TEST_BASIC_AUTH_PASSWORD
}
};
appTester(App.authentication.test, bundle)
.then(() => {
done('Should not get here');
})
.catch((error) => {
error.message.should.containEql('Authorization denied, invalid credentials.');
done();
});
it('should create a contact update hook', (done) => {
zapier.tools.env.inject();
const bundle = {
targetUrl: 'http://provided.by?zapier',
authData: {
baseUrl: process.env.TEST_BASE_URL,
username: process.env.TEST_BASIC_AUTH_USERNAME,
password: process.env.TEST_BASIC_AUTH_PASSWORD
}
};
appTester(App.triggers.contactUpdated.operation.performSubscribe, bundle)
.then(response => {
should.exist(response.hook);
response.hook.webhookUrl.should.eql(bundle.targetUrl);
response.hook.id.should.be.greaterThan(0);
response.hook.name.should.eql('Trigger Zapier about contact update events');
response.hook.description.should.eql('Created via Zapier');