getUrl -> url consistency
test improvements
This commit is contained in:
@@ -70,6 +70,11 @@ const Collection = sequelize.define(
|
||||
await collection.save();
|
||||
},
|
||||
},
|
||||
getterMethods: {
|
||||
url() {
|
||||
return `/collections/${this.id}`;
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -120,10 +125,6 @@ Collection.addHook('afterUpdate', model =>
|
||||
|
||||
// Instance methods
|
||||
|
||||
Collection.prototype.getUrl = function() {
|
||||
return `/collections/${this.id}`;
|
||||
};
|
||||
|
||||
Collection.prototype.addDocumentToStructure = async function(
|
||||
document,
|
||||
index,
|
||||
|
||||
@@ -6,10 +6,10 @@ import uuid from 'uuid';
|
||||
beforeEach(flushdb);
|
||||
beforeEach(jest.resetAllMocks);
|
||||
|
||||
describe('#getUrl', () => {
|
||||
describe('#url', () => {
|
||||
test('should return correct url for the collection', () => {
|
||||
const collection = new Collection({ id: '1234' });
|
||||
expect(collection.getUrl()).toBe('/collections/1234');
|
||||
expect(collection.url).toBe('/collections/1234');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -104,6 +104,12 @@ const Document = sequelize.define(
|
||||
afterCreate: createRevision,
|
||||
afterUpdate: createRevision,
|
||||
},
|
||||
getterMethods: {
|
||||
url: function() {
|
||||
const slugifiedTitle = slugify(this.title);
|
||||
return `/doc/${slugifiedTitle}-${this.urlId}`;
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -312,18 +318,13 @@ Document.prototype.getSummary = function() {
|
||||
return lines.length >= 1 ? lines[1] : '';
|
||||
};
|
||||
|
||||
Document.prototype.getUrl = function() {
|
||||
const slugifiedTitle = slugify(this.title);
|
||||
return `/doc/${slugifiedTitle}-${this.urlId}`;
|
||||
};
|
||||
|
||||
Document.prototype.toJSON = function() {
|
||||
// Warning: only use for new documents as order of children is
|
||||
// handled in the collection's documentStructure
|
||||
return {
|
||||
id: this.id,
|
||||
title: this.title,
|
||||
url: this.getUrl(),
|
||||
url: this.url,
|
||||
children: [],
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user