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

Commit 434a165

Browse files
author
Luciano Nooijen
committed
Added SEO tags to article table
Release V1.0.0-alpha.3
1 parent 81c3e92 commit 434a165

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

controllers/articles.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const fieldsBase = [
99
'articles.subtitle',
1010
'articles.slug',
1111
'articles.posted_on',
12+
'articles.seo_title',
13+
'articles.seo_description',
14+
'articles.seo_tags',
1215
'article_content.image_url AS article_image_url',
1316
'article_content.summary',
1417
'authors.name AS author_name',
@@ -154,6 +157,9 @@ const addArticle = async (knex, article) => {
154157
slug: article.slug,
155158
author: article.author,
156159
category: article.author,
160+
seo_title: article.seo_title,
161+
seo_description: article.seo_description,
162+
seo_tags: article.seo_tags,
157163
};
158164
const addedArticleData = await addToArticlesTable(knex, articleData);
159165
const addedArticleId = addedArticleData.id;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* eslint newline-per-chained-call: ["error", { "ignoreChainWithDepth": 10 }] */
2+
/* eslint-disable prettier/prettier, max-len, arrow-body-style */
3+
4+
const addSeoTags = table => {
5+
table.string('seo_title').notNullable();
6+
table.string('seo_description').notNullable();
7+
table.string('seo_tags').notNullable();
8+
};
9+
10+
const removeSeoTags = table => {
11+
table.dropColumn('seo_title');
12+
table.dropColumn('seo_description');
13+
table.dropColumn('seo_tags');
14+
};
15+
16+
module.exports.up = (knex, Promise) => {
17+
return Promise.all([
18+
knex.schema.table('articles', table => addSeoTags(table)),
19+
]);
20+
};
21+
22+
module.exports.down = (knex, Promise) => {
23+
return Promise.all([
24+
knex.schema.table('articles', table => removeSeoTags(table)),
25+
]);
26+
};

database/seeds/test-data.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,19 @@ const insertArticles = knex =>
9696
subtitle: 'Subtitle Article 1',
9797
slug: 'article_one',
9898
category: 1,
99+
seo_title: 'Title1',
100+
seo_description: 'Description1',
101+
seo_tags: 'Tags1',
99102
},
100103
{
101104
author: 1,
102105
title: 'Article 2',
103106
subtitle: 'Subtitle Article 2',
104107
slug: 'article_two',
105108
category: 1,
109+
seo_title: 'Title2',
110+
seo_description: 'Description2',
111+
seo_tags: 'Tags2',
106112
},
107113
]),
108114
); // eslint-disable-line

tests/controllers/articles.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ const newArticle = {
2626
html_content: 'the content',
2727
author: 2,
2828
category: 1,
29+
seo_title: 'Titletest',
30+
seo_description: 'Descriptiontest',
31+
seo_tags: 'Tagstest',
2932
related_articles: [1, 2],
3033
};
3134

@@ -83,7 +86,7 @@ describe('Articles Controller', () => {
8386
});
8487

8588
test('getArticle should return an article with content', async () => {
86-
expect.assertions(14);
89+
expect.assertions(17);
8790
const article = await getArticle(blog, 1);
8891
expect(typeof article.id).toBe('number');
8992
expect(typeof article.title).toBe('string');
@@ -99,6 +102,9 @@ describe('Articles Controller', () => {
99102
expect(typeof article.category_name).toBe('string');
100103
expect(typeof article.category_slug).toBe('string');
101104
expect(typeof article.reading_time).toBe('number');
105+
expect(typeof article.seo_title).toBe('string');
106+
expect(typeof article.seo_description).toBe('string');
107+
expect(typeof article.seo_tags).toBe('string');
102108
});
103109

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

0 commit comments

Comments
 (0)