@@ -8,11 +8,11 @@ import {
88import { User } from '../../../src/user/entity/user.entity' ;
99import { UserRepository } from '../../../src/user/repository/user.repository' ;
1010import { UserFixture } from '../../fixture/user.fixture' ;
11- import * as path from 'path' ;
1211import TestAgent from 'supertest/lib/agent' ;
1312import { FileRepository } from '../../../src/file/repository/file.repository' ;
1413import { createAccessToken } from '../../jest.setup' ;
1514import * as fs from 'fs/promises' ;
15+ import * as uuid from 'uuid' ;
1616
1717const URL = '/api/file' ;
1818
@@ -21,6 +21,7 @@ describe(`POST ${URL} E2E Test`, () => {
2121 let agent : TestAgent ;
2222 let user : User ;
2323 let fileRepository : FileRepository ;
24+ const fileRandomName = 'test-random-uuid-file-name' ;
2425
2526 beforeAll ( async ( ) => {
2627 app = global . testApp ;
@@ -35,6 +36,7 @@ describe(`POST ${URL} E2E Test`, () => {
3536 beforeEach ( ( ) => {
3637 jest . spyOn ( fs , 'writeFile' ) . mockResolvedValue ( undefined ) ;
3738 jest . spyOn ( fs , 'mkdir' ) . mockResolvedValue ( undefined ) ;
39+ jest . spyOn ( uuid , 'v4' ) . mockReturnValue ( fileRandomName as any ) ;
3840 } ) ;
3941
4042 it ( '[401] μΈμ¦λμ§ μμ μ¬μ©μκ° μμ²ν κ²½μ° νμΌ μ
λ‘λλ₯Ό μ€ν¨νλ€.' , async ( ) => {
@@ -69,6 +71,15 @@ describe(`POST ${URL} E2E Test`, () => {
6971 const { data } = response . body ;
7072 expect ( response . status ) . toBe ( HttpStatus . BAD_REQUEST ) ;
7173 expect ( data ) . toBeUndefined ( ) ;
74+
75+ // DB, Redis when
76+ const savedFile = await fileRepository . findOneBy ( {
77+ originalName : 'test.png' ,
78+ mimetype : 'image/png' ,
79+ } ) ;
80+
81+ // DB, Redis then
82+ expect ( savedFile ) . toBeNull ( ) ;
7283 } ) ;
7384
7485 it ( '[400] νμΌ νμ
μ΄ μΌμΉνμ§ μμ κ²½μ° νμΌ μ
λ‘λλ₯Ό μ€ν¨νλ€. ' , async ( ) => {
@@ -90,6 +101,15 @@ describe(`POST ${URL} E2E Test`, () => {
90101 const { data } = response . body ;
91102 expect ( response . status ) . toBe ( HttpStatus . BAD_REQUEST ) ;
92103 expect ( data ) . toBeUndefined ( ) ;
104+
105+ // DB, Redis when
106+ const savedFile = await fileRepository . findOneBy ( {
107+ originalName : 'test.png' ,
108+ mimetype : 'image/png' ,
109+ } ) ;
110+
111+ // DB, Redis then
112+ expect ( savedFile ) . toBeNull ( ) ;
93113 } ) ;
94114
95115 it ( '[400] νμΌ ν¬κΈ°κ° μΌμΉνμ§ μμ κ²½μ° νμΌ μ
λ‘λλ₯Ό μ€ν¨νλ€. ' , async ( ) => {
@@ -111,6 +131,15 @@ describe(`POST ${URL} E2E Test`, () => {
111131 const { data } = response . body ;
112132 expect ( response . status ) . toBe ( HttpStatus . BAD_REQUEST ) ;
113133 expect ( data ) . toBeUndefined ( ) ;
134+
135+ // DB, Redis when
136+ const savedFile = await fileRepository . findOneBy ( {
137+ originalName : 'test.png' ,
138+ mimetype : 'image/png' ,
139+ } ) ;
140+
141+ // DB, Redis then
142+ expect ( savedFile ) . toBeNull ( ) ;
114143 } ) ;
115144
116145 it ( '[201] νμΌμ ν¬ν¨ν κ²½μ° νμΌ μ
λ‘λλ₯Ό μ±κ³΅νλ€.' , async ( ) => {
@@ -135,8 +164,8 @@ describe(`POST ${URL} E2E Test`, () => {
135164 id : expect . any ( Number ) ,
136165 originalName : 'test.png' ,
137166 mimetype : 'image/png' ,
138- size : expect . any ( Number ) ,
139- url : expect . any ( String ) ,
167+ size : 1024 ,
168+ url : expect . stringContaining ( fileRandomName ) ,
140169 userId : user . id ,
141170 createdAt : expect . any ( String ) ,
142171 } ) ;
0 commit comments