|
| 1 | +import { describe, it, jest } from '@jest/globals'; |
| 2 | +import { assertTurboContract } from '../../app/__tests__/turboModuleContractHelper'; |
| 3 | + |
| 4 | +const SPEC_METHODS = [ |
| 5 | + 'configureAuthDomain', |
| 6 | + 'getCustomAuthDomain', |
| 7 | + 'addAuthStateListener', |
| 8 | + 'removeAuthStateListener', |
| 9 | + 'addIdTokenListener', |
| 10 | + 'removeIdTokenListener', |
| 11 | + 'forceRecaptchaFlowForTesting', |
| 12 | + 'setAutoRetrievedSmsCodeForPhoneNumber', |
| 13 | + 'setAppVerificationDisabledForTesting', |
| 14 | + 'useUserAccessGroup', |
| 15 | + 'signOut', |
| 16 | + 'signInAnonymously', |
| 17 | + 'createUserWithEmailAndPassword', |
| 18 | + 'isSignInWithEmailLink', |
| 19 | + 'signInWithEmailAndPassword', |
| 20 | + 'signInWithEmailLink', |
| 21 | + 'signInWithCustomToken', |
| 22 | + 'revokeToken', |
| 23 | + 'sendPasswordResetEmail', |
| 24 | + 'sendSignInLinkToEmail', |
| 25 | + 'deleteUser', |
| 26 | + 'reload', |
| 27 | + 'sendEmailVerification', |
| 28 | + 'verifyBeforeUpdateEmail', |
| 29 | + 'updateEmail', |
| 30 | + 'updatePassword', |
| 31 | + 'updatePhoneNumber', |
| 32 | + 'updateProfile', |
| 33 | + 'getIdToken', |
| 34 | + 'getIdTokenResult', |
| 35 | + 'signInWithCredential', |
| 36 | + 'signInWithProvider', |
| 37 | + 'signInWithPhoneNumber', |
| 38 | + 'verifyPhoneNumberWithMultiFactorInfo', |
| 39 | + 'verifyPhoneNumberForMultiFactor', |
| 40 | + 'resolveMultiFactorSignIn', |
| 41 | + 'resolveTotpSignIn', |
| 42 | + 'generateTotpSecret', |
| 43 | + 'generateQrCodeUrl', |
| 44 | + 'openInOtpApp', |
| 45 | + 'getSession', |
| 46 | + 'unenrollMultiFactor', |
| 47 | + 'finalizeMultiFactorEnrollment', |
| 48 | + 'finalizeTotpEnrollment', |
| 49 | + 'confirmationResultConfirm', |
| 50 | + 'verifyPhoneNumber', |
| 51 | + 'confirmPasswordReset', |
| 52 | + 'applyActionCode', |
| 53 | + 'checkActionCode', |
| 54 | + 'linkWithCredential', |
| 55 | + 'linkWithProvider', |
| 56 | + 'unlink', |
| 57 | + 'reauthenticateWithCredential', |
| 58 | + 'reauthenticateWithProvider', |
| 59 | + 'fetchSignInMethodsForEmail', |
| 60 | + 'setLanguageCode', |
| 61 | + 'setTenantId', |
| 62 | + 'useDeviceLanguage', |
| 63 | + 'verifyPasswordResetCode', |
| 64 | + 'useEmulator', |
| 65 | +] as const; |
| 66 | + |
| 67 | +describe('TurboModule wrapper contract (NewArch-AD-17.1)', function () { |
| 68 | + it('exposes every spec method callable through the real wrapper', function () { |
| 69 | + assertTurboContract( |
| 70 | + { |
| 71 | + namespace: 'auth', |
| 72 | + nativeModuleName: 'NativeRNFBTurboAuth', |
| 73 | + nativeEvents: ['auth_state_changed', 'auth_id_token_changed', 'phone_auth_state_changed'], |
| 74 | + hasMultiAppSupport: true, |
| 75 | + hasCustomUrlOrRegionSupport: false, |
| 76 | + turboModule: true, |
| 77 | + specMethods: SPEC_METHODS, |
| 78 | + constants: { |
| 79 | + APP_LANGUAGE: { '[DEFAULT]': 'en-US' }, |
| 80 | + APP_USER: { '[DEFAULT]': null }, |
| 81 | + }, |
| 82 | + createMock: method => |
| 83 | + jest.fn(() => |
| 84 | + method === 'configureAuthDomain' || |
| 85 | + method === 'addAuthStateListener' || |
| 86 | + method === 'removeAuthStateListener' || |
| 87 | + method === 'addIdTokenListener' || |
| 88 | + method === 'removeIdTokenListener' || |
| 89 | + method === 'setLanguageCode' || |
| 90 | + method === 'useDeviceLanguage' || |
| 91 | + method === 'openInOtpApp' || |
| 92 | + method === 'verifyPhoneNumber' || |
| 93 | + method === 'useEmulator' || |
| 94 | + method === 'isSignInWithEmailLink' |
| 95 | + ? method === 'isSignInWithEmailLink' |
| 96 | + ? false |
| 97 | + : undefined |
| 98 | + : Promise.resolve(), |
| 99 | + ), |
| 100 | + }, |
| 101 | + { |
| 102 | + createUserWithEmailAndPassword: wrapped => { |
| 103 | + void wrapped.createUserWithEmailAndPassword('a@b.com', 'password'); |
| 104 | + }, |
| 105 | + signInWithEmailAndPassword: wrapped => { |
| 106 | + void wrapped.signInWithEmailAndPassword('a@b.com', 'password'); |
| 107 | + }, |
| 108 | + signInWithEmailLink: wrapped => { |
| 109 | + void wrapped.signInWithEmailLink('a@b.com', 'https://example.com/link'); |
| 110 | + }, |
| 111 | + signInWithCustomToken: wrapped => { |
| 112 | + void wrapped.signInWithCustomToken('token'); |
| 113 | + }, |
| 114 | + signInWithCredential: wrapped => { |
| 115 | + void wrapped.signInWithCredential('google.com', 'token', 'secret'); |
| 116 | + }, |
| 117 | + signInWithProvider: wrapped => { |
| 118 | + void wrapped.signInWithProvider({ providerId: 'google.com' }); |
| 119 | + }, |
| 120 | + signInWithPhoneNumber: wrapped => { |
| 121 | + void wrapped.signInWithPhoneNumber('+15555550100', true); |
| 122 | + }, |
| 123 | + sendPasswordResetEmail: wrapped => { |
| 124 | + void wrapped.sendPasswordResetEmail('a@b.com', null); |
| 125 | + }, |
| 126 | + sendSignInLinkToEmail: wrapped => { |
| 127 | + void wrapped.sendSignInLinkToEmail('a@b.com', { url: 'https://example.com' }); |
| 128 | + }, |
| 129 | + sendEmailVerification: wrapped => { |
| 130 | + void wrapped.sendEmailVerification(null); |
| 131 | + }, |
| 132 | + verifyBeforeUpdateEmail: wrapped => { |
| 133 | + void wrapped.verifyBeforeUpdateEmail('new@b.com', null); |
| 134 | + }, |
| 135 | + updatePhoneNumber: wrapped => { |
| 136 | + void wrapped.updatePhoneNumber('phone', 'token', 'secret'); |
| 137 | + }, |
| 138 | + updateProfile: wrapped => { |
| 139 | + void wrapped.updateProfile({ displayName: 'Test' }); |
| 140 | + }, |
| 141 | + getIdToken: wrapped => { |
| 142 | + void wrapped.getIdToken(true); |
| 143 | + }, |
| 144 | + getIdTokenResult: wrapped => { |
| 145 | + void wrapped.getIdTokenResult(true); |
| 146 | + }, |
| 147 | + verifyPhoneNumberWithMultiFactorInfo: wrapped => { |
| 148 | + void wrapped.verifyPhoneNumberWithMultiFactorInfo('uid', 'session'); |
| 149 | + }, |
| 150 | + verifyPhoneNumberForMultiFactor: wrapped => { |
| 151 | + void wrapped.verifyPhoneNumberForMultiFactor('+15555550100', 'session'); |
| 152 | + }, |
| 153 | + resolveMultiFactorSignIn: wrapped => { |
| 154 | + void wrapped.resolveMultiFactorSignIn('session', 'verification-id', '123456'); |
| 155 | + }, |
| 156 | + resolveTotpSignIn: wrapped => { |
| 157 | + void wrapped.resolveTotpSignIn('session', 'uid', '123456'); |
| 158 | + }, |
| 159 | + generateTotpSecret: wrapped => { |
| 160 | + void wrapped.generateTotpSecret('session'); |
| 161 | + }, |
| 162 | + generateQrCodeUrl: wrapped => { |
| 163 | + void wrapped.generateQrCodeUrl('secret', 'account', 'issuer'); |
| 164 | + }, |
| 165 | + openInOtpApp: wrapped => { |
| 166 | + wrapped.openInOtpApp('secret', 'otpauth://totp/example'); |
| 167 | + }, |
| 168 | + finalizeMultiFactorEnrollment: wrapped => { |
| 169 | + void wrapped.finalizeMultiFactorEnrollment('verification-id', '123456', 'Device'); |
| 170 | + }, |
| 171 | + finalizeTotpEnrollment: wrapped => { |
| 172 | + void wrapped.finalizeTotpEnrollment('secret', '123456', 'Device'); |
| 173 | + }, |
| 174 | + confirmationResultConfirm: wrapped => { |
| 175 | + void wrapped.confirmationResultConfirm('123456'); |
| 176 | + }, |
| 177 | + verifyPhoneNumber: wrapped => { |
| 178 | + wrapped.verifyPhoneNumber('+15555550100', 'request-key', 60, true); |
| 179 | + }, |
| 180 | + confirmPasswordReset: wrapped => { |
| 181 | + void wrapped.confirmPasswordReset('code', 'new-password'); |
| 182 | + }, |
| 183 | + linkWithCredential: wrapped => { |
| 184 | + void wrapped.linkWithCredential('google.com', 'token', 'secret'); |
| 185 | + }, |
| 186 | + linkWithProvider: wrapped => { |
| 187 | + void wrapped.linkWithProvider({ providerId: 'google.com' }); |
| 188 | + }, |
| 189 | + reauthenticateWithCredential: wrapped => { |
| 190 | + void wrapped.reauthenticateWithCredential('google.com', 'token', 'secret'); |
| 191 | + }, |
| 192 | + reauthenticateWithProvider: wrapped => { |
| 193 | + void wrapped.reauthenticateWithProvider({ providerId: 'google.com' }); |
| 194 | + }, |
| 195 | + setTenantId: wrapped => { |
| 196 | + void wrapped.setTenantId('tenant-id'); |
| 197 | + }, |
| 198 | + useEmulator: wrapped => { |
| 199 | + wrapped.useEmulator('localhost', 9099); |
| 200 | + }, |
| 201 | + forceRecaptchaFlowForTesting: wrapped => { |
| 202 | + void wrapped.forceRecaptchaFlowForTesting(true); |
| 203 | + }, |
| 204 | + setAutoRetrievedSmsCodeForPhoneNumber: wrapped => { |
| 205 | + void wrapped.setAutoRetrievedSmsCodeForPhoneNumber('+15555550100', '123456'); |
| 206 | + }, |
| 207 | + setAppVerificationDisabledForTesting: wrapped => { |
| 208 | + void wrapped.setAppVerificationDisabledForTesting(true); |
| 209 | + }, |
| 210 | + useUserAccessGroup: wrapped => { |
| 211 | + void wrapped.useUserAccessGroup('group.example'); |
| 212 | + }, |
| 213 | + }, |
| 214 | + ); |
| 215 | + }); |
| 216 | +}); |
0 commit comments