-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
There was a problem hiding this 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", |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = {}; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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.
There was a problem hiding this 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"; |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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.
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.