1import nock from 'nock';
2
3import { getExpoApiBaseUrl } from '../endpoint';
4import {
5  updateDevelopmentSessionAsync,
6  closeDevelopmentSessionAsync,
7} from '../updateDevelopmentSession';
8
9describe(updateDevelopmentSessionAsync, () => {
10  it('update development session', async () => {
11    const scope = nock(getExpoApiBaseUrl())
12      .post('/v2/development-sessions/notify-alive?deviceId=123')
13      .reply(200, require('./fixtures/native-modules/44.0.0.json'));
14    await updateDevelopmentSessionAsync({
15      deviceIds: ['123'],
16      exp: {
17        name: 'Test',
18        description: 'Test',
19        slug: 'test',
20        primaryColor: '#ffffff',
21      },
22      runtime: 'native',
23      url: 'exp://192.168.1.69:19001',
24    });
25
26    expect(scope.isDone()).toBe(true);
27  });
28  it('fails when the servers are down', async () => {
29    const scope = nock(getExpoApiBaseUrl())
30      .post('/v2/development-sessions/notify-alive?deviceId=123')
31      .reply(500, 'something went wrong');
32    await expect(
33      updateDevelopmentSessionAsync({
34        deviceIds: ['123'],
35        exp: {
36          name: 'Test',
37          description: 'Test',
38          slug: 'test',
39          primaryColor: '#ffffff',
40        },
41        runtime: 'native',
42        url: 'exp://192.168.1.69:19001',
43      })
44    ).rejects.toThrowError(/Expo server/);
45    expect(scope.isDone()).toBe(true);
46  });
47});
48
49describe(closeDevelopmentSessionAsync, () => {
50  it('close development session', async () => {
51    const scope = nock(getExpoApiBaseUrl())
52      .post('/v2/development-sessions/notify-close?deviceId=123')
53      .reply(200, {
54        data: {
55          deleted: [
56            {
57              username: 'fiberjw',
58              session: {
59                description: 'Goodweebs on Juwans-MacBook-Pro.local',
60                source: 'desktop',
61                url: 'exp://192.168.1.69:19001',
62              },
63            },
64          ],
65        },
66      });
67    await closeDevelopmentSessionAsync({
68      deviceIds: ['123'],
69      url: 'exp://192.168.1.69:19001',
70    });
71
72    expect(scope.isDone()).toBe(true);
73  });
74  it('fails when the servers are down', async () => {
75    const scope = nock(getExpoApiBaseUrl())
76      .post('/v2/development-sessions/notify-close?deviceId=123')
77      .reply(500, 'something went wrong');
78    await expect(
79      closeDevelopmentSessionAsync({
80        deviceIds: ['123'],
81        url: 'exp://192.168.1.69:19001',
82      })
83    ).rejects.toThrowError(/Expo server/);
84    expect(scope.isDone()).toBe(true);
85  });
86});
87