-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2593569
commit 0295fd0
Showing
9 changed files
with
3,518 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Octokit as Core } from "@octokit/core"; | ||
import { RequestError } from "@octokit/request-error"; | ||
|
||
import { createPullRequest } from "../src"; | ||
const Octokit = Core.plugin(createPullRequest); | ||
|
||
test("labels without error", async () => { | ||
const fixtures = require("./fixtures/labels-with-error"); | ||
const fixturePr = fixtures[fixtures.length - 2].response; | ||
const octokit = new Octokit(); | ||
|
||
octokit.hook.wrap("request", (_, options) => { | ||
const currentFixtures = fixtures.shift(); | ||
const { | ||
baseUrl, | ||
method, | ||
url, | ||
request, | ||
headers, | ||
mediaType, | ||
draft, | ||
...params | ||
} = options; | ||
|
||
expect( | ||
`${currentFixtures.request.method} ${currentFixtures.request.url}` | ||
).toEqual(`${options.method} ${options.url}`); | ||
|
||
Object.keys(params).forEach((paramName) => { | ||
expect(currentFixtures.request[paramName]).toStrictEqual( | ||
params[paramName] | ||
); | ||
}); | ||
|
||
if (currentFixtures.response.status >= 400) { | ||
throw new RequestError("Error", currentFixtures.response.status, { | ||
request: currentFixtures.request, | ||
headers: currentFixtures.response.headers, | ||
}); | ||
} | ||
|
||
return currentFixtures.response; | ||
}); | ||
|
||
expect(async () => { | ||
return octokit.createPullRequest({ | ||
owner: "gr2m", | ||
repo: "pull-request-test", | ||
title: "One comes, one goes", | ||
body: "because", | ||
labels: ["enhancement", "help wanted"], | ||
head: "with-labels", | ||
changes: { | ||
files: { | ||
"path/to/file1.txt": "Content for file1", | ||
"path/to/file2.txt": "Content for file2", | ||
}, | ||
commit: "why", | ||
}, | ||
}); | ||
}).rejects.toThrow(new Error("Error")); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Octokit as Core } from "@octokit/core"; | ||
import { RequestError } from "@octokit/request-error"; | ||
|
||
import { createPullRequest } from "../src"; | ||
const Octokit = Core.plugin(createPullRequest); | ||
|
||
test("labels without permissions", async () => { | ||
const fixtures = require("./fixtures/labels-without-permissions"); | ||
const fixturePr = fixtures[fixtures.length - 2].response; | ||
const octokit = new Octokit(); | ||
|
||
octokit.hook.wrap("request", (_, options) => { | ||
const currentFixtures = fixtures.shift(); | ||
const { | ||
baseUrl, | ||
method, | ||
url, | ||
request, | ||
headers, | ||
mediaType, | ||
draft, | ||
...params | ||
} = options; | ||
|
||
expect( | ||
`${currentFixtures.request.method} ${currentFixtures.request.url}` | ||
).toEqual(`${options.method} ${options.url}`); | ||
|
||
Object.keys(params).forEach((paramName) => { | ||
expect(currentFixtures.request[paramName]).toStrictEqual( | ||
params[paramName] | ||
); | ||
}); | ||
|
||
if (currentFixtures.response.status >= 400) { | ||
throw new RequestError("Error", currentFixtures.response.status, { | ||
request: currentFixtures.request, | ||
headers: currentFixtures.response.headers, | ||
}); | ||
} | ||
|
||
return currentFixtures.response; | ||
}); | ||
|
||
const pr = await octokit.createPullRequest({ | ||
owner: "gr2m", | ||
repo: "pull-request-test", | ||
title: "One comes, one goes", | ||
body: "because", | ||
labels: ["enhancement", "help wanted"], | ||
head: "with-labels", | ||
changes: { | ||
files: { | ||
"path/to/file1.txt": "Content for file1", | ||
"path/to/file2.txt": "Content for file2", | ||
}, | ||
commit: "why", | ||
}, | ||
}); | ||
|
||
expect(pr).toStrictEqual(fixturePr); | ||
expect(fixtures.length).toEqual(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Octokit as Core } from "@octokit/core"; | ||
import { RequestError } from "@octokit/request-error"; | ||
|
||
import { createPullRequest } from "../src"; | ||
const Octokit = Core.plugin(createPullRequest); | ||
|
||
test("labels", async () => { | ||
const fixtures = require("./fixtures/labels"); | ||
const fixturePr = fixtures[fixtures.length - 2].response; | ||
const octokit = new Octokit(); | ||
|
||
octokit.hook.wrap("request", (_, options) => { | ||
const currentFixtures = fixtures.shift(); | ||
const { | ||
baseUrl, | ||
method, | ||
url, | ||
request, | ||
headers, | ||
mediaType, | ||
draft, | ||
...params | ||
} = options; | ||
|
||
expect( | ||
`${currentFixtures.request.method} ${currentFixtures.request.url}` | ||
).toEqual(`${options.method} ${options.url}`); | ||
|
||
Object.keys(params).forEach((paramName) => { | ||
expect(currentFixtures.request[paramName]).toStrictEqual( | ||
params[paramName] | ||
); | ||
}); | ||
|
||
if (currentFixtures.response.status >= 400) { | ||
throw new RequestError("Error", currentFixtures.response.status, { | ||
request: currentFixtures.request, | ||
headers: currentFixtures.response.headers, | ||
}); | ||
} | ||
|
||
return currentFixtures.response; | ||
}); | ||
|
||
const pr = await octokit.createPullRequest({ | ||
owner: "gr2m", | ||
repo: "pull-request-test", | ||
title: "One comes, one goes", | ||
body: "because", | ||
labels: ["enhancement", "help wanted"], | ||
head: "with-labels", | ||
changes: { | ||
files: { | ||
"path/to/file1.txt": "Content for file1", | ||
"path/to/file2.txt": "Content for file2", | ||
}, | ||
commit: "why", | ||
}, | ||
}); | ||
|
||
expect(pr).toStrictEqual(fixturePr); | ||
expect(fixtures.length).toEqual(0); | ||
}); |