Skip to content

Commit

Permalink
fix(store): update node content and excerpt
Browse files Browse the repository at this point in the history
  • Loading branch information
hjvedvik committed Jan 7, 2019
1 parent f78d528 commit 637e0e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 15 additions & 2 deletions gridsome/__tests__/PluginStore.spec.js
Expand Up @@ -74,14 +74,24 @@ test('update node', () => {

const oldNode = contentType.addNode({
id: 'test',
date: '2018-09-04T23:20:33.918Z'
date: '2018-09-04T23:20:33.918Z',
content: 'Lorem ipsum dolor sit amet',
excerpt: 'Lorem ipsum...',
fields: {
foo: 'bar'
}
})

const oldTimestamp = oldNode.internal.timestamp
const uid = oldNode.uid

const node = contentType.updateNode('test', {
title: 'New title'
title: 'New title',
content: 'Praesent commodo cursus magna',
excerpt: 'Praesent commodo...',
fields: {
foo: 'foo'
}
})

const entry = api.store.store.index.findOne({ uid: node.uid })
Expand All @@ -92,6 +102,9 @@ test('update node', () => {
expect(node.slug).toEqual('new-title')
expect(node.path).toEqual('/test/new-title')
expect(node.date).toEqual('2018-09-04T23:20:33.918Z')
expect(node.content).toEqual('Praesent commodo cursus magna')
expect(node.excerpt).toEqual('Praesent commodo...')
expect(node.fields.foo).toEqual('foo')
expect(node.internal.timestamp).not.toEqual(oldTimestamp)
expect(emit).toHaveBeenCalledTimes(2)
expect(entry.id).toEqual('test')
Expand Down
2 changes: 2 additions & 0 deletions gridsome/lib/app/ContentTypeCollection.js
Expand Up @@ -87,6 +87,8 @@ class ContentTypeCollection extends EventEmitter {
node.title = options.title || fields.title || node.title
node.date = options.date || fields.date || node.date
node.slug = options.slug || fields.slug || this.slugify(node.title)
node.content = options.content || fields.content || node.content
node.excerpt = options.excerpt || fields.excerpt || node.excerpt
node.internal = Object.assign({}, node.internal, internal)
node.path = typeof options.path === 'string'
? '/' + options.path.replace(/^\/+/g, '')
Expand Down

0 comments on commit 637e0e4

Please sign in to comment.