/
integration.js
99 lines (88 loc) · 2.85 KB
/
integration.js
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
import { Octokit } from '@octokit/core'; // eslint-disable-line import/no-extraneous-dependencies
import { paginateGraphql } from '@octokit/plugin-paginate-graphql';
import { graphql, HttpResponse } from 'msw'; // https://mswjs.io/docs/getting-started/mocks/graphql-api
import { setupServer } from 'msw/node'; // https://mswjs.io/docs/getting-started/integrate/node
import { ApiWrapper } from '../apiwrapper';
import { RepositoryProjectsManager } from '../projects.js'; // eslint-disable-line import/extensions
const GraphQlOctokit = Octokit.plugin(paginateGraphql);
const octokit = new GraphQlOctokit({ auth: 'fake-token-value' }); // don't use default GITHUB_TOKEN token from env
const apiWrapper = new ApiWrapper({ octokit });
const rpm = new RepositoryProjectsManager({ apiWrapper, ownerName: 'acme', repositoryName: 'example-repository' });
const server = setupServer(); // MSW mock server
describe('RepositoryProjectsManager integration test', () => {
beforeAll(() => {
server.listen();
});
beforeEach(() => {
server.use(
graphql.query(/fetchOrgainzation/, () => HttpResponse.json({
data: {
organization: {
id: 'O_0000000001',
name: 'ACME Corporation',
},
},
})),
graphql.query(/paginate/, () => HttpResponse.json({
data: {
repository: {
name: 'example-repository',
id: 'R_0000000001',
projectsV2: {
nodes: [
{
id: 'PVT_kwDOAnsQgs4AP9Qq',
title: 'layer-200/module-1',
},
{
id: 'PVT_000000000000002',
title: 'layer-100/module-2',
},
],
pageInfo: {
hasNextPage: false,
endCursor: 'Nw',
},
},
},
},
})),
graphql.query(/paginate/, () => HttpResponse.json({
data: {
repository: {
name: 'example-repository',
id: 'R_0000000001',
projectsV2: {
nodes: [
{
id: 'PVT_kwDOAnsQgs4AP9Qq',
title: 'layer-200/module-1',
},
{
id: 'PVT_000000000000002',
title: 'layer-100/module-2',
},
],
pageInfo: {
hasNextPage: false,
endCursor: 'Nw',
},
},
},
},
})),
);
});
afterAll(() => {
server.close();
});
test('when no change is required', async () => {
const titles = [
'layer-200/module-1',
'layer-100/module-2',
];
await rpm.sync(titles);
const outputTitles = rpm.projects().map((p) => p.title);
expect(outputTitles).toEqual(titles);
});
});