Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection Sendgrid V4 #1074

Merged
merged 4 commits into from Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -65,6 +65,7 @@
"@lowdefy/connection-axios-http": "4.0.0-alpha.6",
"@lowdefy/connection-elasticsearch": "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 @@ -29,6 +29,7 @@ const defaultPackages = [
'@lowdefy/connection-axios-http',
'@lowdefy/connection-elasticsearch',
'@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);
});