Skip to content

Commit

Permalink
Merge pull request #1074 from wrightia/v4-connection-sendgrid
Browse files Browse the repository at this point in the history
Connection Sendgrid V4
  • Loading branch information
SamTolmay committed Feb 1, 2022
2 parents 7ce9d1f + 8be05fc commit c139cd4
Show file tree
Hide file tree
Showing 16 changed files with 420 additions and 347 deletions.
1 change: 1 addition & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/build/package.json
Expand Up @@ -67,6 +67,7 @@
"@lowdefy/connection-knex": "4.0.0-alpha.6",
"@lowdefy/connection-mongodb": "4.0.0-alpha.6",
"@lowdefy/connection-redis": "4.0.0-alpha.6",
"@lowdefy/connection-sendgrid": "4.0.0-alpha.6",
"@lowdefy/operators-change-case": "4.0.0-alpha.6",
"@lowdefy/operators-diff": "4.0.0-alpha.6",
"@lowdefy/operators-js": "4.0.0-alpha.6",
Expand Down
1 change: 1 addition & 0 deletions packages/build/src/scripts/generateDefaultTypes.js
Expand Up @@ -31,6 +31,7 @@ const defaultPackages = [
'@lowdefy/connection-knex',
'@lowdefy/connection-mongodb',
'@lowdefy/connection-redis',
'@lowdefy/connection-sendgrid',
'@lowdefy/operators-change-case',
// '@lowdefy/operators-diff',
'@lowdefy/operators-js',
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/connections/connection-sendgrid/package.json
Expand Up @@ -27,8 +27,8 @@
},
"type": "module",
"exports": {
".": "./dist/index.js",
"./connections/*": "./dist/connections/*"
"./connections": "./dist/connections.js",
"./types": "./dist/types.js"
},
"files": [
"dist/*"
Expand Down
Expand Up @@ -14,13 +14,4 @@
limitations under the License.
*/

export default {
import: {
path: 'connections/SendGridMail/SendGridMailSend/SendGridMailSend.js',
schema: 'connections/SendGridMail/SendGridMailSend/SendGridMailSendSchema.json',
},
meta: {
checkRead: false,
checkWrite: false,
},
};
export { default as SendGridMail } from './connections/SendGridMail/SendGridMail.js';
Expand Up @@ -15,11 +15,10 @@
*/

import SendGridMailSend from './SendGridMailSend/SendGridMailSend.js';
import schema from './schema.js';

export default {
import: {
schema: 'connections/SendGridMail/SendGridMailSchema.json',
},
schema,
requests: {
SendGridMailSend,
},
Expand Down
Expand Up @@ -16,7 +16,8 @@

import { validate } from '@lowdefy/ajv';
import SendGridMail from './SendGridMail.js';
import schema from './SendGridMailSchema.json';

const schema = SendGridMail.schema;

test('All requests are present', () => {
expect(SendGridMail.requests.SendGridMailSend).toBeDefined();
Expand Down

This file was deleted.

Expand Up @@ -16,12 +16,12 @@

import sendgrid from '@sendgrid/mail';
import { type } from '@lowdefy/helpers';
import schema from './SendGridMailSendSchema.json';
import schema from './schema.js';

// https://sendgrid.api-docs.io/v3.0/how-to-use-the-sendgrid-v3-api/api-authentication
// https://github.com/sendgrid/sendgrid-nodejs/blob/master/docs/use-cases/README.md#email-use-cases

async function sendGridMailSend({ request, connection }) {
async function SendGridMailSend({ request, connection }) {
const { apiKey, from, templateId, mailSettings } = connection;
sendgrid.setApiKey(apiKey);
const messages = (type.isArray(request) ? request : [request]).map((msg) => ({
Expand All @@ -41,4 +41,10 @@ async function sendGridMailSend({ request, connection }) {
return { response: 'Mail sent successfully' };
}

export default sendGridMailSend;
SendGridMailSend.schema = schema;
SendGridMailSend.meta = {
checkRead: false,
checkWrite: false,
};

export default SendGridMailSend;
Expand Up @@ -15,8 +15,10 @@
*/

import { validate } from '@lowdefy/ajv';
import sendGridMailSend from './SendGridMailSend.js';
import schema from './SendGridMailSendSchema.json';
import SendGridMailSend from './SendGridMailSend.js';

const { checkRead, checkWrite } = SendGridMailSend.meta;
const schema = SendGridMailSend.schema;

const mockSend = jest.fn();

Expand Down Expand Up @@ -53,7 +55,7 @@ test('send with valid request and connection', async () => {
apiKey: 'X',
from: { name: 'a@b.om', email: 'a.cc@mm.co' },
};
const send = await sendGridMailSend({ request, connection });
const send = await SendGridMailSend({ request, connection });
expect(mockSend.mock.calls).toEqual([
[
[
Expand Down Expand Up @@ -83,7 +85,7 @@ test('send to list of emails', async () => {
apiKey: 'X',
from: 'x@y.com',
};
const send = await sendGridMailSend({ request, connection });
const send = await SendGridMailSend({ request, connection });
expect(mockSend.mock.calls).toEqual([
[
[
Expand Down Expand Up @@ -120,7 +122,7 @@ test('send a list of different emails', async () => {
apiKey: 'X',
from: 'x@y.com',
};
const send = await sendGridMailSend({ request, connection });
const send = await SendGridMailSend({ request, connection });
expect(mockSend.mock.calls).toEqual([
[
[
Expand Down Expand Up @@ -220,7 +222,7 @@ test('request throws an error', async () => {
apiKey: 'X',
from: { name: 'a@b.om', email: 'a.cc@mm.co' },
};
await expect(() => sendGridMailSend({ request, connection })).rejects.toThrow('Test error.');
await expect(() => SendGridMailSend({ request, connection })).rejects.toThrow('Test error.');
});

test('request throws an error with response body', async () => {
Expand All @@ -233,7 +235,15 @@ test('request throws an error with response body', async () => {
apiKey: 'X',
from: { name: 'a@b.om', email: 'a.cc@mm.co' },
};
await expect(() => sendGridMailSend({ request, connection })).rejects.toThrow(
await expect(() => SendGridMailSend({ request, connection })).rejects.toThrow(
'["Test error 1.","Test error 2."]'
);
});

test('checkRead should be false', async () => {
expect(checkRead).toBe(false);
});

test('checkWrite should be false', async () => {
expect(checkWrite).toBe(false);
});

0 comments on commit c139cd4

Please sign in to comment.