-
Notifications
You must be signed in to change notification settings - Fork 35
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
fix: EventResult should await OK response #299
fix: EventResult should await OK response #299
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #299 +/- ##
==========================================
+ Coverage 83.63% 83.64% +0.01%
==========================================
Files 48 48
Lines 4235 4238 +3
Branches 1055 1055
==========================================
+ Hits 3542 3545 +3
Misses 663 663
Partials 30 30 ☔ View full report in Codecov by Sentry. |
LGTM, although, it would be nice to implement a test case that verifies this. For example by setting up a unit test with a fetch call that will return a rejected promise.
Currently, it believe the library will NOT throw for non-OK responses. This test will not pass: it('Should throw HTTP if fetch resolves with non-JSON', async () => {
client.fetch.mockResolvedValue(
new Response('Not JSON', { status: 500 })
);
await expect(
client
.identifiers()
.create('aid1', { bran: '0123456789abcdefghijk' })
).rejects.toThrow('Fail');
}); This is because the library does not check the HTTP status code. It will not fail until we try to read the message body as JSON, which we do in |
@lenkan I'd argue this is now covered by the typing. But sure, I can add a test in case a regression happens on the types. |
@lenkan I didn't quite get your example. The call will throw an error if the response is e.g. 400 before checking https://github.com/WebOfTrust/signify-ts/blob/main/src/keri/app/clienting.ts#L206-L215
|
Ah yes, sorry. I saw that and was just about to write a comment about this. I was mistaken. I thought it didn't, but that is because the |
Let me know if you want to add anything more, otherwise I can merge it. |
@lenkan Thanks, I added the first test for completeness. Nothing else to add now from my side. |
In places, we were still passing a
Promise<Response>
toEventResult
. This is problematic because if a non 2xx code is returned as the fetch call will reject after the function has returned.