Add ability to mock captcha via process.env.CAPTCHA
process.env.NODE_ENV must be set to test
This commit is contained in:
parent
a9f37103bd
commit
0ef21394e3
14
packages/captcha/src/Captcha.test.ts
Normal file
14
packages/captcha/src/Captcha.test.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { getValue } from './Captcha'
|
||||||
|
|
||||||
|
describe('getValue', () => {
|
||||||
|
it('returns value by default', () => {
|
||||||
|
expect(getValue('test')).toBe('test')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns process.env.CAPTCHA value (for testing)', () => {
|
||||||
|
expect(getValue('1234', {
|
||||||
|
NODE_ENV: 'test',
|
||||||
|
CAPTCHA: '5678',
|
||||||
|
})).toBe('5678')
|
||||||
|
})
|
||||||
|
})
|
||||||
@ -15,14 +15,20 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To make it easier to pass captcha in tests
|
||||||
|
*/
|
||||||
|
export function getValue(value: string, env = process.env) {
|
||||||
|
return env.NODE_ENV === 'test' && env.CAPTCHA ? env.CAPTCHA : value
|
||||||
|
}
|
||||||
|
|
||||||
export function createCaptcha(
|
export function createCaptcha(
|
||||||
value: string,
|
value: string,
|
||||||
type: CaptchaType,
|
type: CaptchaType,
|
||||||
): Captcha {
|
): Captcha {
|
||||||
return {
|
return {
|
||||||
value,
|
value: getValue(value),
|
||||||
type,
|
type,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user