Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
createRequestContext(url) {
// Fake IncomingRequest
const req = httpMocks.createRequest({
method: 'GET',
url,
});
// Fake ServerResponse
const res = httpMocks.createResponse();
res.__body = '';
res.write = chunk => {
res.__body += chunk;
};
res.end = data => {
if (data) {
res.__body = data;
}
};
return {
url,
req,
res,
redirected: false,
statusCode: 200,
it('should fallthrough if all params are present', function () {
var mockReq = httpMocks.createRequest({
body: {
email: 'user@email.com',
name: 'New Guy'
}
});
var mockRes = httpMocks.createResponse();
middleware.requireBody(['email', 'name'])(mockReq, mockRes, function () {
mockRes.statusCode = 200;
});
mockRes.statusCode.should.eql(200);
});
it('should be false if params has no client id', () => {
let params = {}
let response = HttpMocks.createResponse()
let opAuthRequest = {
host: {}
}
let request = new LoginConsentRequest({ params, response, opAuthRequest })
expect(request.isLocalRpClient(undefined)).to.be.false()
})
test('Create new secret', t => {
const req = _.cloneDeep(reqObj);
req.method = 'POST';
req.headers.referrer = '/applications/1';
req.session.form.applications.edit.id = 1;
const request = httpMocks.createRequest(req);
const response = httpMocks.createResponse({ eventEmitter: EventEmitter });
const resp = applications.routes.secret(request, response, next);
response.render();
return response.on('end', () => {
t.is(response.statusCode, 302, 'Should be a 302 response');
t.is(response._getRedirectUrl(), '/applications/1', 'should redirect to edit url');
return resp.then(res => {
t.not(res, dbmocks.rows[0]['client-secret'], 'should be a new client secret');
});
});
});
it('Should throw an error if url does not exist', () => {
let request = httpMocks.createRequest({
method: 'POST',
body: {}
});
let response = httpMocks.createResponse({
eventEmitter: events.EventEmitter
});
expect(() => {
Controller.createShortUrl(request, response);
}).to.throw(Error);
});
test.cb('Single user route - bad id', t => {
const req = _.cloneDeep(reqObj);
req.url = '/users/1000';
req.params.id = 1000;
const request = httpMocks.createRequest(req);
const response = httpMocks.createResponse({ eventEmitter: EventEmitter });
const resp = users.routes.one(request, response, next);
response.on('end', () => {
t.is(response.statusCode, 200, 'Should be a 200 response');
return resp.then(res => {
t.is(res.status, 404, 'should have 404 status');
t.end();
});
});
response.render();
});
field: common.createAccessor(),
output: common.createAccessor(),
};
resource = new Resource(model, {
type: 'test',
field: {
value: accessors.field,
nullable: true,
},
output: {
value: accessors.output,
nullable: true,
},
});
Runtime.addResource('ModifyResource', resource);
res = httpMocks.createResponse();
});
' on a findOne request', function(done) {
var request = httpMocks.createRequest({
method: 'GET',
url: '/by_slug/test_article_one_slug'
});
var response = httpMocks.createResponse();
Q.all([
model.findOneBySlug('test_article_one_slug'),
Q.delay(1000)
]).then(function(result) {
result = result[0];
response.statusCode.should.equal(200, 'status code');
var responseData = JSON.parse(response._getData());
responseData.should.deep.equal(result.toVO());
}).then(function() {
done();
}, function(error) {
done(error);
});
it('should process a valid request', () => {
const response = httpMocks.createResponse();
return stackController.createStack(request, response)
.then(() => {
expect(response.statusCode).toBe(201);
});
});