Skip to content

Commit

Permalink
Merge pull request #510 from twilio-labs/bnb/update-root-devdeps-and-…
Browse files Browse the repository at this point in the history
…fix-test-failures

fix: update devDependencies and handle resulting issues
  • Loading branch information
cmsunu28 committed Jun 5, 2024
2 parents 646123d + 4317c7f commit 52a0064
Show file tree
Hide file tree
Showing 40 changed files with 8,090 additions and 7,036 deletions.
10 changes: 5 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ module.exports = {
ecmaVersion: 2018,
},
rules: {
'prettier/prettier': 'allow',
'import/no-extraneous-dependencies': 'allow',
'prettier/prettier': 0,
'import/no-extraneous-dependencies': 0,
'no-console': 0,
'sonarjs/no-duplicate-string': 'allow',
'sonarjs/no-identical-functions': 'allow',
'sonarjs/no-duplicate-string': 0,
'sonarjs/no-identical-functions': 0,
'func-names': 0,
'global-require': 0,
'no-shadow': 0,
'import/order': 'allow',
'import/order': 0,
'max-classes-per-file': 0,
},
};
4 changes: 2 additions & 2 deletions _helpers/utils/new-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ async function generateEnvExampleFromRealEnv(projectPath, targetPath) {
# description: ${variable.description}
# format: ${variable.format}
# required: ${variable.required}${
variable.link ? `\n# link: ${variable.link}` : ''
variable.link ? `\n# link: ${variable.link}` : '' // eslint-disable-line sonarjs/no-nested-template-literals
}${variable.configurable ? '' : '\n# configurable: false'}${
variable.contentKey ? `\n# contentKey: ${variable.contentKey}` : ''
variable.contentKey ? `\n# contentKey: ${variable.contentKey}` : '' // eslint-disable-line sonarjs/no-nested-template-literals
}
${variable.key}=
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,8 @@ exports.uploadFlexPlugin = async (
serverlessClient
);

