Skip to content
This repository was archived by the owner on May 15, 2023. It is now read-only.

Commit 4971554

Browse files
committed
add feature for html produces
1 parent cb48d7a commit 4971554

File tree

18 files changed

+481
-433
lines changed

18 files changed

+481
-433
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ handlebars.registerHelper('requestDataParamFormatter', helpers.requestDataParamF
577577
handlebars.registerHelper('isJsonRepresentation', helpers.isJsonRepresentation);
578578
handlebars.registerHelper('isJsonMediaType', helpers.isJsonMediaType);
579579
handlebars.registerHelper('isXmlMediaType', helpers.isXmlMediaType);
580+
handlebars.registerHelper('isHtmlMediaType', helpers.isHtmlMediaType);
580581
handlebars.registerHelper('isPdfMediaType', helpers.isPdfMediaType);
581582
handlebars.registerHelper('isNecessaryBody', helpers.isNecessaryBody);
582583

lib/helpers.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = {
1919
isJsonMediaType : isJsonMediaType,
2020
isXmlMediaType : isXmlMediaType,
2121
isPdfMediaType : isPdfMediaType,
22+
isHtmlMediaType : isHtmlMediaType,
2223
isNecessaryBody : isNecessaryBody,
2324
mediaTypeContainsJson : mediaTypeContainsJson,
2425
mediaTypeContainsPdf : mediaTypeContainsPdf,
@@ -98,6 +99,14 @@ function isPdfMediaType(type, options) {
9899
return mediaTypeContainsPdf(type) ? options.fn(this) : options.inverse(this);
99100
}
100101

102+
/**
103+
* mustache helper method to determine if a mediaType is PDF
104+
* @param {string} type content type to be evaluated
105+
*/
106+
function isHtmlMediaType(type, options) {
107+
return mediaTypeContainsHtml(type) ? options.fn(this) : options.inverse(this);
108+
}
109+
101110
/**
102111
* mustache helper method to determine if is necessary that function test generated
103112
* have body parameter
@@ -141,6 +150,14 @@ function mediaTypeContainsPdf(type) {
141150
return /\bpdf\b/i.test(type);
142151
}
143152

153+
/**
154+
* determines if the mediatype is pdf
155+
* @param {string} type content type to be evaluated
156+
*/
157+
function mediaTypeContainsHtml(type) {
158+
return /\bhtml\b/i.test(type);
159+
}
160+
144161
/**
145162
* replaces path params with obvious indicator for filling values
146163
* (i.e. if any part of the path is surrounded in curly braces {})

templates/request/delete/delete.handlebars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
{{#is assertion 'assert'}}
9191
assert.isNull(body); // non-json response or no schema
9292
{{/is}}
93-
done();
93+
done();
9494
{{/validateResponse}}
9595
});
9696
});

templates/request/get/get.handlebars

Lines changed: 79 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -28,82 +28,94 @@
2828
function(error, res{{#isNecessaryBody returnType noSchema}}, body{{/isNecessaryBody}}) {
2929
if (error) return done(error);
3030

31-
{{#is assertion 'expect'}}
32-
{{#if default}}
33-
expect(res.statusCode).to.equal('DEFAULT RESPONSE CODE HERE');
34-
{{else}}
35-
expect(res.statusCode).to.equal({{responseCode}});
36-
{{/if}}
37-
{{/is}}
38-
{{#is assertion 'should'}}
39-
{{#if default}}
40-
res.statusCode.should.equal('DEFAULT RESPONSE CODE HERE');
41-
{{else}}
42-
res.statusCode.should.equal({{responseCode}});
43-
{{/if}}
44-
{{/is}}
45-
{{#is assertion 'assert'}}
46-
{{#if default}}
47-
assert.equal(res.statusCode, 'DEFAULT RESPONSE CODE HERE');
48-
{{else}}
49-
assert.equal(res.statusCode, {{responseCode}});
50-
{{/if}}
51-
{{/is}}
31+
{{#is assertion 'expect'}}
32+
{{#if default}}
33+
expect(res.statusCode).to.equal('DEFAULT RESPONSE CODE HERE');
34+
{{else}}
35+
expect(res.statusCode).to.equal({{responseCode}});
36+
{{/if}}
37+
{{/is}}
38+
{{#is assertion 'should'}}
39+
{{#if default}}
40+
res.statusCode.should.equal('DEFAULT RESPONSE CODE HERE');
41+
{{else}}
42+
res.statusCode.should.equal({{responseCode}});
43+
{{/if}}
44+
{{/is}}
45+
{{#is assertion 'assert'}}
46+
{{#if default}}
47+
assert.equal(res.statusCode, 'DEFAULT RESPONSE CODE HERE');
48+
{{else}}
49+
assert.equal(res.statusCode, {{responseCode}});
50+
{{/if}}
51+
{{/is}}
5252

53-
{{#validateResponse returnType noSchema}}
53+
{{#validateResponse returnType noSchema}}
5454
{{#isJsonMediaType returnType}}
55-
{{#is assertion 'expect'}}
56-
expect(validator.validate(body, schema)).to.be.true;
57-
{{/is}}
58-
{{#is assertion 'should'}}
59-
validator.validate(body, schema).should.be.true;
60-
{{/is}}
61-
{{#is assertion 'assert'}}
62-
assert.true(validator.validate(body, schema));
63-
{{/is}}
64-
done();
55+
{{#is assertion 'expect'}}
56+
expect(validator.validate(body, schema)).to.be.true;
57+
{{/is}}
58+
{{#is assertion 'should'}}
59+
validator.validate(body, schema).should.be.true;
60+
{{/is}}
61+
{{#is assertion 'assert'}}
62+
assert.true(validator.validate(body, schema));
63+
{{/is}}
64+
done();
6565
{{/isJsonMediaType}}
6666
{{#isXmlMediaType returnType}}
67-
var xml2jsConfig = {{xml2jsConfig}};
67+
var xml2jsConfig = {{xml2jsConfig}};
6868

69-
parseString(res.text, xml2jsConfig, function(parseErr, result) {
70-
if (parseErr) return done(parseErr);
71-
{{#is assertion 'expect'}}
72-
expect(validator.validate(result, schema)).to.be.true;
73-
{{/is}}
74-
{{#is assertion 'should'}}
75-
validator.validate(result, schema).should.be.true;
76-
{{/is}}
77-
{{#is assertion 'assert'}}
78-
assert.true(validator.validate(result, schema));
79-
{{/is}}
80-
done();
81-
});
69+
parseString(res.text, xml2jsConfig, function(parseErr, result) {
70+
if (parseErr) return done(parseErr);
71+
{{#is assertion 'expect'}}
72+
expect(validator.validate(result, schema)).to.be.true;
73+
{{/is}}
74+
{{#is assertion 'should'}}
75+
validator.validate(result, schema).should.be.true;
76+
{{/is}}
77+
{{#is assertion 'assert'}}
78+
assert.true(validator.validate(result, schema));
79+
{{/is}}
80+
done();
81+
});
8282
{{/isXmlMediaType}}
83-
{{else}}
83+
{{else}}
8484
{{#isPdfMediaType returnType}}
85-
{{#is assertion 'expect'}}
86-
expect(body).to.deep.equal(new Buffer(Number(res.header['content-length'])));
87-
{{/is}}
88-
{{#is assertion 'should'}}
89-
body.should.deep.equal(new Buffer(Number(res.header['content-length'])));
90-
{{/is}}
91-
{{#is assertion 'assert'}}
92-
assert.deepEqual(body, new Buffer(Number(res.header['content-length'])));
93-
{{/is}}
85+
{{#is assertion 'expect'}}
86+
expect(body).to.equal(new Buffer(Number(res.header['content-length'])));
87+
{{/is}}
88+
{{#is assertion 'should'}}
89+
body.should.equal(new Buffer(Number(res.header['content-length'])));
90+
{{/is}}
91+
{{#is assertion 'assert'}}
92+
assert.equal(body, new Buffer(Number(res.header['content-length'])));
93+
{{/is}}
9494
{{else}}
95-
{{#is assertion 'expect'}}
96-
expect(body).to.equal(null); // non-json response or no schema
97-
{{/is}}
98-
{{#is assertion 'should'}}
99-
body.should.equal(null); // non-json response or no schema
100-
{{/is}}
101-
{{#is assertion 'assert'}}
102-
assert.isNull(body); // non-json response or no schema
103-
{{/is}}
95+
{{#isHtmlMediaType returnType}}
96+
{{#is assertion 'expect'}}
97+
expect(res.text).to.include('<!DOCTYPE html>');
98+
{{/is}}
99+
{{#is assertion 'should'}}
100+
res.text.should.include('<!DOCTYPE html>');
101+
{{/is}}
102+
{{#is assertion 'assert'}}
103+
assert.include(res.text, '<!DOCTYPE html>');
104+
{{/is}}
105+
{{else}}
106+
{{#is assertion 'expect'}}
107+
expect(body).to.equal(null); // non-json response or no schema
108+
{{/is}}
109+
{{#is assertion 'should'}}
110+
body.should.equal(null); // non-json response or no schema
111+
{{/is}}
112+
{{#is assertion 'assert'}}
113+
assert.isNull(body); // non-json response or no schema
114+
{{/is}}
115+
{{/isHtmlMediaType}}
104116
{{/isPdfMediaType}}
105-
done();
106-
{{/validateResponse}}
117+
done();
118+
{{/validateResponse}}
107119
});
108120
});
109121
{{#if isLoadTest}}

templates/request/patch/patch.handlebars

Lines changed: 58 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -57,82 +57,72 @@
5757
function(error, res{{#isNecessaryBody returnType noSchema}}, body{{/isNecessaryBody}}) {
5858
if (error) return done(error);
5959

60-
{{#is assertion 'expect'}}
61-
{{#if default}}
62-
expect(res.statusCode).to.equal('DEFAULT RESPONSE CODE HERE');
63-
{{else}}
64-
expect(res.statusCode).to.equal({{responseCode}});
65-
{{/if}}
66-
{{/is}}
67-
{{#is assertion 'should'}}
68-
{{#if default}}
69-
res.statusCode.should.equal('DEFAULT RESPONSE CODE HERE');
70-
{{else}}
71-
res.statusCode.should.equal({{responseCode}});
72-
{{/if}}
73-
{{/is}}
74-
{{#is assertion 'assert'}}
75-
{{#if default}}
76-
assert.equal(res.statusCode, 'DEFAULT RESPONSE CODE HERE');
77-
{{else}}
78-
assert.equal(res.statusCode, {{responseCode}});
79-
{{/if}}
80-
{{/is}}
81-
82-
{{#validateResponse returnType noSchema}}
60+
{{#validateResponse returnType noSchema}}
8361
{{#isJsonMediaType returnType}}
84-
{{#is assertion 'expect'}}
85-
expect(validator.validate(body, schema)).to.be.true;
86-
{{/is}}
87-
{{#is assertion 'should'}}
88-
validator.validate(body, schema).should.be.true;
89-
{{/is}}
90-
{{#is assertion 'assert'}}
91-
assert.true(validator.validate(body, schema));
92-
{{/is}}
93-
done();
62+
{{#is assertion 'expect'}}
63+
expect(validator.validate(body, schema)).to.be.true;
64+
{{/is}}
65+
{{#is assertion 'should'}}
66+
validator.validate(body, schema).should.be.true;
67+
{{/is}}
68+
{{#is assertion 'assert'}}
69+
assert.true(validator.validate(body, schema));
70+
{{/is}}
71+
done();
9472
{{/isJsonMediaType}}
9573
{{#isXmlMediaType returnType}}
96-
var xml2jsConfig = {{xml2jsConfig}};
74+
var xml2jsConfig = {{xml2jsConfig}};
9775

98-
parseString(res.text, xml2jsConfig, function(parseErr, result) {
99-
if (parseErr) return done(parseErr);
100-
{{#is assertion 'expect'}}
101-
expect(validator.validate(body, schema)).to.be.true;
102-
{{/is}}
103-
{{#is assertion 'should'}}
104-
validator.validate(body, schema).should.be.true;
105-
{{/is}}
106-
{{#is assertion 'assert'}}
107-
assert.true(validator.validate(body, schema));
108-
{{/is}}
109-
done();
110-
});
76+
parseString(res.text, xml2jsConfig, function(parseErr, result) {
77+
if (parseErr) return done(parseErr);
78+
{{#is assertion 'expect'}}
79+
expect(validator.validate(result, schema)).to.be.true;
80+
{{/is}}
81+
{{#is assertion 'should'}}
82+
validator.validate(result, schema).should.be.true;
83+
{{/is}}
84+
{{#is assertion 'assert'}}
85+
assert.true(validator.validate(result, schema));
86+
{{/is}}
87+
done();
88+
});
11189
{{/isXmlMediaType}}
112-
{{else}}
90+
{{else}}
11391
{{#isPdfMediaType returnType}}
114-
{{#is assertion 'expect'}}
115-
expect(body).to.deep.equal(new Buffer(Number(res.header['content-length'])));
116-
{{/is}}
117-
{{#is assertion 'should'}}
118-
body.should.deep.equal(new Buffer(Number(res.header['content-length'])));
119-
{{/is}}
120-
{{#is assertion 'assert'}}
121-
assert.deepEqual(body, new Buffer(Number(res.header['content-length'])));
122-
{{/is}}
92+
{{#is assertion 'expect'}}
93+
expect(body).to.equal(new Buffer(Number(res.header['content-length'])));
94+
{{/is}}
95+
{{#is assertion 'should'}}
96+
body.should.equal(new Buffer(Number(res.header['content-length'])));
97+
{{/is}}
98+
{{#is assertion 'assert'}}
99+
assert.equal(body, new Buffer(Number(res.header['content-length'])));
100+
{{/is}}
123101
{{else}}
124-
{{#is assertion 'expect'}}
125-
expect(body).to.equal(null); // non-json response or no schema
126-
{{/is}}
127-
{{#is assertion 'should'}}
128-
body.should.equal(null); // non-json response or no schema
129-
{{/is}}
130-
{{#is assertion 'assert'}}
131-
assert.isNull(body); // non-json response or no schema
132-
{{/is}}
102+
{{#isHtmlMediaType returnType}}
103+
{{#is assertion 'expect'}}
104+
expect(res.text).to.include('<!DOCTYPE html>');
105+
{{/is}}
106+
{{#is assertion 'should'}}
107+
res.text.should.include('<!DOCTYPE html>');
108+
{{/is}}
109+
{{#is assertion 'assert'}}
110+
assert.include(res.text, '<!DOCTYPE html>');
111+
{{/is}}
112+
{{else}}
113+
{{#is assertion 'expect'}}
114+
expect(body).to.equal(null); // non-json response or no schema
115+
{{/is}}
116+
{{#is assertion 'should'}}
117+
body.should.equal(null); // non-json response or no schema
118+
{{/is}}
119+
{{#is assertion 'assert'}}
120+
assert.isNull(body); // non-json response or no schema
121+
{{/is}}
122+
{{/isHtmlMediaType}}
133123
{{/isPdfMediaType}}
134-
done();
135-
{{/validateResponse}}
124+
done();
125+
{{/validateResponse}}
136126
});
137127
});
138128
{{#if isLoadTest}}

0 commit comments

Comments
 (0)