Skip to content

Commit

Permalink
Simplified 'template' Cucumber tests. Updated docs. Simplified 'templ…
Browse files Browse the repository at this point in the history
…ate' listing param handling.
  • Loading branch information
nick13jaremek committed Apr 28, 2016
1 parent 0bcab07 commit 94e06a3
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 161 deletions.
2 changes: 1 addition & 1 deletion apiary.apib
Expand Up @@ -646,7 +646,7 @@ Returns a the content of an email template (either HTML or other) and the placeh
"placeholders": ["USER"]
}

+ Response 400
+ Response 404

{
"code": "NotFoundError",
Expand Down
104 changes: 13 additions & 91 deletions cucumber/features/step_definitions/template_steps.js
Expand Up @@ -9,159 +9,81 @@ module.exports = function() {

this.World = require('../support/world').World;

this.Then(/^a template object (.*) is sent to (.*) and creates template successfully with (.*)/, function(requestBody, endpoint, response, callback) {
this.Then(/^a template object (.*) is sent to (.*) yielding (.*)/, function(requestBody, endpoint, response, callback) {
let _this = this;

let requestBodyObj = _this.readJSONResource(requestBody);
let res = _this.readJSONResource(response);

templatePlatformStub.generateHtmlTemplate = sinon.stub(templatePlatform, 'generateHtmlTemplate');
templatePlatformStub.generateHtmlTemplate.yields(res.data.error, res.data.content);
templatePlatformStub.generateHtmlTemplate.yields(res.stubbed.error, res.stubbed.output);

let request = this.buildRequest('POST', endpoint, {
'x-user-id': this.get('identity')
});

request
.send(requestBodyObj)
.expect(res.status)
.end(function(err) {
templatePlatformStub.generateHtmlTemplate.restore();
if (err) {
return callback(err);
}

return callback();
});
});

this.Then(/^a template object (.*) is sent to (.*) and returns error with (.*)/, function(requestBody, endpoint, response, callback) {

let _this = this;

let requestBodyObj = _this.readJSONResource(requestBody);
let res = _this.readJSONResource(response);

templatePlatformStub.generateHtmlTemplate = sinon.stub(templatePlatform, 'generateHtmlTemplate');
templatePlatformStub.generateHtmlTemplate.yields(res.data.error, res.data.content);

let request = this.buildRequest('POST', endpoint, {
'x-user-id': this.get('identity')
});

request
.send(requestBodyObj)
.expect(res.status)
.end(function(err) {
if (err) {
return callback(err);
}
templatePlatformStub.generateHtmlTemplate.restore();

return callback();
});
});

this.Then(/^a request for template listing is sent to (.*) yielding the list of templates in (.*)$/, function(endpoint, response, callback) {
let _this = this;

let res = _this.readJSONResource(response);

templatePlatformStub.getListOfHtmlTemplates = sinon.stub(templatePlatform, 'getListOfHtmlTemplates');
templatePlatformStub.getListOfHtmlTemplates.yields(res.data.error, res.data.content);

let request = this.buildRequest('GET', endpoint, {
'x-user-id': this.get('identity')
});

request
.send()
.expect(res.status)
.expect(res.result.status)
.end(function(err, output) {
templatePlatformStub.getListOfHtmlTemplates.restore();
templatePlatformStub.generateHtmlTemplate.restore();
if (err) {
return callback(err);
}

expect(output.body).to.have.length(res.data.content.length);
expect(output.body).to.deep.equal(res.result.body);
return callback();
});
});

this.Then(/^a request for template listing is sent to (.*) and fails yielding the error in (.*)$/, function(endpoint, response, callback) {
this.Then(/^a request for template listing is sent to (.*) yielding (.*)$/, function(endpoint, response, callback) {
let _this = this;

let res = _this.readJSONResource(response);

templatePlatformStub.getListOfHtmlTemplates = sinon.stub(templatePlatform, 'getListOfHtmlTemplates');
templatePlatformStub.getListOfHtmlTemplates.yields(res.data.error, res.data.content);
templatePlatformStub.getListOfHtmlTemplates.yields(res.stubbed.error, res.stubbed.output);

let request = this.buildRequest('GET', endpoint, {
'x-user-id': this.get('identity')
});

request
.send()
.expect(res.status)
.expect(res.result.status)
.end(function(err, output) {
templatePlatformStub.getListOfHtmlTemplates.restore();
if (err) {
return callback(err);
}

expect(output.body).to.deep.equal(res.data.error);
return callback();
});
});

this.Then(/^a request for template details is sent to (.*) yielding the template in (.*)$/, function(endpoint, response, callback) {
let _this = this;

let res = _this.readJSONResource(response);

templatePlatformStub.getTemplateDetails = sinon.stub(templatePlatform, 'getTemplateDetails');
templatePlatformStub.getTemplateDetails.yields(res.data.error, res.data.content);

let request = this.buildRequest('GET', endpoint, {
'x-user-id': this.get('identity')
});

request
.send()
.expect(res.status)
.end(function(err, output) {
templatePlatformStub.getTemplateDetails.restore();
if (err) {
return callback(err);
}

expect(output.body).to.deep.equal(res.data.content);
expect(output.body).to.deep.equal(res.result.body);
return callback();
});
});

this.Then(/^a request for template details is sent to (.*) and fails yielding the error in (.*)$/, function(endpoint, response, callback) {
this.Then(/^a request for template details is sent to (.*) yielding (.*)$/, function(endpoint, response, callback) {
let _this = this;

let res = _this.readJSONResource(response);

templatePlatformStub.getTemplateDetails = sinon.stub(templatePlatform, 'getTemplateDetails');
templatePlatformStub.getTemplateDetails.yields(res.data.error, res.data.content);
templatePlatformStub.getTemplateDetails.yields(res.stubbed.error, res.stubbed.output);

let request = this.buildRequest('GET', endpoint, {
'x-user-id': this.get('identity')
});

request
.send()
.expect(res.status)
.expect(res.result.status)
.end(function(err, output) {
templatePlatformStub.getTemplateDetails.restore();
if (err) {
return callback(err);
}

expect(output.body).to.deep.equal(res.data.error);
expect(output.body).to.deep.equal(res.result.body);
return callback();
});
});
Expand Down
13 changes: 3 additions & 10 deletions cucumber/features/template_features/template_create.feature
Expand Up @@ -2,16 +2,9 @@ Feature: the server receives a request to create a new email template

Scenario Outline: generate an HTML email template based on the request item
Given an authenticated identity in the app with <identity_id>
Then a template object <body> is sent to <endpoint> and creates template successfully with <response>
Then a template object <body> is sent to <endpoint> yielding <response>

Examples:
| identity_id | endpoint | body | response |
| identity_id | endpoint | body | response |
| 01f0000000000000003f0001 | /api/notification/template | template/valid_template_creation_body.json | template/valid_template_creation_response.js |

Scenario Outline: fail to generate email template based on the request item
Given an authenticated identity in the app with <identity_id>
Then a template object <body> is sent to <endpoint> and returns error with <response>

Examples:
| identity_id | endpoint | body | response |
| 01f0000000000000003f0001 | /api/notification/template | template/invalid_template_creation_body.json | template/invalid_template_creation_response.js |
| 01f0000000000000003f0001 | /api/notification/template | template/invalid_template_creation_body.json | template/invalid_template_creation_response.js |
12 changes: 3 additions & 9 deletions cucumber/features/template_features/template_details.feature
Expand Up @@ -2,16 +2,10 @@ Feature: the server receives a request to send a the details of a given email te

Scenario Outline: return successfully the details associated to a given email template
Given an authenticated identity in the app with <identity_id>
Then a request for template details is sent to <endpoint> yielding the template in <response>
Then a request for template details is sent to <endpoint> yielding <response>

Examples:
| identity_id | endpoint | response |
| 01f0000000000000003f0001 | /api/notification/template/details/some-template.html | template/valid_template_details_response.js |

Scenario Outline: fail to return the details associated to a given email template
Given an authenticated identity in the app with <identity_id>
Then a request for template details is sent to <endpoint> and fails yielding the error in <response>

Examples:
| identity_id | endpoint | response |
| 01f0000000000000003f0001 | /api/notification/template/details/no-file.html | template/invalid_template_details_response.js |
| 01f0000000000000003f0001 | /api/notification/template/details/no-file.html | template/invalid_template_details_response.js |
| 01f0000000000000003f0001 | /api/notification/template/details/invalid-format | template/missing_type_template_details_response.js |
13 changes: 4 additions & 9 deletions cucumber/features/template_features/template_list.feature
@@ -1,17 +1,12 @@

Feature: the server receives a request to send a list of the available email templates

Scenario Outline: list successfully the names of the generated email templates
Given an authenticated identity in the app with <identity_id>
Then a request for template listing is sent to <endpoint> yielding the list of templates in <response>
Then a request for template listing is sent to <endpoint> yielding <response>

Examples:
| identity_id | endpoint | response |
| identity_id | endpoint | response |
| 01f0000000000000003f0001 | /api/notification/template/list | template/valid_template_list_response.js |
| 01f0000000000000003f0001 | /api/notification/template/list | template/invalid_template_list_response.js |

Scenario Outline: fail to list the names of the generated email templates
Given an authenticated identity in the app with <identity_id>
Then a request for template listing is sent to <endpoint> and fails yielding the error in <response>

Examples:
| identity_id | endpoint | response |
| 01f0000000000000003f0001 | /api/notification/template/list | template/invalid_template_list_response.js |
15 changes: 10 additions & 5 deletions cucumber/test_files/template/invalid_template_creation_response.js
@@ -1,12 +1,17 @@
'use strict';

const errors = require('../../../lib/util/errors');

module.exports = {
status: 400,
data: {
error: new errors.BadRequestError('Creation error'),
content: {
output: 'done'
stubbed: {
error: new errors.BadRequestError('Missing or invalid parameters: content, filename, type'),
output: undefined
},
result: {
status: 400,
body: {
code: 'BadRequestError',
message: 'Missing or invalid parameters: content, filename, type'
}
}
};
@@ -1,12 +1,18 @@
'use strict';

module.exports = {
status: 500,
data: {
stubbed: {
error: {
code: 'InternalError',
message: 'Read error'
},
content: undefined
output: undefined
},
result: {
status: 500,
body: {
code: 'InternalError',
message: 'Read error'
}
}
};
14 changes: 11 additions & 3 deletions cucumber/test_files/template/invalid_template_list_response.js
@@ -1,12 +1,20 @@
'use strict';

const errors = require('../../../lib/util/errors');

module.exports = {
status: 500,
data: {
stubbed: {
error: {
code: 'InternalError',
message: 'Read error'
},
content: undefined
output: undefined
},
result: {
status: 500,
body: {
code: 'InternalError',
message: 'Read error'
}
}
};
Expand Up @@ -3,9 +3,15 @@
const errors = require('../../../lib/util/errors');

module.exports = {
status: 400,
data: {
error: new errors.BadRequestError('Missing template name and/or type'),
content: undefined
stubbed: {
error: new errors.BadRequestError('Invalid template filename: must have the <basename>.<extension> format'),
output: undefined
},
result: {
status: 400,
body: {
code: 'BadRequestError',
message: 'Invalid template filename: must have the <basename>.<extension> format'
}
}
};
11 changes: 8 additions & 3 deletions cucumber/test_files/template/valid_template_creation_response.js
@@ -1,10 +1,15 @@
'use strict';

module.exports = {
status: 200,
data: {
stubbed: {
error: null,
content: {
output: {
output: 'done'
}
},
result: {
status: 200,
body: {
output: 'done'
}
}
Expand Down
16 changes: 12 additions & 4 deletions cucumber/test_files/template/valid_template_details_response.js
@@ -1,11 +1,19 @@
'use strict';

'use strict';

module.exports = {
status: 200,
data: {
stubbed: {
error: null,
content: {
html: '<html><body><h1>Hello, {{USER}}!</h1></body></html>',
output: {
content: '<html><body><h1>Hello, {{USER}}!</h1></body></html>',
placeholders: ['USER']
}
},
result: {
status: 200,
body: {
content: '<html><body><h1>Hello, {{USER}}!</h1></body></html>',
placeholders: ['USER']
}
}
Expand Down

0 comments on commit 94e06a3

Please sign in to comment.