2019-11-28 05:39:33 +02:00
|
|
|
import GraphQLAPI from '../GraphQLAPI';
|
|
|
|
|
|
|
|
global.fetch = jest.fn().mockRejectedValue(new Error('should not call fetch inside tests'));
|
|
|
|
|
|
|
|
describe('github GraphQL API', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('editorialWorkflowGit', () => {
|
|
|
|
it('should should flatten nested tree into a list of files', () => {
|
2020-02-24 23:44:10 +01:00
|
|
|
const api = new GraphQLAPI({ branch: 'gh-pages', repo: 'owner/my-repo' });
|
2019-11-28 05:39:33 +02:00
|
|
|
const entries = [
|
|
|
|
{
|
|
|
|
name: 'post-1.md',
|
|
|
|
sha: 'sha-1',
|
|
|
|
type: 'blob',
|
|
|
|
blob: { size: 1 },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'post-2.md',
|
|
|
|
sha: 'sha-2',
|
|
|
|
type: 'blob',
|
|
|
|
blob: { size: 2 },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '2019',
|
|
|
|
sha: 'dir-sha',
|
|
|
|
type: 'tree',
|
|
|
|
object: {
|
|
|
|
entries: [
|
|
|
|
{
|
|
|
|
name: 'nested-post.md',
|
|
|
|
sha: 'nested-post-sha',
|
|
|
|
type: 'blob',
|
|
|
|
blob: { size: 3 },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const path = 'posts';
|
|
|
|
|
|
|
|
expect(api.getAllFiles(entries, path)).toEqual([
|
|
|
|
{
|
|
|
|
name: 'post-1.md',
|
2020-01-15 00:15:14 +02:00
|
|
|
id: 'sha-1',
|
2019-11-28 05:39:33 +02:00
|
|
|
type: 'blob',
|
|
|
|
size: 1,
|
|
|
|
path: 'posts/post-1.md',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'post-2.md',
|
2020-01-15 00:15:14 +02:00
|
|
|
id: 'sha-2',
|
2019-11-28 05:39:33 +02:00
|
|
|
type: 'blob',
|
|
|
|
size: 2,
|
|
|
|
path: 'posts/post-2.md',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'nested-post.md',
|
2020-01-15 00:15:14 +02:00
|
|
|
id: 'nested-post-sha',
|
2019-11-28 05:39:33 +02:00
|
|
|
type: 'blob',
|
|
|
|
size: 3,
|
|
|
|
path: 'posts/2019/nested-post.md',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|