Skip to content

Commit

Permalink
Merge pull request #28 from nick13jaremek/feature/platforms-refactor
Browse files Browse the repository at this point in the history
Feature/platforms refactor
  • Loading branch information
luismesas committed Aug 17, 2015
2 parents 89ed065 + b9bde2a commit 03a524a
Show file tree
Hide file tree
Showing 51 changed files with 634 additions and 346 deletions.
3 changes: 2 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"mailgun": {
"apiKey": "",
"domain": "",
"batch_limit": 1000
"batch_limit": 1000,
"custom_batch_limit": 10
}
},
"twilio": {
Expand Down
6 changes: 6 additions & 0 deletions config/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@
},
"mongoose": {
"debug": false
},
"mailer": {
"mailgun": {
"batch_limit": 1000,
"custom_batch_limit": 2
}
}
}
11 changes: 7 additions & 4 deletions cucumber/features/email_features/email_send.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ Feature: the server receives a request to send an email
Then a request is sent to <endpoint> to send an email <email> and returns <response>

Examples:
| identity_id | endpoint | email | response |
| 01f0000000000000003f0001 | /api/notification/email | email/valid_email.json | email/valid_email_response.json |
| 01f0000000000000003f0002 | /api/notification/email | email/invalid_to_email.json | email/invalid_to_email_response.json |
| 01f0000000000000003f0003 | /api/notification/email | email/invalid_from_email.json | email/invalid_from_email_response.json |
| identity_id | endpoint | email | response |
| 01f0000000000000003f0001 | /api/notification/email | email/valid_email_over_batch_limit.json | email/valid_email_response.json |
| 01f0000000000000003f0001 | /api/notification/email | email/valid_email_under_batch_limit.json | email/valid_email_response.json |
| 01f0000000000000003f0002 | /api/notification/email | email/invalid_to_email.json | email/invalid_to_email_response.json |
| 01f0000000000000003f0003 | /api/notification/email | email/invalid_from_email.json | email/invalid_from_email_response.json |
| 01f0000000000000003f0001 | /api/notification/email | email/empty_email.json | email/empty_email_response.json |
| 01f0000000000000003f0002 | /api/notification/email | email/missing_email_message.json | email/missing_email_message_response.json |
13 changes: 12 additions & 1 deletion cucumber/features/identity_features/identity_create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,15 @@ Feature: A requester asks for the creation of an identity object
| endpoint | request_contents | status |
| /api/identity | identity/valid_identity_sms | 201 |
| /api/identity | identity/valid_identity_apn | 201 |
| /api/identity | identity/duplicated_identity | 409 |
| /api/identity | identity/duplicated_identity | 409 |

Scenario Outline: check the number of channels of a new identity object based on the request body contents
When someone makes a POST to <endpoint> with content <request_contents>
Then the backend responds with <status>
And next GET request to <endpoint> returns a response with <num_channels> channels

Examples:
| endpoint | request_contents | status | num_channels |
| /api/identity | identity/valid_identity_with_existing_channels | 201 | 2 |
| /api/identity | identity/valid_identity_with_one_existing_channel | 201 | 1 |
| /api/identity | identity/valid_identity_without_channels | 201 | 0 |
31 changes: 17 additions & 14 deletions cucumber/features/identity_features/identity_edit_profile.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,28 @@ Feature: A requester attempts to modify the data for a given identity

Scenario Outline: edit the profile data associated to the requester's identity object
Given an authenticated identity in the app with <identity_id>
When a user makes a PUT to <endpoint> to change his <name> field with value <value>
When a user makes a PUT to <endpoint> to change his <field_name> field with value <value>
Then the backend responds with <status>
And the next GET request to <endpoint> returns the identity with <name> field with value <value>
And the next GET request to <endpoint> returns the identity with <field_name> field with value <value>

