-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix support of relative urls in
createJsonQuery
and `createJsonMuta…
…tion`
- Loading branch information
1 parent
56db427
commit df94492
Showing
3 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@farfetched/core": patch | ||
--- | ||
|
||
Fix support of relative urls in `createJsonQuery` and `createJsonMutation` |
54 changes: 54 additions & 0 deletions
54
packages/core/src/__tests__/relative_urls_in_jsdom.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* @vitest-environment jsdom | ||
*/ | ||
import { describe, test, expect } from 'vitest'; | ||
import { allSettled, fork } from 'effector'; | ||
|
||
import { createJsonQuery } from '../query/create_json_query'; | ||
import { unknownContract } from '../contract/unknown_contract'; | ||
import { fetchFx } from '../fetch/fetch'; | ||
|
||
describe('relative paths in createJsonQuery, issue #493', () => { | ||
test('does not throw error for valid relative path', async () => { | ||
const query = createJsonQuery({ | ||
request: { url: '/api', method: 'GET' }, | ||
response: { contract: unknownContract }, | ||
}); | ||
|
||
const scope = fork({ | ||
// We have to to mock fetchFx, because URL validation embed in createJsonQuery.__.executeFx | ||
handlers: [[fetchFx, () => new Response(JSON.stringify('DATA'))]], | ||
}); | ||
|
||
await allSettled(query.start, { scope }); | ||
|
||
expect(scope.getState(query.$error)).toBe(null); | ||
expect(scope.getState(query.$data)).toBe('DATA'); | ||
}); | ||
|
||
test('does throw error for invalid relative path', async () => { | ||
const query = createJsonQuery({ | ||
request: { url: 'api **** jkjj', method: 'GET' }, | ||
response: { contract: unknownContract }, | ||
}); | ||
|
||
const scope = fork({ | ||
// We have to to mock fetchFx, because URL validation embed in createJsonQuery.__.executeFx | ||
handlers: [[fetchFx, () => new Response(JSON.stringify('DATA'))]], | ||
}); | ||
|
||
await allSettled(query.start, { scope }); | ||
|
||
expect(scope.getState(query.$error)).toMatchInlineSnapshot(` | ||
{ | ||
"errorType": "CONFIGURATION", | ||
"explanation": "Operation is misconfigured", | ||
"reason": "Invalid URL", | ||
"validationErrors": [ | ||
""api **** jkjj" is not valid URL", | ||
], | ||
} | ||
`); | ||
expect(scope.getState(query.$data)).toBe(null); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters