From bfe46a8e132276bb089ec9bcaf644df656fb7a37 Mon Sep 17 00:00:00 2001 From: Joseph Earl Date: Wed, 12 Apr 2017 22:58:23 +0100 Subject: [PATCH] Fixes #324 Use branch name from config when creating PR --- package.json | 4 +- src/backends/github/API.js | 3 +- src/backends/github/__tests__/API.spec.js | 39 + .../EntryEditorToolbar.spec.js.snap | 6 +- .../MarkupItReactRenderer.spec.js.snap | 20 +- yarn.lock | 885 +++++++----------- 6 files changed, 419 insertions(+), 538 deletions(-) create mode 100644 src/backends/github/__tests__/API.spec.js diff --git a/package.json b/package.json index 04f76bc1..0f2bc367 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,8 @@ "file-loader": "^0.8.5", "identity-obj-proxy": "^3.0.0", "imports-loader": "^0.6.5", - "jest-cli": "^16.0.1", + "jest": "19.1.0-alpha.eed82034", + "jest-cli": "19.1.0-alpha.eed82034", "lint-staged": "^3.1.0", "node-sass": "^3.10.0", "npm-check": "^5.2.3", @@ -101,7 +102,6 @@ "history": "^2.1.2", "immutability-helper": "^2.0.0", "immutable": "^3.7.6", - "jest": "^17.0.0", "js-base64": "^2.1.9", "js-yaml": "^3.7.0", "json-loader": "^0.5.4", diff --git a/src/backends/github/API.js b/src/backends/github/API.js index ef7765bf..4bd8ddda 100644 --- a/src/backends/github/API.js +++ b/src/backends/github/API.js @@ -393,7 +393,7 @@ export default class API { return this.deleteRef("heads", branchName); } - createPR(title, head, base = "master") { + createPR(title, head, base = this.branch) { const body = "Automatically generated by Netlify CMS"; return this.request(`${ this.repoURL }/pulls`, { method: "POST", @@ -518,5 +518,4 @@ export default class API { body: JSON.stringify({ message, tree, parents }), }); } - } diff --git a/src/backends/github/__tests__/API.spec.js b/src/backends/github/__tests__/API.spec.js new file mode 100644 index 00000000..ba665961 --- /dev/null +++ b/src/backends/github/__tests__/API.spec.js @@ -0,0 +1,39 @@ +import AssetProxy from "../../../valueObjects/AssetProxy"; +import API from "../API"; + +describe('github API', () => { + const mockAPI = (api, responses) => { + api.request = (path, options = {}) => { + const normalizedPath = path.indexOf('?') !== -1 ? path.substr(0, path.indexOf('?')) : path; + const response = responses[normalizedPath]; + return typeof response === 'function' + ? Promise.resolve(response(options)) + : Promise.reject(new Error(`No response for path '${normalizedPath}'`)) + }; + } + + it('should create PR with correct base branch name when publishing with editorial workflow', () => { + let prBaseBranch = null; + const api = new API({ branch: 'gh-pages', repo: 'my-repo' }); + const responses = { + '/repos/my-repo/branches/gh-pages': () => ({ commit: { sha: 'def' } }), + '/repos/my-repo/git/trees/def': () => ({ tree: [] }), + '/repos/my-repo/git/trees': () => ({}), + '/repos/my-repo/git/commits': () => ({}), + '/repos/my-repo/git/refs': () => ({}), + '/repos/my-repo/pulls': (pullRequest) => { + prBaseBranch = JSON.parse(pullRequest.body).base; + return { head: { sha: 'cbd' } }; + }, + '/user': () => ({}), + '/repos/my-repo/git/blobs': () => ({}), + '/repos/my-repo/git/refs/meta/_netlify_cms': () => ({ 'object': {} }) + }; + mockAPI(api, responses); + + return expect( + api.editorialWorkflowGit(null, { slug: 'entry', sha: 'abc' }, null, {}) + .then(() => prBaseBranch) + ).resolves.toEqual('gh-pages') + }); +}); diff --git a/src/components/EntryEditor/__tests__/__snapshots__/EntryEditorToolbar.spec.js.snap b/src/components/EntryEditor/__tests__/__snapshots__/EntryEditorToolbar.spec.js.snap index 801382be..f51fe48a 100644 --- a/src/components/EntryEditor/__tests__/__snapshots__/EntryEditorToolbar.spec.js.snap +++ b/src/components/EntryEditor/__tests__/__snapshots__/EntryEditorToolbar.spec.js.snap @@ -1,3 +1,5 @@ -exports[`EntryEditorToolbar should disable and update label of Save button when persisting 1`] = `"
"`; +// Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`EntryEditorToolbar should have both buttons enabled initially 1`] = `"
"`; +exports[`EntryEditorToolbar should disable and update label of Save button when persisting 1`] = `"
"`; + +exports[`EntryEditorToolbar should have both buttons enabled initially 1`] = `"
"`; diff --git a/src/components/MarkupItReactRenderer/__tests__/__snapshots__/MarkupItReactRenderer.spec.js.snap b/src/components/MarkupItReactRenderer/__tests__/__snapshots__/MarkupItReactRenderer.spec.js.snap index 87212581..1495c18c 100644 --- a/src/components/MarkupItReactRenderer/__tests__/__snapshots__/MarkupItReactRenderer.spec.js.snap +++ b/src/components/MarkupItReactRenderer/__tests__/__snapshots__/MarkupItReactRenderer.spec.js.snap @@ -1,23 +1,25 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + exports[`MarkitupReactRenderer HTML rendering should render HTML 1`] = `"

Paragraph with inline element

"`; exports[`MarkitupReactRenderer Markdown rendering Code should render code 1`] = `"

Use the printf() function.

"`; exports[`MarkitupReactRenderer Markdown rendering Code should render code 2 1`] = `"

There is a literal backtick (\`) here.

"`; -exports[`MarkitupReactRenderer Markdown rendering General should render markdown 1`] = `"

H1

Text with bold & em elements

H2

H3

  1. ol item 1
  2. ol item 2
  3. ol item 3

H4

link title

H5

\"alt

H6
"`; +exports[`MarkitupReactRenderer Markdown rendering General should render markdown 1`] = `"

H1

Text with bold & em elements

H2

H3

  1. ol item 1
  2. ol item 2
  3. ol item 3

H4

link title

H5

\\"alt

H6
"`; exports[`MarkitupReactRenderer Markdown rendering HTML should render HTML as is when using Markdown 1`] = ` -"

Title

-