-
-
Notifications
You must be signed in to change notification settings - Fork 703
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(restapi): add emailSend action (#2042)
* feat(restapi): add emailSend action * added emailSend reducer Co-authored-by: Giulia Ghisini <giulia.ghisini@redturtle.it>
- Loading branch information
1 parent
ac97e22
commit 4985607
Showing
8 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* emailNotification actions. | ||
* @module actions/emailNotification/emailNotification | ||
*/ | ||
|
||
import { EMAIL_SEND } from '@plone/volto/constants/ActionTypes'; | ||
|
||
/** | ||
* Email send function | ||
* @function emailSend | ||
* @param {string} name New password. | ||
* @param {string} from Sender mail address. | ||
* @param {string} to Receiver mail address. | ||
* @param {string} subject Email subject. | ||
* @param {string} message Email message. | ||
* @returns {Object} Edit emailSend action. | ||
*/ | ||
export function emailSend(name, from, to, subject, message) { | ||
return { | ||
type: EMAIL_SEND, | ||
request: { | ||
op: 'post', | ||
path: '/@email-send', | ||
data: { | ||
name, | ||
from, | ||
to, | ||
subject, | ||
message, | ||
}, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { emailSend } from './emailSend'; | ||
import { EMAIL_SEND } from '@plone/volto/constants/ActionTypes'; | ||
|
||
describe('Send email message', () => { | ||
describe('emailSend', () => { | ||
it('should create an action to send a mail notification', () => { | ||
const action = emailSend( | ||
'John Doe', | ||
'john@doe.com', | ||
'jane@doe.com', | ||
'Hello!', | ||
'Just want to say hi.', | ||
); | ||
|
||
expect(action.type).toEqual(EMAIL_SEND); | ||
expect(action.request.op).toEqual('post'); | ||
expect(action.request.path).toEqual('/@email-send'); | ||
expect(action.request.data).toEqual({ | ||
name: 'John Doe', | ||
from: 'john@doe.com', | ||
to: 'jane@doe.com', | ||
subject: 'Hello!', | ||
message: 'Just want to say hi.', | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* emailSend reducer. | ||
* @module reducers/emailSend/emailSend | ||
*/ | ||
|
||
import { EMAIL_SEND } from '@plone/volto/constants/ActionTypes'; | ||
|
||
const initialState = { | ||
error: null, | ||
loaded: false, | ||
loading: false, | ||
}; | ||
|
||
/** | ||
* emailSend reducer. | ||
* @function emailSend | ||
* @param {Object} state Current state. | ||
* @param {Object} action Action to be handled. | ||
* @returns {Object} New state. | ||
*/ | ||
export default function emailSend(state = initialState, action = {}) { | ||
switch (action.type) { | ||
case `${EMAIL_SEND}_PENDING`: | ||
return { | ||
...state, | ||
error: null, | ||
loaded: false, | ||
loading: true, | ||
}; | ||
case `${EMAIL_SEND}_SUCCESS`: | ||
return { | ||
...state, | ||
error: null, | ||
loaded: true, | ||
loading: false, | ||
}; | ||
case `${EMAIL_SEND}_FAIL`: | ||
return { | ||
...state, | ||
error: action.error, | ||
loaded: false, | ||
loading: false, | ||
}; | ||
default: | ||
return state; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import emailSend from './emailSend'; | ||
import { EMAIL_SEND } from '@plone/volto/constants/ActionTypes'; | ||
|
||
describe('emailSend reducer', () => { | ||
it('should return the initial state', () => { | ||
expect(emailSend()).toEqual({ | ||
error: null, | ||
loaded: false, | ||
loading: false, | ||
}); | ||
}); | ||
|
||
it('should handle EMAIL_SEND_PENDING', () => { | ||
expect( | ||
emailSend(undefined, { | ||
type: `${EMAIL_SEND}_PENDING`, | ||
}), | ||
).toEqual({ | ||
error: null, | ||
loaded: false, | ||
loading: true, | ||
}); | ||
}); | ||
|
||
it('should handle EMAIL_SEND_SUCCESS', () => { | ||
expect( | ||
emailSend(undefined, { | ||
type: `${EMAIL_SEND}_SUCCESS`, | ||
}), | ||
).toEqual({ | ||
error: null, | ||
loaded: true, | ||
loading: false, | ||
}); | ||
}); | ||
|
||
it('should handle EMAIL_SEND_FAIL', () => { | ||
expect( | ||
emailSend(undefined, { | ||
type: `${EMAIL_SEND}_FAIL`, | ||
error: 'failed', | ||
}), | ||
).toEqual({ | ||
error: 'failed', | ||
loaded: false, | ||
loading: false, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters