Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup full test coverage #72

Merged
merged 5 commits into from
May 26, 2023
Merged

Setup full test coverage #72

merged 5 commits into from
May 26, 2023

Conversation

joewagner
Copy link
Contributor

@joewagner joewagner commented May 26, 2023

Fixes #70

I had to do a little bit of refactoring to enable testing the ipfs pinning, and the ipfs mock package will need to merge and publish a PR I opened before these will pass, but this gets us full coverage.

@joewagner joewagner changed the base branch from main to staging May 26, 2023 18:34
Copy link
Contributor Author

@joewagner joewagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready for review. I know it's the end of the day, so no worries if you can get to this till next week.

"eslint-config-prettier": "^8.8.0",
"eslint-config-standard": "^17.0.0",
"mocha": "^10.0.0",
"mockipfs": "npm:@joewagner/mockipfs@^0.3.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an open PR to get these changes into the official package, but until then I published a version that works.

export {
pinToLocal,
pinToProvider,
Pinner,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see an easy way to enable passing the ipfs connection details to the pinning processor, so I abstracted it into a class that get instantiated with the connection details.
This is the majority of the refactoring i ended up doing.

Pinner,
type FileContent,
} from "./processors/pinContentToIpfs.js";
export { default as truncate } from "./processors/truncate.js";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed process to processors for consistency in avoiding potential collisions with the reserved word.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, thought I already did it. Ty sir.

const resolvedRow: RowObject = {};
const resultsRequests = resultSet.map(async (row: RowObject) => {
// needs to be `any` since the resolver is being plugged into this package
const resolvedRow: any = {};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests were not working with the typescript compiler because this type was [key: string]: string | number; and different processors return different types than string | number

export class Pinner {
ipfsOptions: IPFS.Options;
ipfs: IPFS.IPFSHTTPClient;
where: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of refactoring here, but I believe i preserved all the existing logic.
This is worth a solid read through.

}

// TODO: why are we using the first value?
return pinningServices[0];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a todo comment here because I'm not really sure what the implications of 2 remote services existing are. Regardless, this preserves the existing logic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure either. Perhaps we should loop through and pin to all, since a huge purpose for IPFS is to decentralize. Or pin to all by default and make any option? Don't need to change now, but worth thinking about.

localPinner.pin.bind(localPinner),
localPinner.resolveCid.bind(localPinner)
);
// TODO: Allow passing in the provider's endpoint.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This TODO was already here, I just moved it during the refactor.

import { describe, test } from "mocha";
import { assert } from "sinon";
import { createProcessor, symetricEncrypt } from "../src/main";
import fetch, { Headers, Request, Response } from "node-fetch";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed node-fetch since the versions of node we are using for tests done need it anymore.

@joewagner joewagner marked this pull request as ready for review May 26, 2023 19:31
Copy link
Contributor

@awmuncy awmuncy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! A couple of functional improvements we can make, but not related to your changes. I think we can split those into a different PR and get this test coverage merged.

Pinner,
type FileContent,
} from "./processors/pinContentToIpfs.js";
export { default as truncate } from "./processors/truncate.js";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, thought I already did it. Ty sir.

}

// TODO: why are we using the first value?
return pinningServices[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure either. Perhaps we should loop through and pin to all, since a huge purpose for IPFS is to decentralize. Or pin to all by default and make any option? Don't need to change now, but worth thinking about.

@joewagner joewagner merged commit bb13289 into staging May 26, 2023
@joewagner joewagner deleted the joe/tests branch May 26, 2023 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[JET-11] Add full coverage testing
2 participants