1import { isInteractive } from '../../utils/interactive';
2import { openBrowserAsync } from '../../utils/open';
3import { registerAsync } from '../registerAsync';
4
5jest.mock('../../utils/open');
6jest.mock('../../utils/interactive', () => ({
7  isInteractive: jest.fn(() => true),
8}));
9
10const originalEnv = process.env;
11beforeEach(() => {
12  delete process.env.EXPO_OFFLINE;
13  delete process.env.CI;
14});
15
16afterAll(() => {
17  process.env = originalEnv;
18});
19
20it(`asserts that registration is not supported in offline-mode`, async () => {
21  process.env.EXPO_OFFLINE = '1';
22  await expect(registerAsync()).rejects.toThrowErrorMatchingInlineSnapshot(
23    `"Cannot register an account in offline-mode"`
24  );
25  expect(openBrowserAsync).not.toBeCalled();
26});
27
28it(`asserts that registration is not supported in non-interactive environments`, async () => {
29  jest.mocked(isInteractive).mockReturnValueOnce(false);
30
31  await expect(registerAsync()).rejects.toThrow(
32    expect.objectContaining({
33      name: 'CommandError',
34      message: expect.stringContaining('Cannot register an account in CI.'),
35    })
36  );
37
38  expect(openBrowserAsync).not.toBeCalled();
39});
40
41it(`launches a registration window`, async () => {
42  jest.mocked(isInteractive).mockReturnValueOnce(true);
43
44  await registerAsync();
45
46  expect(openBrowserAsync).toBeCalledWith('https://expo.dev/signup');
47});
48