本文整理汇总了TypeScript中mock-http-server.on函数的典型用法代码示例。如果您正苦于以下问题:TypeScript on函数的具体用法?TypeScript on怎么用?TypeScript on使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了on函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('auth.ensureLogin() should try to refresh token if expired', () => {
const expectedAuth = {
access_token: 'new-foo',
refresh_token: 'new-bar',
expires_in: 3600,
};
server.on({
method: 'POST',
path: '/oauth/token',
reply: {
status: 200,
body: JSON.stringify(expectedAuth),
},
});
// define user data as expired
config.set('user.expires_at', Date.now() - (1000 * 60 * 10)); // 10min old
return auth.ensureLogin()
.then(() => {
const user: IConfigUser = config.get('user');
assert.equal(user.access_token, expectedAuth.access_token);
assert.equal(user.refresh_token, expectedAuth.refresh_token);
assert.isAtLeast(user.expires_at!, Date.now());
});
});
示例2: it
it('retrieve specific dus', () => {
server.on({
method: 'GET',
path: '/api/namespaces/kevoree/tdefs/Ticker/3/specific-dus',
reply: {
status: 200,
body: JSON.stringify([
{
id: 0,
model: '{}',
namespace: 'kevoree',
tdefName: 'Ticker',
tdefVersion: 3,
name: 'kevoree-comp-ticker',
version: '3.1.0-alpha',
platform: 'js',
},
{
id: 1,
model: '{}',
namespace: 'kevoree',
tdefName: 'Ticker',
tdefVersion: 3,
name: 'kevoree-comp-ticker',
version: '3.0.0',
platform: 'java',
},
{
id: 2,
model: '{}',
namespace: 'kevoree',
tdefName: 'Ticker',
tdefVersion: 3,
name: 'kevoree-comp-ticker',
version: '5.4.0-SNAPSHOT',
platform: 'dotnet',
},
]),
},
});
const filters = {
js: '3.1.0-alpha',
dotnet: 'latest',
};
return du.getSpecificByNamespaceAndTdefNameAndTdefVersion('kevoree', 'Ticker', 3, filters)
.then((dus) => {
assert.equal(dus.length, 3);
const js = dus.find((deployUnit) => deployUnit.platform === 'js');
assert.isNotNull(js);
assert.equal(js!.version, filters.js);
const java = dus.find((deployUnit) => deployUnit.platform === 'java');
assert.isNotNull(java);
assert.equal(java!.version, '3.0.0');
const dotnet = dus.find((deployUnit) => deployUnit.platform === 'dotnet');
assert.isNotNull(dotnet);
assert.equal(dotnet!.version, '5.4.0-SNAPSHOT');
});
});
示例3: it
it('create a new tdef', () => {
const expectedTdef = {
id: 4,
namespace: 'kevoree',
name: 'Foo',
version: 1,
model: JSON.stringify({
class: 'org.kevoree.Component@Foo',
name: 'Foo',
version: 1,
potato: 'foo',
}),
};
server.on({
method: 'POST',
path: '/api/namespaces/kevoree/tdefs',
reply: {
status: 201,
body: JSON.stringify(expectedTdef),
},
});
logUserIn();
return tdef.create('kevoree', expectedTdef)
.then((typeDef) => {
assert.equal(typeDef.id, expectedTdef.id);
assert.equal(typeDef.name, expectedTdef.name);
assert.equal(typeDef.version, expectedTdef.version);
assert.equal(typeDef.model, expectedTdef.model);
assert.equal(typeDef.namespace, expectedTdef.namespace);
});
});
示例4: it
it('delete a namespace', () => {
const expectedNs = { name: 'newnamespace', owner: 'kevoree' };
server.on({
method: 'DELETE',
path: '/api/namespaces/newnamespace',
reply: {
status: 200,
body: JSON.stringify(expectedNs),
},
});
logUserIn();
return namespace.delete('newnamespace');
});