-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #396 from dreamit-de/395-fetch-recog
#395 Add fetch failed as FetchError. Add tests
- Loading branch information
Showing
3 changed files
with
31 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
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
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,29 @@ | ||
/* eslint-disable unicorn/error-message */ | ||
import { FETCH_ERROR, GRAPHQL_ERROR } from '@dreamit/graphql-server-base' | ||
import { determineGraphQLOrFetchError } from 'src' | ||
import { expect, test } from 'vitest' | ||
|
||
const redirectedErrorMessage = | ||
'uri requested responds with a redirect, redirect mode is set to error' | ||
|
||
test.each` | ||
errorMessage | expectedErrorName | ||
${'ECONNREFUSED'} | ${FETCH_ERROR} | ||
${'ECONNRESET'} | ${FETCH_ERROR} | ||
${'ETIMEDOUT'} | ${FETCH_ERROR} | ||
${'network timeout'} | ${FETCH_ERROR} | ||
${'invalid redirect URL'} | ${FETCH_ERROR} | ||
${redirectedErrorMessage} | ${FETCH_ERROR} | ||
${'maximum redirect reached'} | ${FETCH_ERROR} | ||
${'Cannot follow redirect'} | ${FETCH_ERROR} | ||
${'socket hang up'} | ${FETCH_ERROR} | ||
${'fetch failed'} | ${FETCH_ERROR} | ||
${'I am a GraphQLError'} | ${GRAPHQL_ERROR} | ||
`( | ||
'Correctly determine if error $errorMessage is a GraphQLError or FetchError $expectedErrorName', | ||
({ errorMessage, expectedErrorName }) => { | ||
expect(determineGraphQLOrFetchError(new Error(errorMessage))).toBe( | ||
expectedErrorName, | ||
) | ||
}, | ||
) |