fix(tests): make mocks for rest octokit async
This commit is contained in:
@@ -185,7 +185,7 @@ function quit(reason) {
|
|||||||
//Test token validity and requests count
|
//Test token validity and requests count
|
||||||
else if (!/^NOT_NEEDED$/.test(token)) {
|
else if (!/^NOT_NEEDED$/.test(token)) {
|
||||||
//Check rate limit
|
//Check rate limit
|
||||||
const {data} = await api.rest.request("GET /rate_limit", {}).catch(() => ({data:{resources:{}}}))
|
const {data} = await api.rest.rateLimit.get().catch(() => ({data:{resources:{}}}))
|
||||||
Object.assign(resources, data.resources)
|
Object.assign(resources, data.resources)
|
||||||
info("API requests (REST)", resources.core ? `${resources.core.remaining}/${resources.core.limit}` : "(unknown)")
|
info("API requests (REST)", resources.core ? `${resources.core.remaining}/${resources.core.limit}` : "(unknown)")
|
||||||
info("API requests (GraphQL)", resources.graphql ? `${resources.graphql.remaining}/${resources.graphql.limit}` : "(unknown)")
|
info("API requests (GraphQL)", resources.graphql ? `${resources.graphql.remaining}/${resources.graphql.limit}` : "(unknown)")
|
||||||
@@ -600,7 +600,7 @@ function quit(reason) {
|
|||||||
info.break()
|
info.break()
|
||||||
info.section("Consumed API requests")
|
info.section("Consumed API requests")
|
||||||
info(" * provided that no other app used your quota during execution", "")
|
info(" * provided that no other app used your quota during execution", "")
|
||||||
const {data:current} = await rest.request("GET /rate_limit", {}).catch(() => ({data:{resources:{}}}))
|
const {data:current} = await rest.rateLimit.get().catch(() => ({data:{resources:{}}}))
|
||||||
for (const type of ["core", "graphql", "search"]) {
|
for (const type of ["core", "graphql", "search"]) {
|
||||||
const used = resources[type].remaining - current.resources[type].remaining
|
const used = resources[type].remaining - current.resources[type].remaining
|
||||||
info({core:"REST API", graphql:"GraphQL API", search:"Search API"}[type], (Number.isFinite(used)&&(used >= 0)) ? used : "(unknown)")
|
info({core:"REST API", graphql:"GraphQL API", search:"Search API"}[type], (Number.isFinite(used)&&(used >= 0)) ? used : "(unknown)")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**Mocked data */
|
/**Mocked data */
|
||||||
export default function({ faker }, target, that, [{ username: login, page, per_page }]) {
|
export default async function({ faker }, target, that, [{ username: login, page, per_page }]) {
|
||||||
console.debug("metrics/compute/mocks > mocking rest api result > rest.activity.listEventsForAuthenticatedUser")
|
console.debug("metrics/compute/mocks > mocking rest api result > rest.activity.listEventsForAuthenticatedUser")
|
||||||
return ({
|
return ({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import listEventsForAuthenticatedUser from "./listEventsForAuthenticatedUser.mjs"
|
import listEventsForAuthenticatedUser from "./listEventsForAuthenticatedUser.mjs"
|
||||||
|
|
||||||
/**Mocked data */
|
/**Mocked data */
|
||||||
export default function({ faker }, target, that, [{ username: login, page, per_page }]) {
|
export default async function({ faker }, target, that, [{ username: login, page, per_page }]) {
|
||||||
console.debug("metrics/compute/mocks > mocking rest api result > rest.activity.listRepoEvents")
|
console.debug("metrics/compute/mocks > mocking rest api result > rest.activity.listRepoEvents")
|
||||||
return listEventsForAuthenticatedUser(...arguments)
|
return listEventsForAuthenticatedUser(...arguments)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**Mocked data */
|
/**Mocked data */
|
||||||
export default function({ faker }, target, that) {
|
export default async function({ faker }, target, that) {
|
||||||
console.debug("metrics/compute/mocks > mocking rest api result > rest.emojis.get")
|
console.debug("metrics/compute/mocks > mocking rest api result > rest.emojis.get")
|
||||||
return ({
|
return ({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**Mocked data */
|
/**Mocked data */
|
||||||
export default function({ faker }, target, that, args) {
|
export default async function({ faker }, target, that, args) {
|
||||||
return ({
|
return ({
|
||||||
status: 200,
|
status: 200,
|
||||||
url: "https://api.github.com/rate_limit",
|
url: "https://api.github.com/rate_limit",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**Mocked data */
|
/**Mocked data */
|
||||||
export default function({ faker }, target, that, [{ owner, repo }]) {
|
export default async function({ faker }, target, that, [{ owner, repo }]) {
|
||||||
console.debug("metrics/compute/mocks > mocking rest api result > rest.repos.getContributorsStats")
|
console.debug("metrics/compute/mocks > mocking rest api result > rest.repos.getContributorsStats")
|
||||||
return ({
|
return ({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**Mocked data */
|
/**Mocked data */
|
||||||
export default function({ faker }, target, that, [{ owner, repo }]) {
|
export default async function({ faker }, target, that, [{ owner, repo }]) {
|
||||||
console.debug("metrics/compute/mocks > mocking rest api result > rest.repos.getViews")
|
console.debug("metrics/compute/mocks > mocking rest api result > rest.repos.getViews")
|
||||||
const count = faker.datatype.number(10000) * 2
|
const count = faker.datatype.number(10000) * 2
|
||||||
const uniques = faker.datatype.number(count) * 2
|
const uniques = faker.datatype.number(count) * 2
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**Mocked data */
|
/**Mocked data */
|
||||||
export default function({ faker }, target, that, [{ page, per_page, owner, repo }]) {
|
export default async function({ faker }, target, that, [{ page, per_page, owner, repo }]) {
|
||||||
console.debug("metrics/compute/mocks > mocking rest api result > rest.repos.listCommits")
|
console.debug("metrics/compute/mocks > mocking rest api result > rest.repos.listCommits")
|
||||||
return ({
|
return ({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**Mocked data */
|
/**Mocked data */
|
||||||
export default function({ faker }, target, that, [{ owner, repo }]) {
|
export default async function({ faker }, target, that, [{ owner, repo }]) {
|
||||||
console.debug("metrics/compute/mocks > mocking rest api result > rest.repos.listContributors")
|
console.debug("metrics/compute/mocks > mocking rest api result > rest.repos.listContributors")
|
||||||
return ({
|
return ({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**Mocked data */
|
/**Mocked data */
|
||||||
export default function({ faker }, target, that, args) {
|
export default async function({ faker }, target, that, args) {
|
||||||
//Arguments
|
//Arguments
|
||||||
const [url] = args
|
const [url] = args
|
||||||
//Head request
|
//Head request
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**Mocked data */
|
/**Mocked data */
|
||||||
export default function({ faker }, target, that, [{ username }]) {
|
export default async function({ faker }, target, that, [{ username }]) {
|
||||||
console.debug("metrics/compute/mocks > mocking rest api result > rest.repos.getByUsername")
|
console.debug("metrics/compute/mocks > mocking rest api result > rest.repos.getByUsername")
|
||||||
return ({
|
return ({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**Mocked data */
|
/**Mocked data */
|
||||||
export default function({ faker }, target, that, [{ username }]) {
|
export default async function({ faker }, target, that, [{ username }]) {
|
||||||
console.debug("metrics/compute/mocks > mocking rest api result > rest.users.listGpgKeysForUser")
|
console.debug("metrics/compute/mocks > mocking rest api result > rest.users.listGpgKeysForUser")
|
||||||
return ({
|
return ({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
Reference in New Issue
Block a user