1
1
import { useTestDatabase } from '../config/index' ;
2
+ import blog from '../config/blog' ;
2
3
3
4
const {
4
5
listArticles,
@@ -31,13 +32,13 @@ const newArticle = {
31
32
describe ( 'Articles Controller' , ( ) => {
32
33
test ( 'listArticles should return articles array' , async ( ) => {
33
34
expect . assertions ( 1 ) ;
34
- const articles = await listArticles ( ) ;
35
+ const articles = await listArticles ( blog ) ;
35
36
expect ( articles . length ) . toBeGreaterThan ( 0 ) ;
36
37
} ) ;
37
38
38
39
test ( 'listArticles articles should include reading time' , async ( ) => {
39
40
expect . assertions ( 1 ) ;
40
- const articles = await listArticles ( ) ;
41
+ const articles = await listArticles ( blog ) ;
41
42
expect ( typeof articles [ 0 ] . reading_time ) . toBe ( 'number' ) ;
42
43
} ) ;
43
44
@@ -57,12 +58,12 @@ describe('Articles Controller', () => {
57
58
expect . assertions ( 2 ) ;
58
59
const hidden = { hidden : true } ;
59
60
const newHiddenArticle = { ...newArticle , ...hidden } ;
60
- const createdArticle = await addArticle ( newHiddenArticle ) ;
61
- const articles = await listArticles ( ) ;
61
+ const createdArticle = await addArticle ( blog , newHiddenArticle ) ;
62
+ const articles = await listArticles ( blog ) ;
62
63
const articlesWithNewArticleId = await articles . filter ( article => {
63
64
return article . id === createdArticle . id ;
64
65
} ) ;
65
- expect ( await getArticle ( createdArticle . id ) ) . toBeDefined ( ) ;
66
+ expect ( await getArticle ( blog , createdArticle . id ) ) . toBeDefined ( ) ;
66
67
expect ( articlesWithNewArticleId . length ) . toBe ( 0 ) ;
67
68
} ) ;
68
69
@@ -72,18 +73,18 @@ describe('Articles Controller', () => {
72
73
const futureDays = date . setDate ( date . getDate ( ) + 100 ) ;
73
74
const future = { posted_on : new Date ( futureDays ) } ;
74
75
const futureArticle = { ...newArticle , ...future } ;
75
- const createdArticle = await addArticle ( futureArticle ) ;
76
- const articles = await listArticles ( ) ;
76
+ const createdArticle = await addArticle ( blog , futureArticle ) ;
77
+ const articles = await listArticles ( blog ) ;
77
78
const articlesWithNewArticleId = await articles . filter ( article => {
78
79
return article . id === createdArticle . id ;
79
80
} ) ;
80
- expect ( await getArticle ( createdArticle . id ) ) . toBeDefined ( ) ;
81
+ expect ( await getArticle ( blog , createdArticle . id ) ) . toBeDefined ( ) ;
81
82
expect ( articlesWithNewArticleId . length ) . toBe ( 0 ) ;
82
83
} ) ;
83
84
84
85
test ( 'getArticle should return an article with content' , async ( ) => {
85
86
expect . assertions ( 14 ) ;
86
- const article = await getArticle ( 1 ) ;
87
+ const article = await getArticle ( blog , 1 ) ;
87
88
expect ( typeof article . id ) . toBe ( 'number' ) ;
88
89
expect ( typeof article . title ) . toBe ( 'string' ) ;
89
90
expect ( typeof article . subtitle ) . toBe ( 'string' ) ;
@@ -132,7 +133,7 @@ describe('Articles Controller', () => {
132
133
133
134
test ( 'getRelatedArticles should return an article array' , async ( ) => {
134
135
expect . assertions ( 14 ) ;
135
- const relatedArticles = await getRelatedArticles ( 1 ) ;
136
+ const relatedArticles = await getRelatedArticles ( blog , 1 ) ;
136
137
const article = relatedArticles [ 0 ] ;
137
138
expect ( typeof article . id ) . toBe ( 'number' ) ;
138
139
expect ( typeof article . title ) . toBe ( 'string' ) ;
@@ -165,20 +166,20 @@ describe('Articles Controller', () => {
165
166
test ( 'addToRelatedArticlesTable cant add empty array' , async ( ) => {
166
167
expect . assertions ( 1 ) ;
167
168
const emptyArray = [ ] ;
168
- const response = await addToRelatedArticlesTable ( 1 , emptyArray ) ;
169
+ const response = await addToRelatedArticlesTable ( blog , 1 , emptyArray ) ;
169
170
expect ( response ) . toEqual ( emptyArray ) ;
170
171
} ) ;
171
172
172
173
test ( 'addToRelatedArticlesTable works with undefined' , async ( ) => {
173
174
expect . assertions ( 1 ) ;
174
175
const emptyArray = [ ] ;
175
- const response = await addToRelatedArticlesTable ( 1 ) ;
176
+ const response = await addToRelatedArticlesTable ( blog , 1 ) ;
176
177
expect ( response ) . toEqual ( emptyArray ) ;
177
178
} ) ;
178
179
179
180
test ( 'addArticle should add an article correctly' , async ( ) => {
180
181
expect . assertions ( 15 ) ;
181
- const addedArticle = await addArticle ( newArticle ) ;
182
+ const addedArticle = await addArticle ( blog , newArticle ) ;
182
183
expect ( typeof addedArticle ) . toBe ( 'object' ) ;
183
184
expect ( typeof addedArticle . id ) . toBe ( 'number' ) ;
184
185
expect ( typeof addedArticle . title ) . toBe ( 'string' ) ;
@@ -202,7 +203,7 @@ describe('Articles Controller', () => {
202
203
// TODO: Fix
203
204
xtest ( 'modifyArticle should modify an article correctly' , async ( ) => {
204
205
expect . assertions ( 9 ) ;
205
- await modifyArticle ( 1 , newArticle ) ;
206
+ await modifyArticle ( blog , 1 , newArticle ) ;
206
207
const modifiedArticle = await getArticle ( 1 ) ;
207
208
expect ( modifiedArticle . title ) . toBe ( newArticle . title ) ;
208
209
expect ( modifiedArticle . subtitle ) . toBe ( newArticle . subtitle ) ;
@@ -219,11 +220,11 @@ describe('Articles Controller', () => {
219
220
// TODO: Fix
220
221
xtest ( 'modifyArticle should work with when partly updating' , async ( ) => {
221
222
expect . assertions ( 9 ) ;
222
- const originalArticle = await getArticle ( 1 ) ;
223
+ const originalArticle = await getArticle ( blog , 1 ) ;
223
224
const newArticlePart = {
224
225
title : 'updated title' ,
225
226
} ;
226
- await modifyArticle ( 1 , newArticlePart ) ;
227
+ await modifyArticle ( blog , 1 , newArticlePart ) ;
227
228
const modifiedArticle = await getArticle ( newArticlePart ) ;
228
229
expect ( modifiedArticle . title ) . toBe ( newArticlePart . title ) ;
229
230
expect ( modifiedArticle . subtitle ) . toBe ( originalArticle . subtitle ) ;
@@ -239,8 +240,9 @@ describe('Articles Controller', () => {
239
240
240
241
test ( 'deleteArticle should delete an article' , async ( ) => {
241
242
expect . assertions ( 2 ) ;
242
- return deleteArticle ( 1 )
243
+ return deleteArticle ( blog , 1 )
243
244
. then ( data => expect ( data . id ) . toBe ( 1 ) )
244
- . then ( async ( ) => expect ( await getArticle ( 1 ) ) . toBeUndefined ( ) ) ;
245
+ . then ( async ( ) =>
246
+ expect ( await getArticle ( blog , 1 ) ) . toBeUndefined ( ) ) ;
245
247
} ) ;
246
248
} ) ;
0 commit comments