Skip to content

Commit

Permalink
test: re-activate more tests and convert them to typescript (#457)
Browse files Browse the repository at this point in the history
Closes #414
  • Loading branch information
Uzlopak authored Jul 18, 2024
1 parent 93d5afb commit 5a4eeb6
Show file tree
Hide file tree
Showing 29 changed files with 185 additions and 2,072 deletions.
83 changes: 0 additions & 83 deletions test/integration/agent-ca/agent-ca-test.js

This file was deleted.

13 changes: 6 additions & 7 deletions test/integration/apps-test.js → test/integration/apps.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
const nock = require("nock");
import { describe, beforeEach, it } from "vitest";
import nock from "nock";
import { Octokit } from "../../src/index.ts";

const { Octokit } = require("../../");
const BEARER_TOKEN =
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1NTM4MTkzMTIsImV4cCI6MTU1MzgxOTM3MiwiaXNzIjoxfQ.etiSZ4LFQZ8tiMGJVqKDoGn8hxMCgwL4iLvU5xBUqbAPr4pbk_jJZmMQjuxTlOnRxq4e7NouTizGCdfohRMb3R1mpLzGPzOH9_jqSA_BWYxolsRP_WDSjuNcw6nSxrPRueMVRBKFHrqcTOZJej0djRB5pI61hDZJ_-DGtiOIFexlK3iuVKaqBkvJS5-TbTekGuipJ652g06gXuz-l8i0nHiFJldcuIruwn28hTUrjgtPbjHdSBVn_QQLKc2Fhij8OrhcGqp_D_fvb_KovVmf1X6yWiwXV5VXqWARS-JGD9JTAr2495ZlLV_E4WPxdDpz1jl6XS9HUhMuwBpaCOuipw";

describe("apps", () => {
let octokit;
let octokit: Octokit;

beforeEach(() => {
octokit = new Octokit({
baseUrl: "https://apps-test-host.com",
auth: `Bearer ${BEARER_TOKEN}`,
log: console.log,
});
});

it('adds "machine-man" preview header', () => {
nock("https://apps-test-host.com", {
reqheaders: {
authorization: `bearer ${BEARER_TOKEN}`,
accept: "application/vnd.github.machine-man-preview+json",
accept: "application/vnd.github.v3+json",
},
})
.get("/app")
Expand All @@ -32,8 +32,7 @@ describe("apps", () => {
nock("https://apps-test-host.com", {
reqheaders: {
authorization: `bearer ${BEARER_TOKEN}`,
accept:
"application/vnd.github.machine-man-preview+json,application/vnd.github.foo-bar-preview+json",
accept: "application/vnd.github.v3+json",
},
})
.get("/app")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const lolex = require("lolex");
const nock = require("nock");
const { createAppAuth } = require("@octokit/auth-app");
const { createActionAuth } = require("@octokit/auth-action");
import { describe, it, expect, vi } from "vitest";
import nock from "nock";
import { createAppAuth } from "@octokit/auth-app";
import { createActionAuth } from "@octokit/auth-action";

const { Octokit } = require("../..");
import { Octokit } from "../../src/index.ts";

describe("authentication", () => {
it("unauthenticated", () => {
Expand Down Expand Up @@ -69,6 +69,9 @@ describe("authentication", () => {
baseUrl: "https://authentication-test-host.com",
auth: "token abc4567",
log: {
error() {},
debug() {},
info() {},
warn() {},
},
});
Expand Down Expand Up @@ -119,7 +122,15 @@ describe("authentication", () => {

it("invalid auth errors", () => {
expect(() => {
Octokit({ auth: {}, log: { warn() {} } });
new Octokit({
auth: {},
log: {
error() {},
debug() {},
info() {},
warn() {},
},
});
}).to.throw(Error);
});

Expand Down Expand Up @@ -203,22 +214,22 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
.get("/")
.reply(200, {});

const clock = lolex.install({
const clock = vi.useFakeTimers({
now: 0,
toFake: ["Date"],
});

const octokit = new Octokit({
authStrategy: createAppAuth,
auth: {
id: APP_ID,
appId: APP_ID,
privateKey: PRIVATE_KEY,
installationId: 123,
},
});

return octokit.request("/").then(() => {
clock.uninstall();
clock.useRealTimers();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const nock = require("nock");

const { Octokit } = require("../../");
import { describe, beforeEach, it, expect } from "vitest";
import nock from "nock";
import { Octokit } from "../../src/index.ts";

describe("request 304s", () => {
let octokit;
let octokit: Octokit;

beforeEach(() => {
octokit = new Octokit({
Expand All @@ -16,7 +16,7 @@ describe("request 304s", () => {

return octokit.rest.orgs
.get({ org: "myorg", headers: { "If-None-Match": "etag" } })
.then((response) => {
.then(() => {
expect.fail("should throw error");
})
.catch((error) => {
Expand All @@ -34,7 +34,7 @@ describe("request 304s", () => {
"If-Modified-Since": "Sun Dec 24 2017 22:00:00 GMT-0600 (CST)",
},
})
.then((response) => {
.then(() => {
expect.fail("should throw error");
})
.catch((error) => {
Expand Down
Loading

0 comments on commit 5a4eeb6

Please sign in to comment.