Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/routes/CreatePostRoute.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable prettier/prettier */
import { TEST_AUTH_COOKIE, TEST_USER } from '../../jest.setup';
import Post, { PostDocument, PostType } from '../models/Post';
import TestUtils from '../utils/TestUtils';
Expand All @@ -11,7 +12,7 @@ const TEST_POST_CONTENT = 'I have an update for you all!';
* npm run test CreatePost
* - Delete this comment.
*/
describe.skip('POST /posts', () => {
describe('POST /posts', () => {
test('If the user is not authenticated, should return a 401.', async () => {
await TestUtils.agent
.post('/posts')
Expand Down
22 changes: 17 additions & 5 deletions src/routes/CreatePostRoute.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable prettier/prettier */
import { body } from 'express-validator';
import { min } from 'mathjs';

import Post, { PostDocument, PostType } from '../models/Post';
import { ApplicationRequest } from '../utils/ApplicationRequest';
Expand All @@ -20,9 +22,9 @@ export default class CreatePostRoute extends BaseRoute<PostDocument> {
* - Fill in the path string with the appropriate path to this endpoint.
* - Delete this comment.
*/
authenticated: false,
method: null,
path: '/'
authenticated: true,
method: RouteMethod.POST,
path: '/posts'
});
}

Expand All @@ -38,7 +40,9 @@ export default class CreatePostRoute extends BaseRoute<PostDocument> {
body('type')
.if((value: PostType) => !!value)
.isIn(Object.values(PostType))
.withMessage('You must choose a valid PostType.')
.withMessage('You must choose a valid PostType.'),

body('content').isLength({ min: 1 }).withMessage('Not a valid message')
];
}

Expand All @@ -54,6 +58,14 @@ export default class CreatePostRoute extends BaseRoute<PostDocument> {
// content, and post type. Then return the post!

// TODO: (13.04) Return the post!
return null;
const { content, type } = req.params;

const post: PostDocument = await Post.create({
author: req.user?._id,
content: 'I have an update for you all!',
type: 'WIN'
});

return post;
}
}