• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evolvedbinary / prosemirror-lwdita / d2499a42-427e-45b3-98eb-04591d5522bd

12 Sep 2024 09:50AM UTC coverage: 62.123% (+1.7%) from 60.443%
d2499a42-427e-45b3-98eb-04591d5522bd

push

circleci

marmoure
[test] test creating PR from contributions

189 of 374 branches covered (50.53%)

Branch coverage included in aggregate %.

35 of 36 new or added lines in 1 file covered. (97.22%)

677 of 1020 relevant lines covered (66.37%)

20.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.03
/packages/prosemirror-lwdita/src/tests/github.plugin.spec.ts
1
/*!
2
Copyright (C) 2020 Evolved Binary
3

4
This program is free software: you can redistribute it and/or modify
5
it under the terms of the GNU Affero General Public License as
6
published by the Free Software Foundation, either version 3 of the
7
License, or (at your option) any later version.
8

9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
GNU Affero General Public License for more details.
13

14
You should have received a copy of the GNU Affero General Public License
15
along with this program.  If not, see <https://www.gnu.org/licenses/>.
16
*/
17

18
import { expect } from 'chai';
1✔
19
import { createPrFromContribution, fetchRawDocumentFromGitHub, transformGitHubDocumentToProsemirrorJson } from '../github.plugin';
1✔
20
import fetchMock from 'fetch-mock';
1✔
21
import { shortXdita, shortXditaProsemirroJson } from './test-utils';
1✔
22

23
describe('fetchRawDocumentFromGitHub', () => {
1✔
24
  afterEach(() => {
1✔
25
    fetchMock.restore();
2✔
26
  });
27

28
  it('should fetch the raw content of a document from a GitHub repository', async () => {
1✔
29
    const ghrepo = 'evolvedbinary/prosemirror-lwdita';
1✔
30
    const source = 'packages/prosemirror-lwdita-demo/example-xdita/02-short-file.xml';
1✔
31
    const mockResponse = '<xml>Mock Content</xml>';
1✔
32
    // this will mock the next fetch request
33
    fetchMock.getOnce(`https://raw.githubusercontent.com/${ghrepo}/main/${source}`, {
1✔
34
      body: mockResponse,
35
      headers: { 'Content-Type': 'text/plain' },
36
    });
37

38
    const result = await fetchRawDocumentFromGitHub(ghrepo, source);
1✔
39
    expect(result).to.equal(mockResponse);
1✔
40
  });
41

42
  it('should handle errors when fetching the document', async () => {
1✔
43
    const ghrepo = 'evolvedbinary/prosemirror-lwdita';
1✔
44
    const source = 'packages/prosemirror-lwdita-demo/example-xdita/02-short-file.xml';
1✔
45
    // this will mock the next fetch request
46
    fetchMock.getOnce(`https://raw.githubusercontent.com/${ghrepo}/main/${source}`, 404);
1✔
47

48
    try {
1✔
49
      await fetchRawDocumentFromGitHub(ghrepo, source);
1✔
50
      throw new Error('Expected fetchRawDocumentFromGitHub to throw an error');
1✔
51
    } catch (error) {
52
      expect(error).to.be.instanceOf(Error);
1✔
53
    }
54
  });
55
});
56

57
describe('transformGitHubDocumentToProsemirrorJson', () => {
1✔
58
  it('should transform a raw GitHub document into a ProseMirror state save', async () => {
1✔
59
    const mockXdita = shortXdita;
1✔
60
    
61
    const prosemirrorJson = await transformGitHubDocumentToProsemirrorJson(mockXdita)
1✔
62

63
    const mockJson = shortXditaProsemirroJson;
1✔
64
    expect(prosemirrorJson).to.deep.equal(mockJson)
1✔
65
  });
66
});
67

68
describe('createPrFromContribution', () => {
1✔
69
  beforeEach(() => {
1✔
70
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
71
    const window = global as any;
1✔
72
    Object.defineProperty(window, 'localStorage', { 
1✔
73
      value: {
74
        getItem: () => 'mock-token',
1✔
75
      },
76
    });
77
  });
78

79
  afterEach(() => {
1✔
80
    fetchMock.restore();
1✔
81
  });
82

83
  it('should create a pull request from a contribution', async () => {
1✔
84
    const ghrepo = 'evolvedbinary/prosemirror-lwdita';
1✔
85
    const source = 'packages/prosemirror-lwdita-demo/example-xdita/02-short-file.xml';
1✔
86
    const changedDocument = '<xml>Changed Content</xml>';
1✔
87
    const token = 'mock-token';
1✔
88

89
    // Mock fetch request
90
    fetchMock.postOnce('/api/github/integration', {
1✔
91
      status: 200
92
    });
93

94
    await createPrFromContribution(ghrepo, source, changedDocument);
1✔
95

96
    const lastCall = fetchMock.lastCall('/api/github/integration') as fetchMock.MockCall;
1✔
97
    if (!lastCall) {
1!
NEW
98
      throw new Error('No fetch call found for /api/github/integration');
×
99
    }
100
    const [url, options] = lastCall;
1✔
101
    if(options) {
1✔
102
      if(!options.headers) return;
1!
103
      if(!options.body) return;
1!
104
      expect(url).to.equal('/api/github/integration');
1✔
105
      expect(options.method).to.equal('POST');
1✔
106

107
      // @ts-expect-error TS7053 happens because the headers are not typed
108
      expect(options.headers['Content-Type']).to.equal('application/json'); 
1✔
109
      // @ts-expect-error TS7053 happens because the headers are not typed
110
      expect(options.headers['Authorization']).to.equal(`Bearer ${token}`); 
1✔
111
      const body = JSON.parse(options.body as string);
1✔
112
      expect(body.owner).to.equal('evolvedbinary');
1✔
113
      expect(body.repo).to.equal('prosemirror-lwdita');
1✔
114
      expect(body.newOwner).to.equal('marmoure');
1✔
115
      expect(body.newBranch).to.equal('new-branch');
1✔
116
      expect(body.commitMessage).to.equal('Update the document');
1✔
117
      expect(body.change.path).to.equal(source);
1✔
118
      expect(body.change.content).to.equal(changedDocument);
1✔
119
      expect(body.title).to.equal('Update the document');
1✔
120
      expect(body.body).to.equal('Update the document ------------------ This is an automated PR made by the prosemirror-lwdita demo');
1✔
121
    }
122
  });
123
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc