-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(common/utils/catch-spotify-error): fix coverage
- Loading branch information
Showing
2 changed files
with
46 additions
and
19 deletions.
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 |
---|---|---|
@@ -1,53 +1,78 @@ | ||
import { test, describe, expect } from 'vitest' | ||
import { BadGatewayException, UnauthorizedException } from '@nestjs/common' | ||
|
||
import { catchSpotifyError } from './catch-spotify-error' | ||
import { | ||
SPOTIFY_DEFAULT_ERROR_MESSAGE, | ||
SpotifyAuthError, | ||
catchSpotifyError, | ||
} from './catch-spotify-error' | ||
|
||
import { axiosResponseMockFactory } from '@common/mocks' | ||
|
||
describe('catchSpotifyError', () => { | ||
test('should throw UnauthorizedException', () => { | ||
const message = 'Unauthorized' | ||
|
||
expect(() => | ||
catchSpotifyError( | ||
axiosResponseMockFactory( | ||
{ | ||
error: { | ||
message: 'Unauthorized', | ||
message, | ||
status: 401, | ||
}, | ||
}, | ||
401 | ||
) | ||
) | ||
).toThrowError(UnauthorizedException) | ||
).toThrowError(new UnauthorizedException(message)) | ||
}) | ||
|
||
test('should throw UnauthorizedException as invalid grant', () => { | ||
const message = 'Invalid token' | ||
|
||
expect(() => | ||
catchSpotifyError( | ||
axiosResponseMockFactory( | ||
{ | ||
error: { | ||
message: 'invalid_grant', | ||
status: 401, | ||
}, | ||
error: 'invalid_grant', | ||
error_description: message, | ||
}, | ||
401 | ||
) | ||
) | ||
).toThrowError(UnauthorizedException) | ||
).toThrowError(new UnauthorizedException(message)) | ||
}) | ||
|
||
test('should throw InternalServerErrorException', () => { | ||
test('should throw BadGatewayException', () => { | ||
const message = 'Bad Gateway' | ||
|
||
expect(() => | ||
catchSpotifyError( | ||
axiosResponseMockFactory({ | ||
error: { | ||
message: 'Bad Gateway', | ||
status: 500, | ||
message, | ||
status: 502, | ||
}, | ||
}) | ||
) | ||
).toThrowError(BadGatewayException) | ||
).toThrowError( | ||
new BadGatewayException(SPOTIFY_DEFAULT_ERROR_MESSAGE + message) | ||
) | ||
}) | ||
|
||
test('should throw BadGatewayException', () => { | ||
const message = 'Bad Gateway' | ||
|
||
expect(() => | ||
catchSpotifyError( | ||
axiosResponseMockFactory<SpotifyAuthError>({ | ||
error: message, | ||
error_description: message, | ||
}) | ||
) | ||
).toThrowError( | ||
new BadGatewayException(SPOTIFY_DEFAULT_ERROR_MESSAGE + message) | ||
) | ||
}) | ||
}) |
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