const currentEnvironment = await helpers.environment.getCurrentEnvironment(
context
);
const currentEnvironment =
await helpers.environment.getCurrentEnvironment(context);
await helpers.environment.setEnvironmentVariable(
context,
currentEnvironment,
Expand Down
5 changes: 2 additions & 3 deletions experimental-flex-dialpad/assets/helpers/setup.private.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ async function getWorkspaceSid(twilioClient) {

exports.setupProject = async (context) => {
const twilioClient = context.getTwilioClient();
const currentEnvironment = await helpers.environment.getCurrentEnvironment(
context
);
const currentEnvironment =
await helpers.environment.getCurrentEnvironment(context);
if (!currentEnvironment) {
console.error('Could not find enviroment');
return { setupDone: false };
Expand Down
15 changes: 6 additions & 9 deletions experimental-flex-dialpad/functions/setup.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
exports.handler = async function (context, event, callback) {
const { setupProject, isConfigured } = require(Runtime.getAssets()[
'/helpers/setup.js'
].path);
const {
uploadFlexPlugin,
Status,
getStatus,
deployPlugin,
} = require(Runtime.getAssets()['/helpers/flex-plugins.js'].path);
const { setupProject, isConfigured } = require(
Runtime.getAssets()['/helpers/setup.js'].path
);
const { uploadFlexPlugin, Status, getStatus, deployPlugin } = require(
Runtime.getAssets()['/helpers/flex-plugins.js'].path
);
try {
const pluginName = 'flex-dialpad-addon';
const version = '1.0.0';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ afterAll(() => {
helpers.teardown();
});

test('returns an TwiML MessagingResponse', async (done) => {
test('returns an TwiML MessagingResponse', async () => {
const callback = (err, result) => {
expect(result).toBeInstanceOf(Twilio.twiml.MessagingResponse);
expect(err).toBeFalsy();
done();
};

forwardMessageToMailgun(context, event, callback);
Expand Down
6 changes: 3 additions & 3 deletions frontline-quickstart/functions/callbacks/routing.protected.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const routeConversation = async (context, conversationSid, customerNumber) => {
const assets = Runtime.getAssets();
const { findWorkerForCustomer, findRandomWorker } = require(assets[
'/providers/customers.js'
].path);
const { findWorkerForCustomer, findRandomWorker } = require(
assets['/providers/customers.js'].path
);
let workerIdentity = await findWorkerForCustomer(context, customerNumber);
if (!workerIdentity) {
// Customer doesn't have a worker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ const setCustomerParticipantProperties = async (
// eslint-disable-next-line consistent-return
exports.handler = async function (context, event, callback) {
const assets = Runtime.getAssets();
const { getCustomerByNumber } = require(assets['/providers/customers.js']
.path);
const { getCustomerByNumber } = require(
assets['/providers/customers.js'].path
);

console.log('[ Outgoing Conversations Callback ]');

Expand Down
22 changes: 7 additions & 15 deletions frontline-quickstart/tests/assets/providers/customers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ test('getCustomerByNumber', () => {
expect(customer).toBeDefined();
});

test('getCustomersList', async (done) => {
test('getCustomersList', async () => {
const customers = await getCustomersList(context, TEST_SSO_USERNAME);
expect(customers).toBeDefined();
expect(customers.length).toEqual(2);
done();
});

test('getCustomersList: pageSize splits the list', async (done) => {
test('getCustomersList: pageSize splits the list', async () => {
let customers = await getCustomersList(context, TEST_SSO_USERNAME, 1);
expect(customers).toBeDefined();
expect(customers.length).toEqual(1);
Expand All @@ -54,21 +53,19 @@ test('getCustomersList: pageSize splits the list', async (done) => {
customers = await getCustomersList(context, TEST_SSO_USERNAME);
expect(customers).toBeDefined();
expect(customers.length).toEqual(2);
done();
});

test('getCustomersList: pagination returns the right contacts', async (done) => {
test('getCustomersList: pagination returns the right contacts', async () => {
let customers = await getCustomersList(context, TEST_SSO_USERNAME, 2, 0);
expect(customers).toBeDefined();
expect(customers[0].customer_id).toEqual(1);

customers = await getCustomersList(context, TEST_SSO_USERNAME, 2, 1);
expect(customers).toBeDefined();
expect(customers[0].customer_id).toEqual(2);

done();
});
test('getCustomersList: pageSize splits the list', async (done) => {

test('getCustomersList: pageSize splits the list', async () => {
let customers = await getCustomersList(context, TEST_SSO_USERNAME, 1);
expect(customers).toBeDefined();
expect(customers.length).toEqual(1);
Expand All @@ -80,10 +77,9 @@ test('getCustomersList: pageSize splits the list', async (done) => {
customers = await getCustomersList(context, TEST_SSO_USERNAME);
expect(customers).toBeDefined();
expect(customers.length).toEqual(2);
done();
});

test('findWorkerForCustomer', async (done) => {
test('findWorkerForCustomer', async () => {
let assignedWorker = await findWorkerForCustomer(context, CUSTOMER_1_NUMBER);
expect(assignedWorker).toBeDefined();

Expand All @@ -92,13 +88,9 @@ test('findWorkerForCustomer', async (done) => {

assignedWorker = await findWorkerForCustomer(context);
expect(assignedWorker).toBeFalsy();

done();
});

test('findRandomWorker', async (done) => {
test('findRandomWorker', async () => {
const assignedWorker = await findRandomWorker(context);
expect(assignedWorker).toBeDefined();

done();
});
10 changes: 3 additions & 7 deletions frontline-quickstart/tests/callbacks/crm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ afterAll(() => {
helpers.teardown();
});

test('get customer details by customer ID', async (done) => {
test('get customer details by customer ID', async () => {
const event = {
CustomerId: '1',
Location: 'GetCustomerDetailsByCustomerId',
Expand All @@ -32,13 +32,12 @@ test('get customer details by customer ID', async (done) => {
const callback = (_err, result) => {
expect(result).toBeDefined();
expect(result.objects.customer).toBeDefined();
done();
};

CRMCallback(context, event, callback);
});

test('get customers list for worker', async (done) => {
test('get customers list for worker', async () => {
const event = {
Worker: TEST_SSO_USERNAME,
Location: 'GetCustomersList',
Expand All @@ -48,19 +47,16 @@ test('get customers list for worker', async (done) => {
expect(result).toBeDefined();
expect(result.objects.customers).toBeDefined();
expect(result.objects.customers.length).toEqual(2);
done();
};

CRMCallback(context, event, callback);
});
test('returns 422 for unknown location', async (done) => {
test('returns 422 for unknown location', async () => {
const event = {};

const callback = (_err, result) => {
expect(result).toBeDefined();
expect(result._statusCode).toEqual(422);

done();
};

CRMCallback(context, event, callback);
Expand Down
16 changes: 5 additions & 11 deletions frontline-quickstart/tests/callbacks/outgoing-conversation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ afterAll(() => {
helpers.teardown();
});

test('Outgoing conversation: resolves', async (done) => {
test('Outgoing conversation: resolves', async () => {
const event = {
Location: 'GetProxyAddress',
ChannelType: 'sms',
Expand All @@ -31,13 +31,12 @@ test('Outgoing conversation: resolves', async (done) => {
console.log(result);
expect(_err).toBeFalsy();
expect(result).toBeDefined();
done();
};

outgoingConversation(context, event, callback);
});

test('Outgoing conversation: fails on missing Location', async (done) => {
test('Outgoing conversation: fails on missing Location', async () => {
const event = {
ChannelType: 'sms',
};
Expand All @@ -47,13 +46,12 @@ test('Outgoing conversation: fails on missing Location', async (done) => {
expect(_err).toBeFalsy();
expect(result).toBeDefined();
expect(result._statusCode).toEqual(422);
done();
};

outgoingConversation(context, event, callback);
});

test('Outgoing conversation: resolves for SMS channel', async (done) => {
test('Outgoing conversation: resolves for SMS channel', async () => {
const event = {
Location: 'GetProxyAddress',
ChannelType: 'sms',
Expand All @@ -63,13 +61,12 @@ test('Outgoing conversation: resolves for SMS channel', async (done) => {
console.log(result);
expect(_err).toBeFalsy();
expect(result).toEqual({ proxy_address: context.TWILIO_PHONE_NUMBER });
done();
};

outgoingConversation(context, event, callback);
});

test('Outgoing conversation: fails on unknown channelType', async (done) => {
test('Outgoing conversation: fails on unknown channelType', async () => {
const event = {
Location: 'GetProxyAddress',
ChannelType: 'notexistentchanneltype',
Expand All @@ -80,14 +77,12 @@ test('Outgoing conversation: fails on unknown channelType', async (done) => {
expect(_err).toBeFalsy();
expect(result).toBeDefined();
expect(result._statusCode).toEqual(403);

done();
};

outgoingConversation(context, event, callback);
});

test('Outgoing conversation: fails on missing channelType', async (done) => {
test('Outgoing conversation: fails on missing channelType', async () => {
const event = {
Location: 'GetProxyAddress',
};
Expand All @@ -98,7 +93,6 @@ test('Outgoing conversation: fails on missing channelType', async (done) => {
expect(_err).toBeFalsy();
expect(result).toBeDefined();
expect(result._statusCode).toEqual(403);
done();
};

outgoingConversation(context, event, callback);
Expand Down
22 changes: 7 additions & 15 deletions frontline-quickstart/tests/callbacks/routing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ afterAll(() => {
helpers.teardown();
});

test('routing callback', async (done) => {
test('routing callback', async () => {
const event = {
ConversationSid: 'CH12345',
'MessagingBinding.Address': context.EXAMPLE_CUSTOMER_1_PHONE_NUMBER,
Expand All @@ -51,13 +51,12 @@ test('routing callback', async (done) => {
const callback = (_err, result) => {
expect(_err).toBeFalsy();
expect(result).toBeDefined();
done();
};

handler(context, event, callback);
});

test('routeConversation: finds worker', async (done) => {
test('routeConversation: finds worker', async () => {
const conversationSid = 'CH12345';
const customerNumber = context.EXAMPLE_CUSTOMER_1_PHONE_NUMBER;

Expand All @@ -68,11 +67,9 @@ test('routeConversation: finds worker', async (done) => {
);
expect(workerIdentity).toBeDefined();
expect(workerIdentity).toEqual(TEST_SSO_USERNAME);

done();
});

test('routeConversation: finds worker for customer 2', async (done) => {
test('routeConversation: finds worker for customer 2', async () => {
const conversationSid = 'CH12345';
const customerNumber = context.EXAMPLE_CUSTOMER_2_PHONE_NUMBER;

Expand All @@ -83,10 +80,9 @@ test('routeConversation: finds worker for customer 2', async (done) => {
);
expect(workerIdentity).toBeDefined();
expect(workerIdentity).toEqual(TEST_SSO_USERNAME);
done();
});

test('routeConversation: no assigned worker, assigns a random', async (done) => {
test('routeConversation: no assigned worker, assigns a random', async () => {
const conversationSid = 'CH12345';
const customerNumber = '+000000';

Expand All @@ -97,10 +93,9 @@ test('routeConversation: no assigned worker, assigns a random', async (done) =>
);
expect(workerIdentity).toBeDefined();
expect(workerIdentity).toEqual(TEST_SSO_USERNAME);
done();
});

test('routeConversation: fails when not worker is assigned', async (done) => {
test('routeConversation: fails when not worker is assigned', async () => {
const conversationSid = 'CH12345';
const customerNumber = '+000000';
const context = {
Expand All @@ -115,10 +110,9 @@ test('routeConversation: fails when not worker is assigned', async (done) => {
await expect(
routeConversation(context, conversationSid, customerNumber)
).rejects.toThrow();
done();
});

test('routeConversationToWorker', async (done) => {
test('routeConversationToWorker', async () => {
const conversationSid = 'CH12345';
const workerIdentity = TEST_SSO_USERNAME;

Expand All @@ -128,10 +122,9 @@ test('routeConversationToWorker', async (done) => {
workerIdentity
);
expect(conversation).toBeDefined();
done();
});

test('routeConversationToWorker: fails if no Twilio client present', async (done) => {
test('routeConversationToWorker: fails if no Twilio client present', async () => {
const conversationSid = 'CH12345';
const workerIdentity = TEST_SSO_USERNAME;

Expand All @@ -142,5 +135,4 @@ test('routeConversationToWorker: fails if no Twilio client present', async (done
workerIdentity
)
).rejects.toThrow();
done();
});
Loading

0 comments on commit 52a0064

Please sign in to comment.