Skip to content

Commit

Permalink
Feat: 게시글 생성 테스트 코드
Browse files Browse the repository at this point in the history
  • Loading branch information
SoN-B committed Jun 21, 2023
1 parent 8ced1d3 commit 098e707
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions BackEnd/src/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = class Post extends Sequelize.Model {
view: {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0,
},
recommand: {
type: Sequelize.INTEGER,
Expand Down
1 change: 0 additions & 1 deletion BackEnd/src/services/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const postBoard = async (title, content, user_id) => {
return await Post.create({
title: title,
content: content,
view: 0,
user_id: user_id,
});
};
Expand Down
41 changes: 40 additions & 1 deletion BackEnd/src/test/board.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const request = require('supertest');
const { app } = require('../../server');

const { Post } = require('../utils/connect');
const board = require('../controllers/board');

const { config, chalk } = require('../../loaders/module');
Expand Down Expand Up @@ -81,9 +82,47 @@ describe('getBoardByPostId', () => {

test(`should return ${chalk.yellow(404)} if ${chalk.blue('post is not exists')}`, async () => {
const res = await request(app)
.get(`/board/${2}`)
.get(`/board/${100}`)

expect(res.statusCode).toEqual(404);
expect(res.body.message).toEqual('No data.');
});
});

/**
* * 게시글 작성 테스트
* 1. 게시글 작성 성공
*/
describe('postBoard', () => {
let server, token;

beforeAll(async () => {
server = app.listen(config.get('server.port'));

const res = await request(app)
.post('/user/login')
.send({ email: 'test_profile@example.com', password: 'password' });
token = res.body.data.access_token;
});

afterEach(async () => {
await Post.destroy({ where: { title: 'post_test' } });
});

afterAll((done) => {
server.close(done);
});

test(`should return ${chalk.green(200)} if ${chalk.blue('create a new post successful')}`, async () => {
const title = 'post_test';
const content = 'test_content';

const res = await request(app)
.post('/board')
.set('authorization', token)
.send({ title: title, content: content });

expect(res.statusCode).toBe(200);
expect(res.body.message).toBe('Post created success.');
});
});

0 comments on commit 098e707

Please sign in to comment.