Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Treterten committed May 30, 2024
1 parent 8d1d28d commit cf17dca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
17 changes: 12 additions & 5 deletions src/__tests__/connection/database/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ describe('database/actions.js', () => {

describe('exported functions', () => {
const id = 2;
const m = Immutable.fromJS({
const hookRunner = jest.fn((str, m, context, fn) => fn());

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note test

Unused variable hookRunner.
const mCaptcha = Immutable.fromJS({
field: {
email: {
value: '[email protected]'
Expand Down Expand Up @@ -266,35 +267,41 @@ describe('database/actions.js', () => {
{ name: 'other_prop' }
]
},
captcha: {
provider: 'auth0'
},
passwordResetCaptcha: {
provider: 'auth0'
},
});

describe('resetPasswordSuccess', () => {
it('runs swap CAPTCHA', () => {
swap(setEntity, 'lock', id, m);
swap(setEntity, 'lock', id, mCaptcha);
resetPasswordSuccess(id);
expect(swapCaptcha.mock.calls.length).toEqual(1);
});
});

describe('showResetPasswordActivity', () => {
it('runs swap CAPTCHA', () => {
swap(setEntity, 'lock', id, m);
swap(setEntity, 'lock', id, mCaptcha);
showResetPasswordActivity(id);
expect(swapCaptcha.mock.calls.length).toEqual(1);
});
});

describe('showLoginActivity', () => {
it('runs swap CAPTCHA', () => {
swap(setEntity, 'lock', id, m);
swap(setEntity, 'lock', id, mCaptcha);
showLoginActivity(id);
expect(swapCaptcha.mock.calls.length).toEqual(1);
});
});

describe('showSignupActivity', () => {
it('runs swap CAPTCHA', () => {
swap(setEntity, 'lock', id, m);
swap(setEntity, 'lock', id, mCaptcha);
showSignUpActivity(id);
expect(swapCaptcha.mock.calls.length).toEqual(1);
});
Expand Down
9 changes: 3 additions & 6 deletions src/connection/database/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ function resetPasswordError(id, error) {
export function showLoginActivity(id, fields = ['password']) {
const m = read(getEntity, 'lock', id);
const captchaConfig = l.captcha(m);
const captchaProvider = captchaConfig.get('provider');
if (captchaProvider === 'arkose') {
if (captchaConfig && captchaConfig.get('provider') === 'arkose') {
swap(updateEntity, 'lock', id, setScreen, 'login', fields);
} else {
swapCaptcha(id, 'login', false, () => {
Expand All @@ -324,8 +323,7 @@ export function showLoginActivity(id, fields = ['password']) {
export function showSignUpActivity(id, fields = ['password']) {
const m = read(getEntity, 'lock', id);
const captchaConfig = l.captcha(m);
const captchaProvider = captchaConfig.get('provider');
if (captchaProvider === 'arkose') {
if (captchaConfig && captchaConfig.get('provider') === 'arkose') {
swap(updateEntity, 'lock', id, setScreen, 'signUp', fields);
} else {
swapCaptcha(id, 'login', false, () => {
Expand All @@ -337,8 +335,7 @@ export function showSignUpActivity(id, fields = ['password']) {
export function showResetPasswordActivity(id, fields = ['password']) {
const m = read(getEntity, 'lock', id);
const captchaConfig = l.passwordResetCaptcha(m);
const captchaProvider = captchaConfig.get('provider');
if (captchaProvider === 'arkose') {
if (captchaConfig && captchaConfig.get('provider') === 'arkose') {
swap(updateEntity, 'lock', id, setScreen, 'forgotPassword', fields);
} else {
swapCaptcha(id, 'login', false, () => {
Expand Down

0 comments on commit cf17dca

Please sign in to comment.