Skip to content

Commit

Permalink
upgrade dev dependencies + linting
Browse files Browse the repository at this point in the history
  • Loading branch information
BDav24 committed Oct 15, 2018
1 parent 842903a commit 73b0d6b
Show file tree
Hide file tree
Showing 88 changed files with 860 additions and 804 deletions.
30 changes: 15 additions & 15 deletions __tests__/notifme-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import NotifmeSdk from '../src'

const sdk = new NotifmeSdk({})
// $FlowIgnore
sdk.sender = {send: jest.fn()}
sdk.sender = { send: jest.fn() }

test('NotifmeSdk.send should call internal sender send method.', () => {
const request = {
sms: {from: 'Notifme', to: '+15000000001', text: 'Hello John! How are you?'}
sms: { from: 'Notifme', to: '+15000000001', text: 'Hello John! How are you?' }
}
sdk.send(request)
expect(sdk.sender.send).toBeCalledWith(request)
Expand Down Expand Up @@ -51,27 +51,27 @@ const config = {
channels: {
email: {
multiProviderStrategy: 'no-fallback',
providers: [{type: 'logger'}]
providers: [{ type: 'logger' }]
},
sms: {
multiProviderStrategy: 'no-fallback',
providers: [{type: 'logger'}]
providers: [{ type: 'logger' }]
},
voice: {
multiProviderStrategy: 'no-fallback',
providers: [{type: 'logger'}]
providers: [{ type: 'logger' }]
},
push: {
multiProviderStrategy: 'no-fallback',
providers: [{type: 'logger'}]
providers: [{ type: 'logger' }]
},
slack: {
multiProviderStrategy: 'no-fallback',
providers: [{type: 'logger'}]
providers: [{ type: 'logger' }]
},
webpush: {
multiProviderStrategy: 'no-fallback',
providers: [{type: 'logger'}]
providers: [{ type: 'logger' }]
}
}
}
Expand Down Expand Up @@ -100,32 +100,32 @@ test('mergeWithDefaultConfig should merge config with default if not complete.',
})

test('mergeWithDefaultConfig should ignore config if useNotificationCatcher is true.', () => {
expect(sdk.mergeWithDefaultConfig({...config, useNotificationCatcher: true})).toEqual({
expect(sdk.mergeWithDefaultConfig({ ...config, useNotificationCatcher: true })).toEqual({
useNotificationCatcher: true,
channels: {
email: {
multiProviderStrategy: 'no-fallback',
providers: [{type: 'notificationcatcher'}]
providers: [{ type: 'notificationcatcher' }]
},
sms: {
multiProviderStrategy: 'no-fallback',
providers: [{type: 'notificationcatcher'}]
providers: [{ type: 'notificationcatcher' }]
},
voice: {
multiProviderStrategy: 'no-fallback',
providers: [{type: 'notificationcatcher'}]
providers: [{ type: 'notificationcatcher' }]
},
slack: {
multiProviderStrategy: 'no-fallback',
providers: [{type: 'notificationcatcher'}]
providers: [{ type: 'notificationcatcher' }]
},
push: {
multiProviderStrategy: 'no-fallback',
providers: [{type: 'notificationcatcher'}]
providers: [{ type: 'notificationcatcher' }]
},
webpush: {
multiProviderStrategy: 'no-fallback',
providers: [{type: 'notificationcatcher'}]
providers: [{ type: 'notificationcatcher' }]
}
}
})
Expand Down
6 changes: 3 additions & 3 deletions __tests__/providers/email/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test('email unknown provider.', async () => {
expect(result).toEqual({
status: 'success',
channels: {
email: {id: 'custom-returned-id', providerId: 'my-custom-email-provider'}
email: { id: 'custom-returned-id', providerId: 'my-custom-email-provider' }
}
})
})
Expand All @@ -46,7 +46,7 @@ test('email custom provider.', async () => {
type: 'unknown'
}]
}
}})
} })
)).toThrow('Unknown email provider "unknown".')
})

Expand All @@ -64,7 +64,7 @@ test('email logger provider.', async () => {
expect(result).toEqual({
status: 'success',
channels: {
email: {id: expect.stringContaining('id-'), providerId: 'email-logger-provider'}
email: { id: expect.stringContaining('id-'), providerId: 'email-logger-provider' }
}
})
})
16 changes: 8 additions & 8 deletions __tests__/providers/email/mailgun.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @flow */
/* global jest, test, expect */
import NotifmeSdk from '../../../src'
import mockHttp, {mockResponse} from '../mockHttp'
import mockHttp, { mockResponse } from '../mockHttp'

