1import nock from 'nock';
2
3import { getExpoApiBaseUrl } from '../endpoint';
4import { getNativeModuleVersionsAsync } from '../getNativeModuleVersions';
5
6beforeAll(() => {
7  process.env.EXPO_NO_CACHE = 'true';
8});
9
10describe(getNativeModuleVersionsAsync, () => {
11  it('gets versions', async () => {
12    const scope = nock(getExpoApiBaseUrl())
13      .get('/v2/sdks/44.0.0/native-modules')
14      .reply(200, require('./fixtures/native-modules/44.0.0.json'));
15    const versions = await getNativeModuleVersionsAsync('44.0.0');
16
17    expect(Object.keys(versions).length).toBeGreaterThan(4);
18
19    for (const [key, value] of Object.entries(versions)) {
20      expect(key).toEqual(expect.any(String));
21      expect(value).toEqual(expect.any(String));
22    }
23
24    expect(scope.isDone()).toBe(true);
25  });
26  it('fails when the servers are down', async () => {
27    const scope = nock(getExpoApiBaseUrl())
28      .get('/v2/sdks/44.0.0/native-modules')
29      .reply(500, 'something went wrong');
30    await expect(getNativeModuleVersionsAsync('44.0.0')).rejects.toThrowError(/Expo server/);
31    expect(scope.isDone()).toBe(true);
32  });
33});
34