From 0901c717c63d7d1784a266f6fe5127d19d92b610 Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Fri, 10 Dec 2021 17:09:01 +0100 Subject: [PATCH] fix tests --- .../user/auth/GET-user_auth_apple.test.js | 8 ++- .../user/auth/POST-user_auth_social.test.js | 62 +++++++++++++------ .../auth/POST-user_reset_password.test.js | 13 ++-- 3 files changed, 56 insertions(+), 27 deletions(-) diff --git a/test/api/v3/integration/user/auth/GET-user_auth_apple.test.js b/test/api/v3/integration/user/auth/GET-user_auth_apple.test.js index e5beba1fc0..b1c97f6ca4 100644 --- a/test/api/v3/integration/user/auth/GET-user_auth_apple.test.js +++ b/test/api/v3/integration/user/auth/GET-user_auth_apple.test.js @@ -1,3 +1,4 @@ +import { v4 as generateUUID } from 'uuid'; import { generateUser, requester, @@ -12,14 +13,15 @@ describe('GET /user/auth/apple', () => { let randomAppleId = '123456'; beforeEach(async () => { + api = requester(); + user = await generateUser(); randomAppleId = generateUUID(); const expectedResult = { id: randomAppleId, name: 'an apple user' }; sandbox.stub(appleAuth, 'appleProfile').returns(Promise.resolve(expectedResult)); }); - beforeEach(async () => { - api = requester(); - user = await generateUser(); + afterEach(async () => { + appleAuth.appleProfile.restore(); }); it('registers a new user', async () => { diff --git a/test/api/v3/integration/user/auth/POST-user_auth_social.test.js b/test/api/v3/integration/user/auth/POST-user_auth_social.test.js index f6cbc7910d..c4ffe57efb 100644 --- a/test/api/v3/integration/user/auth/POST-user_auth_social.test.js +++ b/test/api/v3/integration/user/auth/POST-user_auth_social.test.js @@ -1,11 +1,11 @@ import passport from 'passport'; +import { v4 as generateUUID } from 'uuid'; import { generateUser, requester, translate as t, getProperty, } from '../../../../../helpers/api-integration/v3'; -import { v4 as generateUUID } from 'uuid'; describe('POST /user/auth/social', () => { let api; @@ -36,9 +36,13 @@ describe('POST /user/auth/social', () => { describe('facebook', () => { beforeEach(async () => { randomFacebookId = generateUUID(); - const expectedResult = { id: randomFacebookId, displayName: 'a facebook user', emails: [ - { value: `${user.auth.local.username}+facebook@example.com`} - ] }; + const expectedResult = { + id: randomFacebookId, + displayName: 'a facebook user', + emails: [ + { value: `${user.auth.local.username}+facebook@example.com` }, + ], + }; sandbox.stub(passport._strategies.facebook, 'userProfile').yields(null, expectedResult); network = 'facebook'; }); @@ -83,9 +87,13 @@ describe('POST /user/auth/social', () => { it('logs an existing user in if they have local auth with matching email', async () => { passport._strategies.facebook.userProfile.restore(); - const expectedResult = { id: randomFacebookId, displayName: 'a facebook user', emails: [ - { value: user.auth.local.email}, - ] }; + const expectedResult = { + id: randomFacebookId, + displayName: 'a facebook user', + emails: [ + { value: user.auth.local.email }, + ], + }; sandbox.stub(passport._strategies.facebook, 'userProfile').yields(null, expectedResult); const response = await api.post(endpoint, { @@ -106,9 +114,13 @@ describe('POST /user/auth/social', () => { expect(registerResponse.newUser).to.be.true; // This is important for existing accounts before the new social handling passport._strategies.facebook.userProfile.restore(); - const expectedResult = { id: randomFacebookId, displayName: 'a facebook user', emails: [ - { value: user.auth.local.email}, - ] }; + const expectedResult = { + id: randomFacebookId, + displayName: 'a facebook user', + emails: [ + { value: user.auth.local.email }, + ], + }; sandbox.stub(passport._strategies.facebook, 'userProfile').yields(null, expectedResult); const response = await api.post(endpoint, { @@ -164,9 +176,13 @@ describe('POST /user/auth/social', () => { describe('google', () => { beforeEach(async () => { randomGoogleId = generateUUID(); - const expectedResult = { id: randomGoogleId, displayName: 'a google user', emails: [ - { value: `${user.auth.local.username}+google@example.com`} - ] }; + const expectedResult = { + id: randomGoogleId, + displayName: 'a google user', + emails: [ + { value: `${user.auth.local.username}+google@example.com` }, + ], + }; sandbox.stub(passport._strategies.google, 'userProfile').yields(null, expectedResult); network = 'google'; }); @@ -208,9 +224,13 @@ describe('POST /user/auth/social', () => { it('logs an existing user in if they have local auth with matching email', async () => { passport._strategies.google.userProfile.restore(); - const expectedResult = { id: randomGoogleId, displayName: 'a google user', emails: [ - { value: user.auth.local.email}, - ] }; + const expectedResult = { + id: randomGoogleId, + displayName: 'a google user', + emails: [ + { value: user.auth.local.email }, + ], + }; sandbox.stub(passport._strategies.google, 'userProfile').yields(null, expectedResult); const response = await api.post(endpoint, { @@ -231,9 +251,13 @@ describe('POST /user/auth/social', () => { expect(registerResponse.newUser).to.be.true; // This is important for existing accounts before the new social handling passport._strategies.google.userProfile.restore(); - const expectedResult = { id: randomGoogleId, displayName: 'a google user', emails: [ - { value: user.auth.local.email}, - ] }; + const expectedResult = { + id: randomGoogleId, + displayName: 'a google user', + emails: [ + { value: user.auth.local.email }, + ], + }; sandbox.stub(passport._strategies.google, 'userProfile').yields(null, expectedResult); const response = await api.post(endpoint, { diff --git a/test/api/v3/integration/user/auth/POST-user_reset_password.test.js b/test/api/v3/integration/user/auth/POST-user_reset_password.test.js index 036ce689e2..8b41593d5c 100644 --- a/test/api/v3/integration/user/auth/POST-user_reset_password.test.js +++ b/test/api/v3/integration/user/auth/POST-user_reset_password.test.js @@ -26,16 +26,19 @@ describe('POST /user/reset-password', async () => { }); it('resets password for social users', async () => { - const email = `${user.auth.local.username}+google@example.com` - user.auth.google.emails = [email]; + const email = `${user.auth.local.username}+google@example.com`; + await user.update({ 'auth.google.emails': [{ value: email }] }); await user.sync(); - const previousPassword = user.auth.local.hashed_password; + const previousPassword = user.auth.local.passwordResetCode; + console.log(previousPassword); const response = await user.post(endpoint, { - email: email, + email, }); expect(response).to.eql({ data: {}, message: t('passwordReset') }); await user.sync(); - expect(user.auth.local.hashed_password).to.not.eql(previousPassword); + console.log(user.auth) + console.log(user.auth.local.hashed_password + " OLD " + previousPassword); + expect(user.auth.local.passwordResetCode).to.not.eql(previousPassword); }); it('same message on error as on success', async () => {