Skip to content

Commit b9320a2

Browse files
authored
fix(cicero-core): setReadme() now preserves logo in Metadata (#874)
1 parent e69ff85 commit b9320a2

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

packages/cicero-core/src/template.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Template {
7878
if (options.verifySignature) {
7979
this.verifyTemplateSignature();
8080
}
81-
if(options && options.offline) {
81+
if (options && options.offline) {
8282
this.getModelManager().validateModelFiles();
8383
}
8484
else {
@@ -153,7 +153,7 @@ class Template {
153153
* @private
154154
*/
155155
_normalize(str) {
156-
if(str && typeof str === 'string') {
156+
if (str && typeof str === 'string') {
157157
return str.replace(/\r/g, '');
158158
}
159159
return str;
@@ -183,7 +183,7 @@ class Template {
183183
});
184184
}
185185

186-
if(this.getTemplate()) {
186+
if (this.getTemplate()) {
187187
content.grammar = this._normalize(this.getTemplate());
188188
}
189189
content.models = {};
@@ -300,7 +300,7 @@ class Template {
300300
* @param {Object} [options] - an optional set of options to configure the instance.
301301
* @return {Promise<Template>} a Promise to the instantiated template
302302
*/
303-
static async fromDirectory(path, options=null) {
303+
static async fromDirectory(path, options = null) {
304304
return TemplateLoader.fromDirectory(Template, path, options);
305305
}
306306

@@ -310,7 +310,7 @@ class Template {
310310
* @param {Object} [options] - an optional set of options to configure the instance.
311311
* @return {Promise<Template>} a Promise to the template
312312
*/
313-
static async fromArchive(buffer, options=null) {
313+
static async fromArchive(buffer, options = null) {
314314
return TemplateLoader.fromArchive(Template, buffer, options);
315315
}
316316

@@ -320,7 +320,7 @@ class Template {
320320
* @param {Object} [options] - an optional set of options to configure the instance.
321321
* @return {Promise} a Promise to the template
322322
*/
323-
static async fromUrl(url, options=null) {
323+
static async fromUrl(url, options = null) {
324324
return TemplateLoader.fromUrl(Template, url, options);
325325
}
326326

@@ -426,7 +426,7 @@ class Template {
426426
* @private
427427
*/
428428
setReadme(readme) {
429-
this.metadata = new Metadata(this.metadata.getPackageJson(), readme, this.metadata.getSamples(), this.metadata.getRequest());
429+
this.metadata = new Metadata(this.metadata.getPackageJson(), readme, this.metadata.getSamples(), this.metadata.getRequest(), this.metadata.getLogo());
430430
}
431431

432432
/**

packages/cicero-core/test/template.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,43 @@ describe('Template', () => {
444444
});
445445

446446
describe('#setReadme', () => {
447+
it('should preserve the logo after calling setReadme', async () => {
448+
const template = await Template.fromDirectory('./test/data/template-logo', options);
449+
template.getMetadata().getLogo().should.be.an.instanceof(Buffer);
450+
template.setReadme('new readme text');
451+
template.getMetadata().getLogo().should.be.an.instanceof(Buffer);
452+
});
447453

448454
it('should not throw for valid readme text', async () => {
449455
const template = await Template.fromDirectory('./test/data/latedeliveryandpenalty', options);
450456
return (() => template.setReadme('readme text')).should.not.throw();
451457
});
452458
});
453459

460+
describe('Metadata regression tests', () => {
461+
it('should preserve the logo after calling setSamples', async () => {
462+
const template = await Template.fromDirectory('./test/data/template-logo', options);
463+
template.getMetadata().getLogo().should.be.an.instanceof(Buffer);
464+
template.setSamples({ default: 'new sample' });
465+
template.getMetadata().getLogo().should.be.an.instanceof(Buffer);
466+
});
467+
468+
it('should preserve the logo after calling setRequest', async () => {
469+
const template = await Template.fromDirectory('./test/data/template-logo', options);
470+
const newRequest = { $class: 'logo@0.0.1.Request' };
471+
template.setRequest(newRequest);
472+
template.getMetadata().getLogo().should.be.an.instanceof(Buffer);
473+
});
474+
475+
it('should preserve the logo after calling setPackageJson', async () => {
476+
const template = await Template.fromDirectory('./test/data/template-logo', options);
477+
const pkg = template.getMetadata().getPackageJson();
478+
pkg.name = 'new_name';
479+
template.setPackageJson(pkg);
480+
template.getMetadata().getLogo().should.be.an.instanceof(Buffer);
481+
});
482+
});
483+
454484
describe('#getRequestTypes', () => {
455485

456486
it('should return request types for single accordclauselogic function', async () => {

0 commit comments

Comments
 (0)