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

Commit b108707

Browse files
author
Luciano Nooijen
committed
Improved Article creation
1 parent 58d055f commit b108707

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

controllers/articles.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ const addArticle = async article => {
147147
title: article.title,
148148
subtitle: article.subtitle,
149149
posted_on: article.posted_on,
150+
hidden: article.hidden,
150151
slug: article.slug,
151152
author: article.author,
152153
category: article.author,

tests/controllers/articles.test.ts

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,33 @@ describe('Articles Controller', () => {
5353
expect(receivedArticles).toEqual(expectedOutput);
5454
});
5555

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+
});
6168

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+
});
6783

6884
test('getArticle should return an article with content', async () => {
6985
expect.assertions(14);
@@ -160,7 +176,7 @@ describe('Articles Controller', () => {
160176
expect(response).toEqual(emptyArray);
161177
});
162178

163-
test.only('addArticle should add an article correctly', async () => {
179+
test('addArticle should add an article correctly', async () => {
164180
expect.assertions(15);
165181
const addedArticle = await addArticle(newArticle);
166182
expect(typeof addedArticle).toBe('object');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy