2017-05-20 20:55:37 +00:00
|
|
|
|
|
|
|
import sinon = require("sinon");
|
2017-05-21 10:27:12 +00:00
|
|
|
import express = require("express");
|
2017-05-20 20:55:37 +00:00
|
|
|
|
2017-05-20 23:15:34 +00:00
|
|
|
export interface RequestMock {
|
|
|
|
app?: any;
|
|
|
|
body?: any;
|
|
|
|
session?: any;
|
|
|
|
headers?: any;
|
2017-05-21 10:27:12 +00:00
|
|
|
get?: any;
|
2017-05-21 20:45:54 +00:00
|
|
|
query?: any;
|
2017-11-01 13:24:18 +00:00
|
|
|
originalUrl: string;
|
2017-05-20 23:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface ResponseMock {
|
|
|
|
send: sinon.SinonStub | sinon.SinonSpy;
|
2017-05-21 10:27:12 +00:00
|
|
|
sendStatus: sinon.SinonStub;
|
|
|
|
sendFile: sinon.SinonStub;
|
|
|
|
sendfile: sinon.SinonStub;
|
2017-05-21 11:11:54 +00:00
|
|
|
status: sinon.SinonStub | sinon.SinonSpy;
|
2017-05-21 20:45:54 +00:00
|
|
|
json: sinon.SinonStub | sinon.SinonSpy;
|
2017-05-21 10:27:12 +00:00
|
|
|
links: sinon.SinonStub;
|
|
|
|
jsonp: sinon.SinonStub;
|
|
|
|
download: sinon.SinonStub;
|
|
|
|
contentType: sinon.SinonStub;
|
|
|
|
type: sinon.SinonStub;
|
|
|
|
format: sinon.SinonStub;
|
|
|
|
attachment: sinon.SinonStub;
|
|
|
|
set: sinon.SinonStub;
|
|
|
|
header: sinon.SinonStub;
|
|
|
|
headersSent: boolean;
|
|
|
|
get: sinon.SinonStub;
|
|
|
|
clearCookie: sinon.SinonStub;
|
|
|
|
cookie: sinon.SinonStub;
|
|
|
|
location: sinon.SinonStub;
|
2017-05-25 13:09:29 +00:00
|
|
|
redirect: sinon.SinonStub | sinon.SinonSpy;
|
2017-05-21 20:45:54 +00:00
|
|
|
render: sinon.SinonStub | sinon.SinonSpy;
|
2017-05-21 10:27:12 +00:00
|
|
|
locals: sinon.SinonStub;
|
|
|
|
charset: string;
|
|
|
|
vary: sinon.SinonStub;
|
|
|
|
app: any;
|
|
|
|
write: sinon.SinonStub;
|
|
|
|
writeContinue: sinon.SinonStub;
|
|
|
|
writeHead: sinon.SinonStub;
|
|
|
|
statusCode: number;
|
|
|
|
statusMessage: string;
|
|
|
|
setHeader: sinon.SinonStub;
|
|
|
|
setTimeout: sinon.SinonStub;
|
|
|
|
sendDate: boolean;
|
|
|
|
getHeader: sinon.SinonStub;
|
2017-05-20 23:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function RequestMock(): RequestMock {
|
|
|
|
return {
|
2017-11-01 13:24:18 +00:00
|
|
|
originalUrl: "/non-api/xxx",
|
2017-05-20 23:15:34 +00:00
|
|
|
app: {
|
|
|
|
get: sinon.stub()
|
2017-10-22 15:42:05 +00:00
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
"x-forwarded-for": "127.0.0.1"
|
|
|
|
},
|
|
|
|
session: {}
|
2017-05-20 23:15:34 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
export function ResponseMock(): ResponseMock {
|
|
|
|
return {
|
|
|
|
send: sinon.stub(),
|
|
|
|
status: sinon.stub(),
|
2017-05-21 10:27:12 +00:00
|
|
|
json: sinon.stub(),
|
|
|
|
sendStatus: sinon.stub(),
|
|
|
|
links: sinon.stub(),
|
|
|
|
jsonp: sinon.stub(),
|
|
|
|
sendFile: sinon.stub(),
|
|
|
|
sendfile: sinon.stub(),
|
|
|
|
download: sinon.stub(),
|
|
|
|
contentType: sinon.stub(),
|
|
|
|
type: sinon.stub(),
|
|
|
|
format: sinon.stub(),
|
|
|
|
attachment: sinon.stub(),
|
|
|
|
set: sinon.stub(),
|
|
|
|
header: sinon.stub(),
|
|
|
|
headersSent: true,
|
|
|
|
get: sinon.stub(),
|
|
|
|
clearCookie: sinon.stub(),
|
|
|
|
cookie: sinon.stub(),
|
|
|
|
location: sinon.stub(),
|
|
|
|
redirect: sinon.stub(),
|
|
|
|
render: sinon.stub(),
|
|
|
|
locals: sinon.stub(),
|
|
|
|
charset: "utf-8",
|
|
|
|
vary: sinon.stub(),
|
|
|
|
app: sinon.stub(),
|
|
|
|
write: sinon.stub(),
|
|
|
|
writeContinue: sinon.stub(),
|
|
|
|
writeHead: sinon.stub(),
|
|
|
|
statusCode: 200,
|
|
|
|
statusMessage: "message",
|
|
|
|
setHeader: sinon.stub(),
|
|
|
|
setTimeout: sinon.stub(),
|
|
|
|
sendDate: true,
|
|
|
|
getHeader: sinon.stub()
|
2017-05-20 23:15:34 +00:00
|
|
|
};
|
|
|
|
}
|