1import { vol } from 'memfs'; 2import path from 'path'; 3 4import { 5 getGoogleServicesFile, 6 getGoogleSignInReversedClientId, 7 setGoogleSignInReversedClientId, 8} from '../Google'; 9import { appendScheme } from '../Scheme'; 10 11jest.mock('fs'); 12jest.mock('../Scheme', () => ({ 13 appendScheme: jest.fn((...props) => jest.requireActual('../Scheme').appendScheme(...props)), 14})); 15 16const googleServicesFixture = jest 17 .requireActual('fs') 18 .readFileSync(path.join(__dirname, 'fixtures/GoogleService-Info.plist'), 'utf-8'); 19 20describe(getGoogleSignInReversedClientId, () => { 21 afterEach(() => vol.reset()); 22 it(`returns null when no file is defined`, () => { 23 expect(getGoogleSignInReversedClientId({}, { projectRoot: '' })).toBe(null); 24 expect(getGoogleServicesFile({})).toBe(null); 25 }); 26 it(`returns the REVERSED_CLIENT_ID from the linked file`, () => { 27 vol.fromJSON( 28 { 29 'path/to/GoogleService-Info.plist': googleServicesFixture, 30 }, 31 '/' 32 ); 33 34 const config = { 35 ios: { googleServicesFile: './path/to/GoogleService-Info.plist' }, 36 }; 37 38 expect(getGoogleServicesFile(config)).toBe('./path/to/GoogleService-Info.plist'); 39 expect(getGoogleSignInReversedClientId(config, { projectRoot: '/' })).toBe( 40 'com.googleusercontent.apps.1234567890123-abcdef' 41 ); 42 }); 43}); 44 45describe(setGoogleSignInReversedClientId, () => { 46 afterEach(() => vol.reset()); 47 48 it(`adds the reversed client id to scheme from GoogleService-Info.Plist`, () => { 49 vol.fromJSON( 50 { 51 'path/to/GoogleService-Info.plist': googleServicesFixture, 52 }, 53 '/' 54 ); 55 56 expect( 57 setGoogleSignInReversedClientId( 58 { 59 ios: { googleServicesFile: './path/to/GoogleService-Info.plist' }, 60 }, 61 {}, 62 { projectRoot: '/' } 63 ) 64 ).toEqual({ 65 CFBundleURLTypes: [ 66 { CFBundleURLSchemes: ['com.googleusercontent.apps.1234567890123-abcdef'] }, 67 ], 68 }); 69 70 expect(appendScheme).toHaveBeenCalledWith( 71 'com.googleusercontent.apps.1234567890123-abcdef', 72 {} 73 ); 74 }); 75}); 76