jest.mock('../../../src/util/logger', () => ({
warn: jest.fn()
Expand Down Expand Up @@ -29,7 +29,7 @@ const request = {
}

test('Mailgun success with minimal parameters.', async () => {
mockResponse(200, JSON.stringify({id: 'returned-id'}))
mockResponse(200, JSON.stringify({ id: 'returned-id' }))
const result = await sdk.send(request)
expect(mockHttp).lastCalledWith(expect.objectContaining({
hostname: 'api.mailgun.net',
Expand All @@ -48,13 +48,13 @@ test('Mailgun success with minimal parameters.', async () => {
expect(result).toEqual({
status: 'success',
channels: {
email: {id: 'returned-id', providerId: 'email-mailgun-provider'}
email: { id: 'returned-id', providerId: 'email-mailgun-provider' }
}
})
})

test('Mailgun success with all parameters.', async () => {
mockResponse(200, JSON.stringify({id: 'returned-id'}))
mockResponse(200, JSON.stringify({ id: 'returned-id' }))
const completeRequest = {
metadata: {
id: '24',
Expand All @@ -66,7 +66,7 @@ test('Mailgun success with all parameters.', async () => {
subject: 'Hi John',
html: '<b>Hello John! How are you?</b>',
replyTo: '[email protected]',
headers: {'My-Custom-Header': 'my-value'},
headers: { 'My-Custom-Header': 'my-value' },
cc: ['[email protected]', '[email protected]'],
bcc: ['[email protected]'],
attachments: [{
Expand Down Expand Up @@ -94,21 +94,21 @@ test('Mailgun success with all parameters.', async () => {
expect(result).toEqual({
status: 'success',
channels: {
email: {id: 'returned-id', providerId: 'email-mailgun-provider'}
email: { id: 'returned-id', providerId: 'email-mailgun-provider' }
}
})
})

test('Mailgun API error.', async () => {
mockResponse(400, JSON.stringify({message: 'error!'}))
mockResponse(400, JSON.stringify({ message: 'error!' }))
const result = await sdk.send(request)
expect(result).toEqual({
status: 'error',
errors: {
email: '400 - error!'
},
channels: {
email: {id: undefined, providerId: 'email-mailgun-provider'}
email: { id: undefined, providerId: 'email-mailgun-provider' }
}
})
})
6 changes: 3 additions & 3 deletions __tests__/providers/email/notificationCatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ const request = {

test('email notification catcher provider should use SMTP provider.', async () => {
const result = await sdk.send(request)
const {to, from, html, text, subject, replyTo} = request.email
const { to, from, html, text, subject, replyTo } = request.email
expect(mockSend).lastCalledWith({
to, from, html, text, subject, replyTo, headers: {'X-to': `[email] ${to}`}
to, from, html, text, subject, replyTo, headers: { 'X-to': `[email] ${to}` }
})
expect(result).toEqual({
status: 'success',
channels: {
email: {id: undefined, providerId: 'email-notificationcatcher-provider'}
email: { id: undefined, providerId: 'email-notificationcatcher-provider' }
}
})
})
14 changes: 7 additions & 7 deletions __tests__/providers/email/sendgrid.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @flow */
/* global jest, test, expect */
import NotifmeSdk from '../../../src'
import mockHttp, {mockResponse} from '../mockHttp'
import mockHttp, { mockResponse } from '../mockHttp'

jest.mock('../../../src/util/logger', () => ({
warn: jest.fn()
Expand Down Expand Up @@ -50,7 +50,7 @@ test('Sendgrid success with minimal parameters.', async () => {
expect(result).toEqual({
status: 'success',
channels: {
email: {id: expect.stringMatching(/\w*/), providerId: 'email-sendgrid-provider'}
email: { id: expect.stringMatching(/\w*/), providerId: 'email-sendgrid-provider' }
}
})
})
Expand All @@ -68,7 +68,7 @@ test('Sendgrid success with all parameters.', async () => {
subject: 'Hi John',
html: '<b>Hello John! How are you?</b>',
replyTo: '[email protected]',
headers: {'My-Custom-Header': 'my-value'},
headers: { 'My-Custom-Header': 'my-value' },
cc: ['[email protected]', '[email protected]'],
bcc: ['[email protected]'],
attachments: [{
Expand Down Expand Up @@ -99,7 +99,7 @@ test('Sendgrid success with all parameters.', async () => {
expect(result).toEqual({
status: 'success',
channels: {
email: {id: '24', providerId: 'email-sendgrid-provider'}
email: { id: '24', providerId: 'email-sendgrid-provider' }
}
})
})
Expand Down Expand Up @@ -143,21 +143,21 @@ test('Sendgrid success with buffered attachment.', async () => {
expect(result).toEqual({
status: 'success',
channels: {
email: {id: '24', providerId: 'email-sendgrid-provider'}
email: { id: '24', providerId: 'email-sendgrid-provider' }
}
})
})

test('Sendgrid API error.', async () => {
mockResponse(400, JSON.stringify({errors: [{code: '24', message: 'error!'}]}))
mockResponse(400, JSON.stringify({ errors: [{ code: '24', message: 'error!' }] }))
const result = await sdk.send(request)
expect(result).toEqual({
status: 'error',
errors: {
email: '400 - code: 24, message: error!'
},
channels: {
email: {id: undefined, providerId: 'email-sendgrid-provider'}
email: { id: undefined, providerId: 'email-sendgrid-provider' }
}
})
})
4 changes: 2 additions & 2 deletions __tests__/providers/email/sendmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import NotifmeSdk from '../../../src'

const mockSendMail = jest.fn()
mockSendMail.mockReturnValue({messageId: 'returned-id'})
mockSendMail.mockReturnValue({ messageId: 'returned-id' })
jest.mock('nodemailer', () => ({
createTransport: () => ({
sendMail: mockSendMail
Expand Down Expand Up @@ -41,7 +41,7 @@ test('Sendmail should use nodemailer.', async () => {
expect(result).toEqual({
status: 'success',
channels: {
email: {id: 'returned-id', providerId: 'email-sendmail-provider'}
email: { id: 'returned-id', providerId: 'email-sendmail-provider' }
}
})
})
10 changes: 5 additions & 5 deletions __tests__/providers/email/ses.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @flow */
/* global jest, test, expect */
import NotifmeSdk from '../../../src'
import mockHttp, {mockResponse} from '../mockHttp'
import mockHttp, { mockResponse } from '../mockHttp'

jest.mock('../../../src/util/logger', () => ({
warn: jest.fn()
Expand Down Expand Up @@ -56,21 +56,21 @@ test('SES success with minimal parameters.', async () => {
expect(result).toEqual({
status: 'success',
channels: {
email: {id: 'returned-id', providerId: 'email-ses-provider'}
email: { id: 'returned-id', providerId: 'email-ses-provider' }
}
})
})

test('SES should return an error if a parameter is not of the right type.', async () => {
// $FlowIgnore
const result = await sdk.send({email: {text: []}})
const result = await sdk.send({ email: { text: [] } })
expect(result).toEqual({
status: 'error',
errors: {
email: 'The "chunk" argument must be one of type string or Buffer. Received type object'
},
channels: {
email: {id: undefined, providerId: 'email-ses-provider'}
email: { id: undefined, providerId: 'email-ses-provider' }
}
})
})
Expand All @@ -84,7 +84,7 @@ test('SES API error.', async () => {
email: '400 - error!'
},
channels: {
email: {id: undefined, providerId: 'email-ses-provider'}
email: { id: undefined, providerId: 'email-ses-provider' }
}
})
})
4 changes: 2 additions & 2 deletions __tests__/providers/email/smtp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import NotifmeSdk from '../../../src'

const mockSendMail = jest.fn()
mockSendMail.mockReturnValue({messageId: 'returned-id'})
mockSendMail.mockReturnValue({ messageId: 'returned-id' })
jest.mock('nodemailer', () => ({
createTransport: () => ({
sendMail: mockSendMail
Expand Down Expand Up @@ -42,7 +42,7 @@ test('Smtp should use nodemailer.', async () => {
expect(result).toEqual({
status: 'success',
channels: {
email: {id: 'returned-id', providerId: 'email-smtp-provider'}
email: { id: 'returned-id', providerId: 'email-smtp-provider' }
}
})
})
Loading

0 comments on commit 73b0d6b

Please sign in to comment.