Skip to content
This repository has been archived by the owner on Jan 20, 2020. It is now read-only.

Commit

Permalink
Added SEO tags to article table
Browse files Browse the repository at this point in the history
Release V1.0.0-alpha.3
  • Loading branch information
Luciano Nooijen committed Feb 26, 2019
1 parent 81c3e92 commit 434a165
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
6 changes: 6 additions & 0 deletions controllers/articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const fieldsBase = [
'articles.subtitle',
'articles.slug',
'articles.posted_on',
'articles.seo_title',
'articles.seo_description',
'articles.seo_tags',
'article_content.image_url AS article_image_url',
'article_content.summary',
'authors.name AS author_name',
Expand Down Expand Up @@ -154,6 +157,9 @@ const addArticle = async (knex, article) => {
slug: article.slug,
author: article.author,
category: article.author,
seo_title: article.seo_title,
seo_description: article.seo_description,
seo_tags: article.seo_tags,
};
const addedArticleData = await addToArticlesTable(knex, articleData);
const addedArticleId = addedArticleData.id;
Expand Down
26 changes: 26 additions & 0 deletions database/migrations/20190226092504_seo_tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint newline-per-chained-call: ["error", { "ignoreChainWithDepth": 10 }] */
/* eslint-disable prettier/prettier, max-len, arrow-body-style */

const addSeoTags = table => {
table.string('seo_title').notNullable();
table.string('seo_description').notNullable();
table.string('seo_tags').notNullable();
};

const removeSeoTags = table => {
table.dropColumn('seo_title');
table.dropColumn('seo_description');
table.dropColumn('seo_tags');
};

module.exports.up = (knex, Promise) => {
return Promise.all([
knex.schema.table('articles', table => addSeoTags(table)),
]);
};

module.exports.down = (knex, Promise) => {
return Promise.all([
knex.schema.table('articles', table => removeSeoTags(table)),
]);
};
6 changes: 6 additions & 0 deletions database/seeds/test-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,19 @@ const insertArticles = knex =>
subtitle: 'Subtitle Article 1',
slug: 'article_one',
category: 1,
seo_title: 'Title1',
seo_description: 'Description1',
seo_tags: 'Tags1',
},
{
author: 1,
title: 'Article 2',
subtitle: 'Subtitle Article 2',
slug: 'article_two',
category: 1,
seo_title: 'Title2',
seo_description: 'Description2',
seo_tags: 'Tags2',
},
]),
); // eslint-disable-line
Expand Down
8 changes: 7 additions & 1 deletion tests/controllers/articles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const newArticle = {
html_content: 'the content',
author: 2,
category: 1,
seo_title: 'Titletest',
seo_description: 'Descriptiontest',
seo_tags: 'Tagstest',
related_articles: [1, 2],
};

Expand Down Expand Up @@ -83,7 +86,7 @@ describe('Articles Controller', () => {
});

test('getArticle should return an article with content', async () => {
expect.assertions(14);
expect.assertions(17);
const article = await getArticle(blog, 1);
expect(typeof article.id).toBe('number');
expect(typeof article.title).toBe('string');
Expand All @@ -99,6 +102,9 @@ describe('Articles Controller', () => {
expect(typeof article.category_name).toBe('string');
expect(typeof article.category_slug).toBe('string');
expect(typeof article.reading_time).toBe('number');
expect(typeof article.seo_title).toBe('string');
expect(typeof article.seo_description).toBe('string');
expect(typeof article.seo_tags).toBe('string');
});

test('calculateReadingTime should calculate reading time', async () => {
Expand Down

0 comments on commit 434a165

Please sign in to comment.