aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/modules/datasource/orb/index.spec.ts
blob: 1cb1e8519d4ac56a118092933e10ff737ddeaf6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { getPkgReleases } from '..';
import * as httpMock from '../../../../test/http-mock';
import { OrbDatasource } from '.';

const orbData = {
  data: {
    orb: {
      name: 'hutson/library-release-workflows',
      homeUrl: '',
      versions: [
        { version: '4.2.0', createdAt: '2018-12-13T23:19:09.356Z' },
        { version: '4.1.6', createdAt: '2018-12-12T18:56:42.563Z' },
        { version: '4.1.5', createdAt: '2018-12-12T17:13:31.542Z' },
        { version: '4.1.4', createdAt: '2018-12-11T22:13:29.297Z' },
        { version: '4.1.3', createdAt: '2018-12-11T21:40:44.870Z' },
        { version: '4.1.2', createdAt: '2018-12-11T21:28:37.846Z' },
        { version: '4.1.1' },
        { version: '4.1.0', createdAt: '2018-12-11T18:14:41.116Z' },
        { version: '4.0.0', createdAt: '2018-12-11T17:41:26.595Z' },
        { version: '3.0.0', createdAt: '2018-12-11T05:28:14.080Z' },
      ],
    },
  },
};

const baseUrl = 'https://circleci.com';

const datasource = OrbDatasource.id;

describe('modules/datasource/orb/index', () => {
  describe('getReleases', () => {
    it('returns null for empty result', async () => {
      httpMock.scope(baseUrl).post('/graphql-unstable').reply(200, {});
      expect(
        await getPkgReleases({
          datasource,
          packageName: 'hyper-expanse/library-release-workflows',
        }),
      ).toBeNull();
    });

    it('returns null for missing orb', async () => {
      httpMock
        .scope(baseUrl)
        .post('/graphql-unstable')
        .reply(200, { data: {} });
      expect(
        await getPkgReleases({
          datasource,
          packageName: 'hyper-expanse/library-release-wonkflows',
        }),
      ).toBeNull();
    });

    it('returns null for 404', async () => {
      httpMock.scope(baseUrl).post('/graphql-unstable').reply(404);
      expect(
        await getPkgReleases({
          datasource,
          packageName: 'hyper-expanse/library-release-workflows',
        }),
      ).toBeNull();
    });

    it('returns null for unknown error', async () => {
      httpMock.scope(baseUrl).post('/graphql-unstable').replyWithError('');
      expect(
        await getPkgReleases({
          datasource,
          packageName: 'hyper-expanse/library-release-workflows',
        }),
      ).toBeNull();
    });

    it('processes real data', async () => {
      httpMock.scope(baseUrl).post('/graphql-unstable').reply(200, orbData);
      const res = await getPkgReleases({
        datasource,
        packageName: 'hyper-expanse/library-release-workflows',
      });
      expect(res).toMatchSnapshot();
      expect(res).not.toBeNull();
    });

    it('processes homeUrl', async () => {
      orbData.data.orb.homeUrl = 'https://google.com';
      httpMock.scope(baseUrl).post('/graphql-unstable').reply(200, orbData);
      const res = await getPkgReleases({
        datasource,
        packageName: 'hyper-expanse/library-release-workflows',
      });
      expect(res).toMatchSnapshot();
      expect(res?.homepage).toBe('https://google.com');
    });

    it('supports other registries', async () => {
      httpMock
        .scope('https://cci.internal.dev')
        .post('/graphql-unstable')
        .reply(200, orbData);
      const res = await getPkgReleases({
        datasource,
        packageName: 'hyper-expanse/library-release-workflows',
        registryUrls: ['https://cci.internal.dev'],
      });
      expect(res?.registryUrl).toBe('https://cci.internal.dev');
    });
  });
});