本文整理汇总了TypeScript中supertest.agent函数的典型用法代码示例。如果您正苦于以下问题:TypeScript agent函数的具体用法?TypeScript agent怎么用?TypeScript agent使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了agent函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: beforeEach
beforeEach(() => {
buildVerifier = new BuildVerifier(
defaultConfig.secret,
defaultConfig.githubToken,
defaultConfig.repoSlug,
defaultConfig.githubOrganization,
defaultConfig.githubTeamSlugs,
);
buildCreator = new BuildCreator(defaultConfig.buildsDir);
agent = supertest.agent((usf as any).createMiddleware(buildVerifier, buildCreator));
spyOn(console, 'error');
});
示例2: it
it('works', function (done) {
const auth = kua.create(
// Find the user based on partial user, ...credentials
kua.basicAuth(testing.store.find),
// ACL
kua.acl(ctx => ctx.user, user => user.roles));
let app = new Koa().use(
auth.lock(
endPoint, ['admin', 'user'])
);
let request = Request.agent(listen(app));
request.get('/')
.set(auth.provider.key, auth.provider.encode(users.admin))
.expect("hello")
.end((error, r) => {
if (error) throw (error);
});
request.get('/')
.expect(407)
.end((error, r) => {
if (error) throw (error);
})
request.get('/')
.set(auth.provider.key, auth.provider.encode(users.bob))
.expect(200)
.expect('hello')
.end((error, r) => {
if (error) throw (error);
})
request.get('/')
.set(auth.provider.key, auth.provider.encode(users.guest))
.expect(403)
.end((error, r) => {
if (error) throw (error);
done();
})
// request.get('admin:admin@/something')
// .expect(200)
// .end((error, r) => {
// if (error) throw (error);
// done();
// })
})
示例3: it
it('should test a GET method with a service that return a promise', (done) => {
new JsRestfulRegistry(app).registerService(new TestService());
request.agent(app).get('/books').end((err:any, res: request.Response) => {
util.checkDefaultsJson(err, res, done);
expect(res.body).to.eql([anyBook]);
done();
});
});
示例4: beforeEach
beforeEach(() => {
const circleCiApi = new CircleCiApi(defaultConfig.githubOrg, defaultConfig.githubRepo,
defaultConfig.circleCiToken);
const githubApi = new GithubApi(defaultConfig.githubToken);
const prs = new GithubPullRequests(githubApi, defaultConfig.githubOrg, defaultConfig.githubRepo);
const teams = new GithubTeams(githubApi, defaultConfig.githubOrg);
buildRetriever = new BuildRetriever(circleCiApi, defaultConfig.downloadSizeLimit, defaultConfig.downloadsDir);
buildVerifier = new BuildVerifier(prs, teams, defaultConfig.githubTeamSlugs, defaultConfig.trustedPrLabel);
buildCreator = new BuildCreator(defaultConfig.buildsDir);
const middleware = PreviewServerFactory.createMiddleware(buildRetriever, buildVerifier, buildCreator,
defaultConfig);
agent = supertest.agent(middleware);
});
示例5: it
it('should should clear cookie', async () => {
const agent = request.agent(app.handle);
let res = await agent
.get(`/test/cookie_json/?aa=bb`)
res.should.to.have.status(200);
res.header["set-cookie"][0].should.be.eq("cookie=j%3A%7B%22test%22%3A%22working%22%7D; Path=/; Expires=Mon, 01 Feb 2100 00:00:00 GMT");
let res2 = await agent
.get(`/test/cookie_clear/?aa=bb`)
res2.header["set-cookie"][0].should.be.eq("cookie=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT");
})
示例6: test
test('Throws NotFound', { skip: false }, async (t) => {
//app: Setup ...
let app = new Koa();
var request = supertest.agent(listen(app));
app.use(users.routes.get);
const service = await getStore(true);
//this: test Setup
request.get('/users/bob')
.accept('application.json')
.expect(404)
.end((e, r) => {
t.assert(!e);
t.end();
});
});
示例7: test
test('secret:401', { skip: false }, async (t) => {
let store = await getStore(false);
let app = new Koa()
//Auth
app.use(authentication);
//Secured
app.use(secretRoute);
//...
let request = supertest.agent(listen(app));
request.get('/secret')
.expect(401)
.end(async (err, res) => {
await delay(5);
t.assert(!err);
if (err) debug(`Agent: Error: ${err.message}`);
t.end();
});
});