This repository has been archived by the owner on May 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change default status to 404 without affecting Koa default semantics
- Loading branch information
Showing
2 changed files
with
62 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** Copyright (c) 2018 Uber Technologies, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import test from 'tape-cup'; | ||
import App from 'fusion-core'; | ||
|
||
import {getSimulator} from '../index.js'; | ||
|
||
test('status is 404 if ctx.body is never updated', async t => { | ||
const app = new App('el', el => el); | ||
const ctx = await getSimulator(app).request('/'); | ||
t.equals(ctx.status, 404, 'status defaults to 404'); | ||
t.end(); | ||
}); | ||
|
||
test('status is 200 if ctx.body is updated in request', async t => { | ||
const app = new App('el', el => el); | ||
app.middleware((ctx, next) => { | ||
ctx.body = {ok: 1}; | ||
return next(); | ||
}); | ||
const ctx = await getSimulator(app).request('/'); | ||
t.equals(ctx.status, 200, 'status defaults to 200'); | ||
t.end(); | ||
}); | ||
|
||
test('status is set if ctx.status is updated in request', async t => { | ||
const app = new App('el', () => 'hello'); | ||
app.middleware((ctx, next) => { | ||
ctx.status = 500; | ||
ctx.body = {error: 'error'}; | ||
return next(); | ||
}); | ||
const ctx = await getSimulator(app).render('/'); | ||
t.equals(ctx.status, 500, 'status is set'); | ||
t.end(); | ||
}); | ||
|
||
test('status is 200 if ctx.body is updated in render', async t => { | ||
const app = new App('el', () => 'hello'); | ||
const ctx = await getSimulator(app).render('/'); | ||
t.equals(ctx.status, 200, 'status defaults to 200'); | ||
t.end(); | ||
}); | ||
|
||
test('status is set if ctx.status is updated in render', async t => { | ||
const app = new App('el', () => 'hello'); | ||
app.middleware((ctx, next) => { | ||
ctx.status = 500; | ||
return next(); | ||
}); | ||
const ctx = await getSimulator(app).render('/'); | ||
t.equals(ctx.status, 500, 'status is set'); | ||
t.end(); | ||
}); |
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