1import nock from 'nock';
2
3import { getExpoApiBaseUrl } from '../../../api/endpoint';
4import * as ProjectDevices from '../../project/devices';
5import { DevelopmentSession } from '../DevelopmentSession';
6
7const asMock = (fn: any): jest.Mock => fn as jest.Mock;
8
9jest.mock('../../../api/settings', () => ({
10  APISettings: {
11    isOffline: false,
12  },
13}));
14jest.mock('../../project/devices', () => ({
15  getDevicesInfoAsync: jest.fn(),
16}));
17jest.mock('../../../api/user/user');
18
19describe(`startAsync`, () => {
20  it(`starts a dev session`, async () => {
21    const session = new DevelopmentSession('/', 'http://localhost:19001/');
22
23    asMock(ProjectDevices.getDevicesInfoAsync).mockResolvedValue({
24      devices: [{ installationId: '123' }, { installationId: '456' }],
25    });
26
27    const exp = {
28      name: 'my-app',
29      slug: 'my-app',
30      description: 'my-foo-bar',
31      primaryColor: '#4630eb',
32    };
33    const runtime = 'native';
34    const scope = nock(getExpoApiBaseUrl())
35      .post('/v2/development-sessions/notify-alive?deviceId=123&deviceId=456')
36      .reply(200, '');
37
38    await session.startAsync({
39      exp,
40      runtime,
41    });
42    session.stop();
43    expect(ProjectDevices.getDevicesInfoAsync).toHaveBeenCalledTimes(1);
44    expect(scope.isDone()).toBe(true);
45  });
46});
47