1*8c301ce0SWill Schurmanimport { mkdirSync } from 'fs'; 2*8c301ce0SWill Schurman 3*8c301ce0SWill Schurmanimport { getAccountUsername } from '../getAccountUsername'; 4*8c301ce0SWill Schurmanimport { getExpoHomeDirectory, getUserState } from '../getUserState'; 5*8c301ce0SWill Schurman 6*8c301ce0SWill Schurmanjest.mock('os'); 7*8c301ce0SWill Schurmanjest.mock('fs'); 8*8c301ce0SWill Schurman 9*8c301ce0SWill Schurmandescribe(getAccountUsername, () => { 10*8c301ce0SWill Schurman beforeEach(() => { 11*8c301ce0SWill Schurman delete process.env.EXPO_CLI_USERNAME; 12*8c301ce0SWill Schurman delete process.env.EAS_BUILD_USERNAME; 13*8c301ce0SWill Schurman }); 14*8c301ce0SWill Schurman 15*8c301ce0SWill Schurman it(`gets the account name from EXPO_CLI_USERNAME`, () => { 16*8c301ce0SWill Schurman process.env.EXPO_CLI_USERNAME = 'expo-cli-username'; 17*8c301ce0SWill Schurman process.env.EAS_BUILD_USERNAME = 'eas-build-username'; 18*8c301ce0SWill Schurman expect(getAccountUsername()).toBe('expo-cli-username'); 19*8c301ce0SWill Schurman }); 20*8c301ce0SWill Schurman it(`gets the account name from EAS_BUILD_USERNAME`, () => { 21*8c301ce0SWill Schurman process.env.EAS_BUILD_USERNAME = 'eas-build-username'; 22*8c301ce0SWill Schurman expect(getAccountUsername()).toBe('eas-build-username'); 23*8c301ce0SWill Schurman }); 24*8c301ce0SWill Schurman it(`gets the account name from owner`, () => { 25*8c301ce0SWill Schurman process.env.EXPO_CLI_USERNAME = 'expo-cli-username'; 26*8c301ce0SWill Schurman process.env.EAS_BUILD_USERNAME = 'eas-build-username'; 27*8c301ce0SWill Schurman expect(getAccountUsername({ owner: 'owner-username' })).toBe('owner-username'); 28*8c301ce0SWill Schurman }); 29*8c301ce0SWill Schurman it(`gets the account name from owner 2`, () => { 30*8c301ce0SWill Schurman expect(getAccountUsername({ owner: 'owner-username' })).toBe('owner-username'); 31*8c301ce0SWill Schurman }); 32*8c301ce0SWill Schurman it(`uses anonymous name`, () => { 33*8c301ce0SWill Schurman // Ensure the test doesn't interact with the developer's state.json 34*8c301ce0SWill Schurman expect(getExpoHomeDirectory()).toBe('/home/.expo'); 35*8c301ce0SWill Schurman expect(getAccountUsername()).toBe('anonymous'); 36*8c301ce0SWill Schurman }); 37*8c301ce0SWill Schurman it(`uses previously authenticated username`, async () => { 38*8c301ce0SWill Schurman // Ensure the test doesn't interact with the developer's state.json 39*8c301ce0SWill Schurman expect(getExpoHomeDirectory()).toBe('/home/.expo'); 40*8c301ce0SWill Schurman // Ensure the dir exists 41*8c301ce0SWill Schurman await mkdirSync(getExpoHomeDirectory(), { recursive: true }); 42*8c301ce0SWill Schurman // Set a username... 43*8c301ce0SWill Schurman await getUserState().setAsync('auth', { username: 'bacon-boi' }); 44*8c301ce0SWill Schurman // Check the username... 45*8c301ce0SWill Schurman expect(getAccountUsername()).toBe('bacon-boi'); 46*8c301ce0SWill Schurman }); 47*8c301ce0SWill Schurman}); 48