(1) 암호화 역할 함수를 작성 하였습니다.
//test.encrypt.helper.ts
export class TestEncryptHelper {
static async encrypt(password: string): Promise<string> {
const { createHash } = require('crypto');
return createHash('sha256').update(`${password}[SaltValue]`).digest('hex');
}
}
(2) 단위 테스트를 진행해보기 위하여 작성 하였습니다.
//test.encrypt.helper.spec.ts
import { TestEncryptHelper } from './test.encrypt.helper'
describe('encryptTest' , () => {
it('Text encrypt', async () => {
await TestEncryptHelper.encrypt("1111").then((a) => {
expect(a).toEqual("499327aa0b416319b8f52ec8c8f9f397dcdacc5839bce7dd6080844e59e42bf9");
});
});
});
(3) 테스트 결과 입니다.
$ npm run test > test_api@0.0.1 test > jest PASS src/common/helpers/test.encrypt.helper.spec.ts (14.264 s) encryptTest √ Text encrypt (9 ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 14.857 s Ran all test suites. |
'nest.js' 카테고리의 다른 글
[nestjs] luxon 을 이용하여 심플하게 날짜 및 시간 포멧팅 처리 예제 (0) | 2025.04.04 |
---|---|
[typeorm] createQueryBuilder 를 이용한 MYSQL FULLTEXT SEARCH 검색 테스트 예제 (0) | 2025.04.04 |
[typeorm] countBy 사용시에 동일한 컬럼 두번 정의 불가 (0) | 2025.03.20 |
[nestjs] java jar library 함수 호출 예제 (0) | 2025.02.26 |
node net.connect를 이용하여 Blocking TCP Socket Message Send, Receive 테스트 진행 (3) | 2024.10.09 |