Examples:
| identity_id | endpoint | status | name | value |
| 01f0000000000000003f0001 | /api/identity | 204 | devices.apn | identity/changed_apn_identity.json |
| 01f0000000000000003f0002 | /api/identity | 204 | devices.gcm | identity/changed_gcm_identity.json |
| 01f0000000000000003f0003 | /api/identity | 204 | devices.email | identity/changed_email_identity.json |
| 01f0000000000000003f0003 | /api/identity | 204 | devices.phone | identity/changed_phone_identity.json |
| 01f0000000000000003f0003 | /api/identity | 204 | devices.sms | identity/changed_sms_identity.json |
| identity_id | endpoint | status | field_name | value |
| 01f0000000000000003f0001 | /api/identity | 204 | devices.apn | identity/changed_apn_identity.json |
| 01f0000000000000003f0002 | /api/identity | 204 | devices.gcm | identity/changed_gcm_identity.json |
| 01f0000000000000003f0003 | /api/identity | 204 | devices.email | identity/changed_email_identity.json |
| 01f0000000000000003f0003 | /api/identity | 204 | devices.phone | identity/changed_phone_identity.json |
| 01f0000000000000003f0003 | /api/identity | 204 | devices.sms | identity/changed_sms_identity.json |
| 01f0000000000000003f0002 | /api/identity | 204 | channels | identity/changed_channels_identity.json |


Scenario Outline: edit the profile data associated to the requester's identity object
Scenario Outline: check the response when editing the profile data associated to the requester's identity object
Given an authenticated identity in the app with <identity_id>
When a user makes a PUT to <endpoint> to change his <name> field with value <value>
When a user makes a PUT to <endpoint> to change his <field_name> field with value <value>
Then the backend responds with <status>

Examples:
| identity_id | endpoint | status | name | value |
| 01f0000000000000003f0001 | /api/identity | 204 | devices.apn | identity/changed_apn_identity.json |
| 01f0000000000000003fasdf | /api/identity | 400 | devices.sms | identity/changed_sms_identity.json |
| identity_id | endpoint | status | field_name | value |
| 01f0000000000000003f0001 | /api/identity | 204 | devices.apn | identity/changed_apn_identity.json |
| 01f0000000000000003f0002 | /api/identity | 204 | channels | identity/changed_channels_identity.json |
| 01f0000000000000003f0002 | /api/identity | 204 | channels | identity/changed_channels_identity.json |
| 01f0000000000000003fasdf | /api/identity | 400 | devices.sms | identity/changed_sms_identity.json |
| 01f0000000000000003f0001 | /api/identity | 204 | channels | identity/non_existing_channel_name.json |
18 changes: 10 additions & 8 deletions cucumber/features/sms_features/sms_send_message.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ Feature: the server receives a request to send SMS messages
Then a mock request is sent to <endpoint> to send an SMS message <sms> and returns <response>

