-
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.
- Loading branch information
1 parent
2f1d111
commit 9b07b2a
Showing
10 changed files
with
867 additions
and
64 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 @@ | ||
test |
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,15 +1,14 @@ | ||
{ | ||
"mochaExplorer.files": "test/**/*.ts", | ||
"mochaExplorer.require": "ts-node/register", | ||
"eslint.format.enable": true, | ||
"eslint.alwaysShowStatus": true, | ||
"eslint.validate": [ | ||
"javascript", | ||
"typescript" | ||
], | ||
"eslint.validate": ["javascript", "typescript"], | ||
"typescript.updateImportsOnFileMove.enabled": "always", | ||
"javascript.updateImportsOnFileMove.enabled": "always", | ||
"explorer.confirmDragAndDrop": false, | ||
"explorer.confirmDelete": false, | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true | ||
} | ||
} | ||
} |
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,14 @@ | ||
import { ProblemDocument } from 'http-problem-details' | ||
import http from 'http' | ||
|
||
export {} | ||
|
||
declare global { | ||
namespace Express { | ||
export interface Response<ResBody = any> | ||
extends http.ServerResponse, | ||
Express.Response { | ||
warn(warnings: ProblemDocument[]): this | ||
} | ||
} | ||
} |
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,3 +1,7 @@ | ||
export function hello(name: string): string { | ||
return `hello, ${name}` | ||
import { ProblemDocument } from 'http-problem-details' | ||
|
||
export function warn(warnings: ProblemDocument[]): Express.Response { | ||
this.__warnings = warnings | ||
this.set('Content-Warning', `"embedded-warning"; ${Date.now()}`) | ||
return this | ||
} |
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,10 @@ | ||
import * as mung from 'express-mung' | ||
|
||
function modify(body, _req, res): any { | ||
if (res.__warnings) { | ||
body.warnings = res.__warnings | ||
} | ||
return body | ||
} | ||
|
||
export default mung.json(modify) |
This file was deleted.
Oops, something went wrong.
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,47 @@ | ||
import * as should from 'should' | ||
import { warn } from '../src/index' | ||
import modify from '../src/modify' | ||
import express from 'express' | ||
import { ProblemDocument } from 'http-problem-details' | ||
import { Server } from 'http' | ||
import fetch from 'node-fetch' | ||
require('should') | ||
|
||
function warn1() { | ||
return (_req: any, res: any, next) => { | ||
res.warn = warn | ||
return next() | ||
} | ||
} | ||
|
||
describe('warn', () => { | ||
const app = express() | ||
app.use([warn1(), modify]) | ||
let server: Server | ||
it('should say name', async () => { | ||
try { | ||
app.get('/', (req, res, next) => { | ||
const response = res | ||
return res | ||
.status(200) | ||
.warn([ | ||
new ProblemDocument({ | ||
detail: 'Street name was too long. It has been shortened...', | ||
instance: 'https://example.com/shipments/3a186c51/msgs/c94d', | ||
type: 'https://example.com/errors/shortened_entry' | ||
}) | ||
]) | ||
.send({ some: 'content' }) | ||
}) | ||
server = app.listen(3000) | ||
const res = await fetch('http://localhost:3000/') | ||
const body = await res.json() | ||
body.some.should.equal('content') | ||
console.log(body) | ||
console.log(res.headers) | ||
} finally { | ||
server.close() | ||
// done() | ||
} | ||
}) | ||
}) |
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
Oops, something went wrong.