-
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.
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 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
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,42 @@ | ||
import { test } from 'zinnia:test' | ||
import { AssertionError, assertStringIncludes, assertRejects } from 'zinnia:assert' | ||
import { assertRedirectResponse } from '../lib/http-assertions.js' | ||
|
||
test('assertRedirectResponse - 302', async () => { | ||
const responseMock = { | ||
status: 302, | ||
headers: new Headers({ location: '/new-location' }), | ||
async text () { | ||
throw new AssertionError('res.text() should not have been called') | ||
} | ||
} | ||
|
||
await assertRedirectResponse(responseMock) | ||
}) | ||
|
||
test('assertRedirectResponse - mission Location header', async () => { | ||
const responseMock = { | ||
status: 302, | ||
headers: new Headers(), | ||
async text () { | ||
throw new AssertionError('res.text() should not have been called') | ||
} | ||
} | ||
|
||
const err = await assertRejects(() => assertRedirectResponse(responseMock)) | ||
assertStringIncludes(err.message, 'Location') | ||
}) | ||
|
||
test('assertRedirectResponse - not redirect', async () => { | ||
const responseMock = { | ||
status: 200, | ||
headers: new Headers(), | ||
async text () { | ||
return 'RESPONSE BODY' | ||
} | ||
} | ||
|
||
const err = await assertRejects(() => assertRedirectResponse(responseMock, 'NOT REDIRECT')) | ||
assertStringIncludes(err.message, 'NOT REDIRECT') | ||
assertStringIncludes(err.message, 'RESPONSE BODY') | ||
}) |