1*e377ff85SWill Schurmanimport nock from 'nock';
2*e377ff85SWill Schurman
3*e377ff85SWill Schurmanimport { getExpoApiBaseUrl } from '../endpoint';
4*e377ff85SWill Schurmanimport { getProjectDevelopmentCertificateAsync } from '../getProjectDevelopmentCertificate';
5*e377ff85SWill Schurman
6*e377ff85SWill Schurmanjest.mock('../user/actions', () => ({
7*e377ff85SWill Schurman  ensureLoggedInAsync: jest.fn(),
8*e377ff85SWill Schurman}));
9*e377ff85SWill Schurman
10*e377ff85SWill SchurmanbeforeAll(() => {
11*e377ff85SWill Schurman  process.env.EXPO_NO_CACHE = 'true';
12*e377ff85SWill Schurman});
13*e377ff85SWill Schurman
14*e377ff85SWill Schurmandescribe(getProjectDevelopmentCertificateAsync, () => {
15*e377ff85SWill Schurman  it('gets project development certificate', async () => {
16*e377ff85SWill Schurman    const scope = nock(getExpoApiBaseUrl())
17*e377ff85SWill Schurman      .post('/v2/projects/4254c843-457a-4a6e-9b21-1506dc175ba4/development-certificates')
18*e377ff85SWill Schurman      .reply(200, 'hello');
19*e377ff85SWill Schurman    const cert = await getProjectDevelopmentCertificateAsync(
20*e377ff85SWill Schurman      '4254c843-457a-4a6e-9b21-1506dc175ba4',
21*e377ff85SWill Schurman      'csr'
22*e377ff85SWill Schurman    );
23*e377ff85SWill Schurman    expect(cert).toBe('hello');
24*e377ff85SWill Schurman    expect(scope.isDone()).toBe(true);
25*e377ff85SWill Schurman  });
26*e377ff85SWill Schurman  it('fails when the servers are down', async () => {
27*e377ff85SWill Schurman    const scope = nock(getExpoApiBaseUrl())
28*e377ff85SWill Schurman      .post('/v2/projects/123/development-certificates')
29*e377ff85SWill Schurman      .reply(500, 'something went wrong');
30*e377ff85SWill Schurman    await expect(getProjectDevelopmentCertificateAsync('123', 'csr')).rejects.toThrowError(
31*e377ff85SWill Schurman      /Expo server/
32*e377ff85SWill Schurman    );
33*e377ff85SWill Schurman    expect(scope.isDone()).toBe(true);
34*e377ff85SWill Schurman  });
35*e377ff85SWill Schurman});
36