Skip to content

Commit

Permalink
test: E2E테스트에서 외래키 제약조건으로 인한 테이블 삭제 실패를 방지하는 로직 추가
Browse files Browse the repository at this point in the history
- 테이블을 삭제할때 해당 테이블의 행을 참조하는 다른 테이블의 행이 있어도 테이블 삭제가 가능하도록 FOREIGN_KEY_CHECKS 변수를 0으로 설정
- 테이블 삭제 후 모두 FOREIGN_KEY_CHECKS변수를 1로 설정
  • Loading branch information
choyoungwoo9 committed Jul 3, 2024
1 parent 6000d2f commit 8a3be69
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backend/test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,13 @@ beforeAll(async () => {

beforeEach(async () => {
dataSource = app.get(DataSource);
await dataSource.query('SET FOREIGN_KEY_CHECKS = 0');
const entities = dataSource.entityMetadatas;
for (const entity of entities) {
const repository = dataSource.getRepository(entity.name);
await repository.query(`DELETE FROM \`${entity.tableName}\``);
}
await dataSource.query('SET FOREIGN_KEY_CHECKS = 1');
});

afterAll(async () => {
Expand Down

0 comments on commit 8a3be69

Please sign in to comment.