diff --git a/get-s3.js b/get-s3.js new file mode 100644 index 0000000..b3b809c --- /dev/null +++ b/get-s3.js @@ -0,0 +1 @@ +const AWS = require('aws-sdk') \ No newline at end of file diff --git a/test/meme/delete-meme.test.ts b/test/meme/delete-meme.test.ts index 7644d36..dbf29f1 100644 --- a/test/meme/delete-meme.test.ts +++ b/test/meme/delete-meme.test.ts @@ -3,8 +3,10 @@ import request from 'supertest'; import app from '../../src/app'; import { KeywordModel } from '../../src/model/keyword'; import { MemeModel } from '../../src/model/meme'; +import { UserModel } from '../../src/model/user'; import { createMockData as createKeywordMockData } from '../util/keyword.mock'; import { createMockData } from '../util/meme.mock'; +import { mockUser } from '../util/user.mock'; let testMemeId = ''; let keywordIds = []; @@ -20,10 +22,13 @@ describe("[DELETE] '/api/meme/:memeId' ", () => { await MemeModel.insertMany(mockDatas); memeList = await MemeModel.find({}); testMemeId = memeList[0]._id.toString(); + + await UserModel.insertMany(mockUser); }); afterAll(async () => { await MemeModel.deleteMany({}); + await UserModel.deleteMany({}); }); it('should delete a meme', async () => { @@ -31,7 +36,7 @@ describe("[DELETE] '/api/meme/:memeId' ", () => { expect(response.statusCode).toBe(200); expect(response.body.data).toBeTruthy(); - response = await request(app).get(`/api/meme/list`); + response = await request(app).get(`/api/meme/list`).set('x-device-id', 'deviceId'); expect(response.statusCode).toBe(200); expect(response.body.data.memeList.length).toBe(1); }); diff --git a/test/meme/get-meme-list.test.ts b/test/meme/get-meme-list.test.ts index 8947025..d7abada 100644 --- a/test/meme/get-meme-list.test.ts +++ b/test/meme/get-meme-list.test.ts @@ -3,8 +3,10 @@ import request from 'supertest'; import app from '../../src/app'; import { KeywordModel } from '../../src/model/keyword'; import { MemeModel } from '../../src/model/meme'; +import { UserModel } from '../../src/model/user'; import { createMockData as createKeywordMockData } from '../util/keyword.mock'; import { createMockData } from '../util/meme.mock'; +import { mockUser } from '../util/user.mock'; const totalCount = 15; let keywordIds = []; @@ -19,14 +21,17 @@ describe("[GET] '/api/meme/list' ", () => { const memeMockDatas = createMockData(totalCount, 1, keywordIds); await MemeModel.insertMany(memeMockDatas); + + await UserModel.insertMany(mockUser); }); afterAll(async () => { await MemeModel.deleteMany({}); + await UserModel.deleteMany({}); }); it('should return the default paginated list of memes', async () => { - const response = await request(app).get('/api/meme/list'); + const response = await request(app).get('/api/meme/list').set('x-device-id', 'deviceId'); expect(response.statusCode).toBe(200); expect(response.body.data.pagination.total).toBe(totalCount); expect(response.body.data.pagination.page).toBe(1); @@ -42,7 +47,9 @@ describe("[GET] '/api/meme/list' ", () => { it('should return paginated list of memes for specific page and size', async () => { const size = 5; const page = 1; - const response = await request(app).get(`/api/meme/list?page=${page}&size=${size}`); + const response = await request(app) + .get(`/api/meme/list?page=${page}&size=${size}`) + .set('x-device-id', 'deviceId'); expect(response.statusCode).toBe(200); expect(response.body.data.pagination.total).toBe(totalCount); @@ -54,7 +61,9 @@ describe("[GET] '/api/meme/list' ", () => { it('should return an error for invalid page', async () => { const size = 5; const page = -1; - const response = await request(app).get(`/api/meme/list?page=${page}&size=${size}`); + const response = await request(app) + .get(`/api/meme/list?page=${page}&size=${size}`) + .set('x-device-id', 'deviceId'); expect(response.statusCode).toBe(400); }); @@ -62,7 +71,9 @@ describe("[GET] '/api/meme/list' ", () => { it('should return an error for invalid size', async () => { const size = -1; const page = 3; - const response = await request(app).get(`/api/meme/list?page=${page}&size=${size}`); + const response = await request(app) + .get(`/api/meme/list?page=${page}&size=${size}`) + .set('x-device-id', 'deviceId'); expect(response.statusCode).toBe(400); }); diff --git a/test/meme/get-meme.test.ts b/test/meme/get-meme.test.ts index d21b6c0..0205704 100644 --- a/test/meme/get-meme.test.ts +++ b/test/meme/get-meme.test.ts @@ -4,8 +4,10 @@ import request from 'supertest'; import app from '../../src/app'; import { KeywordModel } from '../../src/model/keyword'; import { MemeModel } from '../../src/model/meme'; +import { UserModel } from '../../src/model/user'; import { createMockData as createKeywordMockData } from '../util/keyword.mock'; import { createMockData as createMemeMockData } from '../util/meme.mock'; +import { mockUser } from '../util/user.mock'; let testMemeId = ''; let keywordIds = []; @@ -23,21 +25,28 @@ describe("[GET] '/api/meme/:memeId' ", () => { memeList = await MemeModel.find({}); testMemeId = memeList[0]._id.toString(); + + await UserModel.insertMany(mockUser); }); afterAll(async () => { await MemeModel.deleteMany({}); + await UserModel.deleteMany({}); }); it('should get a meme', async () => { - const response = await request(app).get(`/api/meme/${testMemeId}`); + const response = await request(app) + .get(`/api/meme/${testMemeId}`) + .set('x-device-id', 'deviceId'); expect(response.body.data._id).toBe(testMemeId); expect(response.body.data).toHaveProperty('keywords'); expect(response.body.data.isTodayMeme).toBeFalsy(); }); it('should not get a meme with nonexisting id', async () => { - const response = await request(app).get(`/api/meme/nonexistingId`); + const response = await request(app) + .get(`/api/meme/nonexistingId`) + .set('x-device-id', 'deviceId'); expect(response.statusCode).toBe(400); }); }); diff --git a/test/meme/get-recommend-meme-list.test.ts b/test/meme/get-recommend-meme-list.test.ts index 1c0fc2b..e5f35a9 100644 --- a/test/meme/get-recommend-meme-list.test.ts +++ b/test/meme/get-recommend-meme-list.test.ts @@ -3,31 +3,35 @@ import request from 'supertest'; import app from '../../src/app'; import { KeywordModel } from '../../src/model/keyword'; import { MemeModel } from '../../src/model/meme'; +import { UserModel } from '../../src/model/user'; import { createMockData as createKeywordMockData } from '../util/keyword.mock'; import { createMockData } from '../util/meme.mock'; +import { mockUser } from '../util/user.mock'; const totalCount = 10; let keywordIds = []; -let keywords = []; describe("[GET] '/api/meme/recommend-memes' ", () => { beforeEach(async () => { const keywordMockDatas = createKeywordMockData(5); const createdKeywords = await KeywordModel.insertMany(keywordMockDatas); keywordIds = createdKeywords.map((k) => k._id); - keywords = createdKeywords.map((k) => k.name); + await UserModel.insertMany(mockUser); }); afterEach(async () => { await MemeModel.deleteMany({}); await KeywordModel.deleteMany({}); + await UserModel.deleteMany({}); }); it('should return list of recommend-memes - default size: 5', async () => { const mockDatas = createMockData(totalCount, 5, keywordIds); await MemeModel.insertMany(mockDatas); - const response = await request(app).get('/api/meme/recommend-memes'); + const response = await request(app) + .get('/api/meme/recommend-memes') + .set('x-device-id', 'deviceId'); expect(response.statusCode).toBe(200); expect(response.body.data.length).toBe(5); }); @@ -37,9 +41,9 @@ describe("[GET] '/api/meme/recommend-memes' ", () => { const mockDatas = createMockData(totalCount, customizedTodayMemeCount, keywordIds); await MemeModel.insertMany(mockDatas); - const response = await request(app).get( - `/api/meme/recommend-memes?size=${customizedTodayMemeCount}`, - ); + const response = await request(app) + .get(`/api/meme/recommend-memes?size=${customizedTodayMemeCount}`) + .set('x-device-id', 'deviceId'); expect(response.statusCode).toBe(200); expect(response.body.data.length).toBe(customizedTodayMemeCount); @@ -50,9 +54,9 @@ describe("[GET] '/api/meme/recommend-memes' ", () => { const mockDatas = createMockData(totalCount, customizedTodayMemeCount, keywordIds); await MemeModel.insertMany(mockDatas); - const response = await request(app).get( - `/api/meme/recommend-memes?size=${customizedTodayMemeCount}`, - ); + const response = await request(app) + .get(`/api/meme/recommend-memes?size=${customizedTodayMemeCount}`) + .set('x-device-id', 'deviceId'); expect(response.statusCode).toBe(400); }); diff --git a/test/meme/patch-meme.test.ts b/test/meme/patch-meme.test.ts index 4714195..7434843 100644 --- a/test/meme/patch-meme.test.ts +++ b/test/meme/patch-meme.test.ts @@ -3,8 +3,10 @@ import request from 'supertest'; import app from '../../src/app'; import { KeywordModel } from '../../src/model/keyword'; import { IMemeUpdatePayload, MemeModel } from '../../src/model/meme'; +import { UserModel } from '../../src/model/user'; import { createMockData as createKeywordMockData } from '../util/keyword.mock'; import { createMockData } from '../util/meme.mock'; +import { mockUser } from '../util/user.mock'; let memeList = []; let keywordIds = []; @@ -22,10 +24,13 @@ describe("[PATCH] '/api/meme/:memeId' ", () => { await MemeModel.insertMany(mockDatas); memeList = await MemeModel.find({}); testMemeId = memeList[0]._id.toString(); + + await UserModel.insertMany(mockUser); }); afterAll(async () => { await MemeModel.deleteMany({}); + await UserModel.deleteMany({}); }); it('should patch a meme', async () => { @@ -37,9 +42,9 @@ describe("[PATCH] '/api/meme/:memeId' ", () => { expect(response.statusCode).toBe(200); expect(response.body.data._id).toBe(memeList[0]._id.toString()); - response = await request(app).get(`/api/meme/${testMemeId}`); + response = await request(app).get(`/api/meme/${testMemeId}`).set('x-device-id', 'deviceId'); expect(response.body.data._id).toBe(memeList[0]._id.toString()); - expect(response.body.data.keywords).toEqual([keywords[1]]); + expect(response.body.data.keywords).toHaveProperty({ _id: keywordIds[1], name: keywords[1] }); expect(response.body.data.isTodayMeme).toBeTruthy(); }); });