|
1 | 1 | import { describe, it, run } from 'https://deno.land/x/wizard/mod.ts'
|
2 | 2 | import { InitAppAndTest } from '../util.ts'
|
3 |
| -import { setHeader } from '../../extensions/res/mod.ts' |
| 3 | +import { setHeader, getResponseHeader, setVaryHeader, redirect } from '../../extensions/res/mod.ts' |
4 | 4 |
|
5 | 5 | describe('res.set(field, val)', () => {
|
6 | 6 | it('should set a string header with a string value', async () => {
|
@@ -48,4 +48,53 @@ describe('res.set(field, val)', () => {
|
48 | 48 | })
|
49 | 49 | })
|
50 | 50 |
|
| 51 | +describe('res.get(field)', () => { |
| 52 | + it('should get a header with a specified field', async () => { |
| 53 | + const { fetch } = InitAppAndTest((_, res) => { |
| 54 | + setHeader(res)('hello', 'World') |
| 55 | + res.end(getResponseHeader(res)('hello')) |
| 56 | + }) |
| 57 | + |
| 58 | + await fetch.get('/').expect('World') |
| 59 | + }) |
| 60 | +}) |
| 61 | + |
| 62 | +describe('res.vary(field)', () => { |
| 63 | + it('should set a "Vary" header properly', async () => { |
| 64 | + const { fetch } = InitAppAndTest((_, res) => { |
| 65 | + setVaryHeader(res)('User-Agent').end() |
| 66 | + }) |
| 67 | + |
| 68 | + await fetch.get('/').expect('Vary', 'User-Agent') |
| 69 | + }) |
| 70 | +}) |
| 71 | + |
| 72 | +describe('res.redirect(url, status)', () => { |
| 73 | + it('should set 302 status and message about redirecting', async () => { |
| 74 | + const { fetch } = InitAppAndTest((req, res) => { |
| 75 | + redirect(req, res, () => {})('/abc') |
| 76 | + }) |
| 77 | + |
| 78 | + await fetch.get('/').expect('Location', '/abc').expect(302 /* 'Redirecting to' */) |
| 79 | + }) |
| 80 | + |
| 81 | + it('should send an HTML link to redirect to', async () => { |
| 82 | + const { fetch } = InitAppAndTest((req, res) => { |
| 83 | + if (req.url === '/abc') { |
| 84 | + req.respond({ |
| 85 | + status: 200, |
| 86 | + body: 'Hello World' |
| 87 | + }) |
| 88 | + } else { |
| 89 | + redirect(req, res, () => {})('/abc') |
| 90 | + } |
| 91 | + }) |
| 92 | + |
| 93 | + await fetch |
| 94 | + .get('/') |
| 95 | + .set('Accept', 'text/html') |
| 96 | + .expect(302 /* '<p>Found. Redirecting to <a href="/abc">/abc</a></p>' */) |
| 97 | + }) |
| 98 | +}) |
| 99 | + |
51 | 100 | run()
|
0 commit comments