); agent = request.agent(app);
describe('helpers/app', function() { const root = pathUtil.join(__dirname, '../fixtures/core/app'); const app = plover({ applicationRoot: root }); const agent = request.agent(app.callback()); it('quick render child view not found', function() { return agent.get('/app-helper/child-view-not-found') .expect(equal('app-helper-child-view-not-found.html')); }); });
/** * Converts a Koa app into a supertest compatible agent instance. * * @param {Application} app * Koa application instance. * * @return {TestAgent} * Supertest agent instance. */ function server (app) { return agent(http.createServer(app.callback())) }
it('should load session from cookie', function (done) { var agent = request.agent(app); agent.get('/add') .expect(200) .expect(shouldSetCookie('node_session')) .end(function(err){ if(err) return done(err); agent.get('/read') .expect(200) .expect('positron', done); }); });
before(function(done) { // Get application app = express.init(sequelize); agent = request.agent(app); done(); });
it('使用filter', async function() { const thisApp = plover({ applicationRoot: root, filters: ['./lib/filters/box.js'] }); const filter = require(pathUtil.join(root, './lib/filters/api.js')); thisApp.addFilter(filter, { match: '/api/*' }); const thisAgent = request.agent(thisApp.callback()); await thisAgent.get('/index?layout=false') .expect(equal('index-with-filter.html')); await thisAgent.get('/api/offer') .expect('X-API', '112233') .expect({ id: 123, name: 'test offer' }); });
beforeEach(function () { serverUrl = `http://localhost:${nconf.get('development').port}`; server = supertest.agent(serverUrl); });
describe('when supplied with redux middleware', () => { const app = routes({ '/async': () => Async.of({ body: 'async' }) }) const middleware = [ future ] const server = http.createServer(mount({ app, middleware })) const agent = request.agent(server) it('supports handlers that return ADTs', () => agent.get('/async').expect(200).then(assertBody('async')) ) })
describe('when called with no options', () => { const server = http.createServer(mount()) const agent = request.agent(server) it('acts as an echo server', () => agent.post('/').send({ a: 'b' }).expect(200, { a: 'b' }) ) })
describe('Admin not logged in', function(){ it('should return 302 when not admin', function(done){ request(app) .get('/admin/') .expect(302, done) }) it('should return 200 with error message Only admins may access the admin page', function(done){ const user = request.agent(app); user.post('/auth/login') .send(sample_user_info) .expect(302, function(err, res) { if(err) return done(err) user.get('/admin/') .expect(200, done) }) }) })
describe('helpers/app', function() { const root = pathUtil.join(__dirname, '../fixtures/core/app'); const app = plover({ applicationRoot: root }); const agent = request.agent(app.callback()); it('quick render child view not found', function() { return agent.get('/app-helper/child-view-not-found') .expect(equal('app-helper-child-view-not-found.html')); }); });
before(function (done) { // Get application app = express.init(mongoose); agent = request.agent(app); done(); });
before(function (done) { // Get application app = express.init(mongoose); agent = request.agent(app); done(); });
before(function (done) { // Get application app = express.init(mongoose); agent = request.agent(app); done(); });
it('使用filter', async function() { const thisApp = plover({ applicationRoot: root, filters: ['./lib/filters/box.js'] }); const filter = require(pathUtil.join(root, './lib/filters/api.js')); thisApp.addFilter(filter, { match: '/api/*' }); const thisAgent = request.agent(thisApp.callback()); await thisAgent.get('/index?layout=false') .expect(equal('index-with-filter.html')); await thisAgent.get('/api/offer') .expect('X-API', '112233') .expect({ id: 123, name: 'test offer' }); });