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