getUrl -> url consistency

test improvements
This commit is contained in:
Tom Moor
2018-11-04 00:59:52 -07:00
parent 8de074b275
commit 6391474d14
16 changed files with 49 additions and 21 deletions

View File

@@ -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,

View File

@@ -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');
});
});

View File

@@ -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: [],
};
};