Examples:
| identity_id | endpoint | sms | response |
| 01f0000000000000003f0001 | /api/notification/sms | sms/valid_sms.json | sms/valid_sms_response.json |
| 01f0000000000000003f0002 | /api/notification/sms | sms/missing_to_phone.json | sms/missing_to_phone_response.json |
| 01f0000000000000003f0003 | /api/notification/sms | sms/missing_from_phone.json | sms/missing_from_phone_response.json |
| 01f0000000000000003f0003 | /api/notification/sms | sms/missing_message_sms.json | sms/missing_message_sms_response.json |
| 01f0000000000000003f0003 | /api/notification/sms | sms/empty_message_sms.json | sms/missing_message_sms_response.json |
| 01f0000000000000003f0003 | /api/notification/sms | sms/empty_to_phone.json | sms/missing_to_phone_response.json |
| 01f0000000000000003f0003 | /api/notification/sms | sms/empty_from_phone.json | sms/missing_from_phone_response.json |
| identity_id | endpoint | sms | response |
| 01f0000000000000003f0001 | /api/notification/sms | sms/valid_sms.json | sms/valid_sms_response.json |
| 01f0000000000000003f0001 | /api/notification/sms | sms/empty_sms.json | sms/empty_sms_response.json |
| 01f0000000000000003f0001 | /api/notification/sms | sms/over_length_limit_sms.json | sms/over_length_limit_sms_response.json |
| 01f0000000000000003f0002 | /api/notification/sms | sms/missing_to_phone.json | sms/missing_to_phone_response.json |
| 01f0000000000000003f0003 | /api/notification/sms | sms/missing_from_phone.json | sms/missing_from_phone_response.json |
| 01f0000000000000003f0003 | /api/notification/sms | sms/missing_message_sms.json | sms/missing_message_sms_response.json |
| 01f0000000000000003f0003 | /api/notification/sms | sms/empty_message_sms.json | sms/missing_message_sms_response.json |
| 01f0000000000000003f0003 | /api/notification/sms | sms/empty_to_phone.json | sms/missing_to_phone_response.json |
| 01f0000000000000003f0003 | /api/notification/sms | sms/empty_from_phone.json | sms/missing_from_phone_response.json |
6 changes: 3 additions & 3 deletions cucumber/features/step_definitions/email_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ module.exports = function() {
var MAILGUN_MESSAGES_ENDPOINT_URL = '/v3/' + config.get('mailer.mailgun.domain') + '/messages';

nock(MAILGUN_MESSAGES_BASE_URL)
.post(MAILGUN_MESSAGES_ENDPOINT_URL)
.times(1)
.reply(200, res.data);
.persist() // Required since multiple requests can be made in parallel from the platform
.post(MAILGUN_MESSAGES_ENDPOINT_URL)
.reply(200, res.data);

var request = this.buildRequest('POST', endpoint, {
'x-user-id': this.get('identity')
Expand Down
25 changes: 25 additions & 0 deletions cucumber/features/step_definitions/identity_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,29 @@ module.exports = function() {

return callback();
});

this.Then(/^next GET request to (.*) returns a response with (.*) channels$/, function(endpoint, numChannels, callback) {

numChannels = Number(numChannels);

var createdIdentityId = this.get('response').body.id;

var request = this.buildRequest('GET', endpoint, {
'x-user-id': createdIdentityId
});

request
.expect(200)
.end(function(err, response) {

if (err) {
return callback(err);
}

var responseChannelsNumber = response.body.channels.length;
assert.equal(responseChannelsNumber, numChannels, 'Number of channels does not match');

return callback();
});
});
};
1 change: 1 addition & 0 deletions cucumber/test_files/email/empty_email.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
7 changes: 7 additions & 0 deletions cucumber/test_files/email/empty_email_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"status": 400,
"data": {
"code": "BadRequestError",
"message": "Missing email parameters"
}
}
2 changes: 1 addition & 1 deletion cucumber/test_files/email/invalid_from_email.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"identities": ["01f0000000000000003f0002"],
"channels": ["01f0000000000000006f0001"],
"channels": ["buddies"],
"content": {
"from": "",
"message": "The \\'from\\' email is invalid"
Expand Down
7 changes: 7 additions & 0 deletions cucumber/test_files/email/missing_email_message.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"identities": ["01f0000000000000003f0002"],
"channels": ["buddies"],
"content": {
"from": "noreply@email.com"
}
}
7 changes: 7 additions & 0 deletions cucumber/test_files/email/missing_email_message_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"status": 400,
"data": {
"code": "BadRequestError",
"message": "Missing 'message' property in parameters"
}
}
File renamed without changes.
3 changes: 1 addition & 2 deletions cucumber/test_files/email/valid_email_response.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"status": 200,
"data": {
"id": "<20150729090542.29416.27304@sandboxd41385ca8b5f40eda0c863e41dc6e997.mailgun.org>",
"message": "Queued. Thank you."
"output": "Queued notifications"
}
}
8 changes: 8 additions & 0 deletions cucumber/test_files/email/valid_email_under_batch_limit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"identities": ["01f0000000000000003f0002"],
"channels": [],
"content": {
"from": "noreply@email.com",
"message": "This is the body of the email"
}
}
3 changes: 3 additions & 0 deletions cucumber/test_files/identity/changed_channels_identity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"channels": ["buddies"]
}
3 changes: 3 additions & 0 deletions cucumber/test_files/identity/empty_channel_names.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"channels": []
}
3 changes: 3 additions & 0 deletions cucumber/test_files/identity/non_existing_channel_name.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"channels": ["non_valid_channel_name"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"devices": {
"sms": [],
"email": ["john@appleseed.com"],
"phone": [],
"apn": [],
"gcm": []
},
"channels": ["friends", "buddies"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"devices": {
"sms": [],
"email": [],
"phone": [],
"apn": [],
"gcm": []
},
"channels": ["buddies", "friends", "non_existing", "another_non_existing"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"devices": {
"sms": [],
"email": [],
"phone": [],
"apn": [],
"gcm": []
},
"channels": ["friends"]
}
10 changes: 10 additions & 0 deletions cucumber/test_files/identity/valid_identity_without_channels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"devices": {
"sms": [],
"email": ["john@appleseed.com"],
"phone": [],
"apn": [],
"gcm": []
},
"channels": []
}
9 changes: 6 additions & 3 deletions cucumber/test_files/sms/empty_from_phone.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"to": ["+15005550010", "+15005550011"],
"from": "",
"message": "This should raise a middleware 'Missing from' error"
"identities": ["01f0000000000000003f0002", "01f0000000000000003f0003"],
"channels": ["friends"],
"content": {
"from": "",
"message": "Hello there!"
}
}
9 changes: 6 additions & 3 deletions cucumber/test_files/sms/empty_message_sms.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"to": ["+15005550010", "+15005550011"],
"from": "+15005550006",
"message": ""
"identities": ["01f0000000000000003f0002", "01f0000000000000003f0003"],
"channels": ["friends"],
"content": {
"from": "+15005550006",
"message": ""
}
}
1 change: 1 addition & 0 deletions cucumber/test_files/sms/empty_sms.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
7 changes: 7 additions & 0 deletions cucumber/test_files/sms/empty_sms_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"status": 400,
"data": {
"code": "BadRequestError",
"message": "Missing SMS parameters"
}
}
9 changes: 6 additions & 3 deletions cucumber/test_files/sms/empty_to_phone.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"to": [],
"from": "+15005550006",
"message": "This should raise a middleware 'Missing to' error"
"identities": [],
"channels": [],
"content": {
"from": "+15005550006",
"message": "This should raise a middleware 'Missing to' error"
}
}
7 changes: 5 additions & 2 deletions cucumber/test_files/sms/missing_from_phone.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"to": ["+15005550006"],
"message": "This should raise a middleware error."
"identities": ["01f0000000000000003f0002", "01f0000000000000003f0003"],
"channels": ["friends"],
"content": {
"message": "Hello there!"
}
}
2 changes: 1 addition & 1 deletion cucumber/test_files/sms/missing_from_phone_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"status": 400,
"data": {
"code": "BadRequestError",
"message": "Missing 'from' property in SMS object"
"message": "Missing 'from' property in parameters"
}
}
7 changes: 5 additions & 2 deletions cucumber/test_files/sms/missing_message_sms.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"to": ["+15005550010", "+15005550011"],
"from": "+15005550006"
"identities": ["01f0000000000000003f0002", "01f0000000000000003f0003"],
"channels": ["friends"],
"content": {
"from": "15005550006"
}
}
2 changes: 1 addition & 1 deletion cucumber/test_files/sms/missing_message_sms_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"status": 400,
"data": {
"code": "BadRequestError",
"message": "Missing 'message' property in SMS object"
"message": "Missing 'message' property in parameters"
}
}
6 changes: 4 additions & 2 deletions cucumber/test_files/sms/missing_to_phone.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"from": "+15005550006",
"message": "This should raise a middleware error"
"content": {
"from": "15005550006",
"message": "This should raise a middleware error"
}
}
2 changes: 1 addition & 1 deletion cucumber/test_files/sms/missing_to_phone_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"status": 400,
"data": {
"code": "BadRequestError",
"message": "Missing 'to' property in SMS object"
"message": "The request body must contain at least one target channel or identity"
}
}
Loading

0 comments on commit 03a524a

Please sign in to comment.