소스 검색

Enable utf-8 encoding for emojis etc, and add corresponding test for posts

sbkwgh 8 년 전
부모
커밋
39b42286df
2개의 변경된 파일28개의 추가작업 그리고 2개의 파일을 삭제
  1. 12 2
      models/index.js
  2. 16 0
      test/thread_post.js

+ 12 - 2
models/index.js

@@ -6,14 +6,24 @@ const config = require('../config/config.json');
 const env = process.env.NODE_ENV || 'development';
 const db = {};
 
+let options = {
+	define: {
+		charset: 'utf8mb4',
+		collate: 'utf8mb4_general_ci'
+	},
+	dialectOptions: {
+		charset: 'utf8mb4'
+	}
+}
 if(env === 'production') {
-	var sequelize = new Sequelize(process.env.DATABASE_URL)
+	var sequelize = new Sequelize(process.env.DATABASE_URL, options)
 } else {
 	var sequelize = new Sequelize(
 		config[env].database, config[env].username, config[env].password, {
 			host: config[env].host,
 			dialect: config[env].dialect,
-			logging: false
+			logging: false,
+			...options
 		}
 	);
 }

+ 16 - 0
test/thread_post.js

@@ -675,6 +675,22 @@ describe('Thread and post', () => {
 		})
 	})
 
+	describe('POST utf8', () => {
+		it('should allow emojis', async () => {
+			let res = await userAgent
+				.post('/api/v1/post')
+				.set('content-type', 'application/json')
+				.send({
+					content: '😂😀',
+					threadId: 1
+				})
+
+			res.should.be.json
+			res.should.have.status(200)
+			res.body.should.have.property('content', '<p>😂😀</p>\n')
+		})
+	})
+
 	describe('DELETE /post/:id', () => {
 		let threadId
 		let postId