test('dynamic route with non-optional repeated segments', async () => { const api = await createPlugin() const collection = api.store.addCollection({ typeName: 'TestPost', route: '/path/:segments+' }) expect(() => collection.addNode({ segments: [] })).toThrow(TypeError, 'Expected "segments" to not be empty') })
// // deprecated // addContentType(options) { deprecate('The store.addContentType() method has been renamed to store.addCollection().') return this.addCollection(options) }
// TODO: remove this before 1.0 test('add deprecated collection field', async () => { const app = await createApp(api => { api.loadSource(store => store.addCollection('test_post')) }) const queryType = app.schema.getSchema().getQueryType() const queryFields = queryType.getFields() expect(queryFields).toHaveProperty('testPost') expect(queryFields).toHaveProperty('allTestPost') expect(queryFields).toHaveProperty('alltest_post') expect(queryFields.alltest_post.isDeprecated).toEqual(true) })
async getPostTypes (actions) { const { data } = await this.fetch('wp/v2/types', {}, {}) const addCollection = actions.addCollection || actions.addContentType for (const type in data) { const options = data[type] this.restBases.posts[type] = trimStart(options.rest_base, '/') addCollection({ typeName: this.createTypeName(type), route: this.routes[type] }) } }
createApp(function (api) { api.loadSource(actions => { actions.addCollection('Post') actions.addCollection('Post1') actions.addCollection('Post2') actions.addCollection('Post3') }) })
async loadTags ({ addCollection }) { console.log(`Loading ${TYPE_TAG}`) const tags = addCollection({ typeName: this.typeNames.tag }) await this.loadBasicEntity(tags, this.contentAPI.tags) }
test('cache parsed components', async () => { const { pages } = await createApp(api => { api.loadSource(store => { store.addCollection('Post') }) }) const parseComponent = jest.spyOn(pages.hooks.parseComponent.for('vue'), 'call') pages.createPage({ path: '/page/1', component: './__fixtures__/PagedPage.vue' }) pages.createPage({ path: '/page/2', component: './__fixtures__/PagedPage.vue' }) pages.createPage({ path: '/page/3', component: './__fixtures__/PagedPage.vue' }) expect(parseComponent).toHaveBeenCalledTimes(1) })
api._app.store.hooks.addCollection.tap({ name: 'VueRemark', before: 'TemplatesPlugin' }, options => { if (options.typeName === this.options.typeName) { options.component = false } })
test('remove node', async () => { const api = await createPlugin() const collection = api.store.addCollection('TestPost') const emit = jest.spyOn(collection._events, 'emit') const node = collection.addNode({ id: 'test' }) collection.removeNode('test') const entry = api.store.store.nodeIndex.getEntry(node.$uid) expect(collection.getNode('test')).toBeNull() expect(emit).toHaveBeenCalledTimes(2) expect(entry).toBeNull() emit.mockRestore() })
api.loadSource(({ addCollection }) => { const posts = addCollection('Post') for (let i = 1; i <= 10; i++) { posts.addNode({ id: i, title: `Post #${i}`, slug: `post-${i}` }) } })
test('transform node', async () => { const api = await createPlugin() const collection = api.store.addCollection('TestPost') const node = collection.addNode({ id: '1', internal: { mimeType: 'application/json', content: JSON.stringify({ id: '2', foo: 'bar' }) } }) expect(node).toMatchObject({ id: '2', foo: 'bar' }) })
test('fail if transformer is not installed', async () => { const api = await createPlugin() const collection = api.store.addCollection('TestPost') expect(() => { collection.addNode({ internal: { mimeType: 'text/markdown', content: '# Test' } }) }).toThrow('text/markdown') })
test('fail if transformer is not installed', async () => { const api = await createPlugin() const collection = api.store.addCollection('TestPost') expect(() => { collection.addNode({ internal: { mimeType: 'text/markdown', content: '# Test' } }) }).toThrow('text/markdown') })
// // deprecated // addContentType(options) { deprecate('The store.addContentType() method has been renamed to store.addCollection().') return this.addCollection(options) }
api.loadSource(({ addCollection }) => { const posts = addCollection('Post') for (let i = 1; i <= 10; i++) { posts.addNode({ id: i, title: `Post #${i}`, slug: `post-${i}` }) } })