Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Muncy committed May 5, 2023
1 parent 763ad43 commit 13606f8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ interface Pin {
}

let globalPinFunction: Pin = defaultPin;
const globalIpfsClient = IPFS.create();
let globalIpfsClient = IPFS.create();

interface SetupOptions {
pin?: Pin
pin?: Pin,
ipfsClient: IPFS.IPFSHTTPClient
}

function setup(options: SetupOptions) {
if(options.ipfsClient)
globalIpfsClient = options.ipfsClient
if(options.pin)
globalPinFunction = options.pin;
}
Expand Down
13 changes: 11 additions & 2 deletions test/prepare.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, test } from "mocha";
import { assert } from "sinon";
import { optionalSetup } from "../src/ipfs-http-client-setup.js";
import { setup } from "../src/setup";
import { prepare } from '../src/main';
import { ipfs } from './mocks';
import fetch, { Headers, Request, Response } from "node-fetch";
Expand All @@ -15,7 +15,16 @@ if (!globalThis.fetch) {
describe('prepare', () => {

before(() => {
optionalSetup(ipfs() as any);
setup({
ipfsClient: ipfs() as any,
pin: async (content) => {
console.log(content)
return {
cid: "ipfs://bafy",
pinned: true
}
}
});
});

test("should prepare the test", async () => {
Expand Down
6 changes: 4 additions & 2 deletions test/resolve.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, test } from "mocha";
import { assert } from "sinon";
import { optionalSetup } from "../src/ipfs-http-client-setup.js";
import { setup } from "../src/setup";
import { resolve } from '../src/main';
import { ipfs } from './mocks';
import fetch, { Headers, Request, Response } from "node-fetch";
Expand All @@ -15,7 +15,9 @@ if (!globalThis.fetch) {
describe('resolve', () => {

before(() => {
optionalSetup(ipfs() as any);
setup({
ipfsClient:ipfs() as any
});
});

test("Should resolve to value", async () => {
Expand Down

0 comments on commit 13606f8

Please sign in to comment.