@@ -53,17 +53,33 @@ describe('Articles Controller', () => {
53
53
expect ( receivedArticles ) . toEqual ( expectedOutput ) ;
54
54
} ) ;
55
55
56
- // test.only('listArticles should not list hidden articles', async () => {
57
- // expect.assertions(1);
58
- // const articles = await listArticles;
59
- // expect(articles.length).toBeGreaterThan(0);
60
- // });
56
+ test ( 'listArticles should not list hidden articles' , async ( ) => {
57
+ expect . assertions ( 2 ) ;
58
+ const hidden = { hidden : true } ;
59
+ const newHiddenArticle = { ...newArticle , ...hidden } ;
60
+ const createdArticle = await addArticle ( newHiddenArticle ) ;
61
+ const articles = await listArticles ( ) ;
62
+ const articlesWithNewArticleId = await articles . filter ( article => {
63
+ return article . id === createdArticle . id ;
64
+ } ) ;
65
+ expect ( await getArticle ( createdArticle . id ) ) . toBeDefined ( ) ;
66
+ expect ( articlesWithNewArticleId . length ) . toBe ( 0 ) ;
67
+ } ) ;
61
68
62
- // test('listArticles should not list articles from the future', async () => {
63
- // expect.assertions(1);
64
- // const articles = await listArticles;
65
- // expect(articles.length).toBeGreaterThan(0);
66
- // });
69
+ test ( 'listArticles should not list articles from the future' , async ( ) => {
70
+ expect . assertions ( 2 ) ;
71
+ const date = new Date ( ) ;
72
+ const futureDays = date . setDate ( date . getDate ( ) + 100 ) ;
73
+ const future = { posted_on : new Date ( futureDays ) } ;
74
+ const futureArticle = { ...newArticle , ...future } ;
75
+ const createdArticle = await addArticle ( futureArticle ) ;
76
+ const articles = await listArticles ( ) ;
77
+ const articlesWithNewArticleId = await articles . filter ( article => {
78
+ return article . id === createdArticle . id ;
79
+ } ) ;
80
+ expect ( await getArticle ( createdArticle . id ) ) . toBeDefined ( ) ;
81
+ expect ( articlesWithNewArticleId . length ) . toBe ( 0 ) ;
82
+ } ) ;
67
83
68
84
test ( 'getArticle should return an article with content' , async ( ) => {
69
85
expect . assertions ( 14 ) ;
@@ -160,7 +176,7 @@ describe('Articles Controller', () => {
160
176
expect ( response ) . toEqual ( emptyArray ) ;
161
177
} ) ;
162
178
163
- test . only ( 'addArticle should add an article correctly' , async ( ) => {
179
+ test ( 'addArticle should add an article correctly' , async ( ) => {
164
180
expect . assertions ( 15 ) ;
165
181
const addedArticle = await addArticle ( newArticle ) ;
166
182
expect ( typeof addedArticle ) . toBe ( 'object' ) ;
0 commit comments