1import { vol } from 'memfs'; 2import path from 'path'; 3 4import { 5 getGoogleServicesFile, 6 getGoogleSignInReservedClientId, 7 setGoogleSignInReservedClientId, 8} from '../Google'; 9import { appendScheme } from '../Scheme'; 10 11jest.mock('fs'); 12jest.mock('../Scheme'); 13 14const originalFs = jest.requireActual('fs'); 15 16describe('ios google config', () => { 17 const projectRoot = '/testproject'; 18 19 afterEach(() => vol.reset()); 20 21 it(`returns null from all getters if no value provided`, () => { 22 expect(getGoogleSignInReservedClientId({}, { projectRoot: null })).toBe(null); 23 expect(getGoogleServicesFile({})).toBe(null); 24 }); 25 26 it(`returns the correct values from all getters if a value is provided`, () => { 27 expect( 28 getGoogleSignInReservedClientId( 29 { 30 ios: { config: { googleSignIn: { reservedClientId: '000' } } }, 31 }, 32 { projectRoot: null } 33 ) 34 ).toBe('000'); 35 expect( 36 getGoogleServicesFile({ ios: { googleServicesFile: './path/to/GoogleService-Info.plist' } }) 37 ).toBe('./path/to/GoogleService-Info.plist'); 38 }); 39 40 it(`adds the reserved client id to scheme if provided`, () => { 41 vol.fromJSON( 42 { 43 'path/to/GoogleService-Info.plist': originalFs.readFileSync( 44 path.join(__dirname, 'fixtures/GoogleService-Info.plist'), 45 'utf-8' 46 ), 47 }, 48 projectRoot 49 ); 50 51 const infoPlist = {}; 52 setGoogleSignInReservedClientId( 53 { 54 ios: { 55 config: { googleSignIn: { reservedClientId: 'client-id-scheme' } }, 56 googleServicesFile: './path/to/GoogleService-Info.plist', 57 }, 58 }, 59 infoPlist, 60 { projectRoot } 61 ); 62 63 expect(appendScheme).toHaveBeenCalledWith('client-id-scheme', infoPlist); 64 }); 65 66 it(`adds the reserved client id to scheme from GoogleService-Info.Plist`, () => { 67 vol.fromJSON( 68 { 69 'path/to/GoogleService-Info.plist': originalFs.readFileSync( 70 path.join(__dirname, 'fixtures/GoogleService-Info.plist'), 71 'utf-8' 72 ), 73 }, 74 projectRoot 75 ); 76 77 const infoPlist = {}; 78 setGoogleSignInReservedClientId( 79 { 80 ios: { googleServicesFile: './path/to/GoogleService-Info.plist' }, 81 }, 82 infoPlist, 83 { projectRoot } 84 ); 85 86 expect(appendScheme).toHaveBeenCalledWith( 87 'com.googleusercontent.apps.1234567890123-abcdef', 88 infoPlist 89 ); 90 }); 91}); 92