1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| const { createUser } = require('../src/registration') const { internet, phone, address, random } = require('faker') const RandExp = require('randexp')
function generateStrongPassword() { const strongPasswordPattern = /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[*.!@$%^&(){}\][:;<>,.?/~_+\-=|]).{8,16}$/ let password = null
do { password = new RandExp(strongPasswordPattern).gen() } while (!password.match(strongPasswordPattern))
return password }
describe('사용자가 데이터를 예상대로 보낼 때', () => { test('필수항목 + 선택항목 - User', async () => { const user = await createUser({ email: internet.email(), password: generateStrongPassword(), nick: internet.userName(), phone: phone.phoneNumber('010-####-####'), postalCode: address.zipCode('#####'), }) expect(user).not.toBeNull() }) test('필수항목 - User', async () => { const user = await createUser({ email: internet.email(), password: generateStrongPassword(), nick: internet.userName(), phone: '', postalCode: '', }) expect(user).not.toBeNull() }) })
describe('사용자가 데이터를 누락했을 때', () => { test('이메일 필드를 보내지 않았을 때 - null', async () => { const user = await createUser({ email: '', password: generateStrongPassword(), nick: internet.userName(), phone: phone.phoneNumber('010-####-####'), postalCode: address.zipCode('#####'), }) expect(user).toBeNull() }) test('비밀번호 필드를 보내지 않았을 때 - null', async () => { const user = await createUser({ email: internet.email(), password: '', nick: internet.userName(), phone: phone.phoneNumber('010-####-####'), postalCode: address.zipCode('#####'), }) expect(user).toBeNull() }) test('닉네임 필드를 보내지 않았을 때 - null', async () => { const user = await createUser({ email: internet.email(), password: generateStrongPassword(), nick: '', phone: phone.phoneNumber('010-####-####'), postalCode: address.zipCode('#####'), }) expect(user).toBeNull() }) test('모바일 필드를 보내지 않았을 때 - User', async () => { const user = await createUser({ email: internet.email(), password: generateStrongPassword(), nick: internet.userName(), phone: '', postalCode: address.zipCode('#####'), }) expect(user).not.toBeNull() }) test('우편번호 필드를 보내지 않았을 때 - User', async () => { const user = await createUser({ email: internet.email(), password: generateStrongPassword(), nick: internet.userName(), phone: phone.phoneNumber('010-####-####'), postalCode: '', }) expect(user).not.toBeNull() }) })
describe('사용자가 데이터를 부실하게 보낼 때', () => { test('이메일 형식이 잘못되었을 때 - null', async () => { const user = await createUser({ email: random.alphaNumeric(10), password: generateStrongPassword(), nick: internet.userName(), phone: phone.phoneNumber('010-####-####'), postalCode: address.zipCode('#####'), }) expect(user).toBeNull() }) test('비밀번호의 강도가 너무 약할 때 - null', async () => { const user = await createUser({ email: internet.email(), password: random.alphaNumeric(10), nick: internet.userName(), phone: phone.phoneNumber('010-####-####'), postalCode: address.zipCode('#####'), }) expect(user).toBeNull() }) })
|