當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript mock-http-server.on函數代碼示例

本文整理匯總了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());
      });
  });
開發者ID:kevoree,項目名稱:kevoree-js,代碼行數:27,代碼來源:auth.ts

示例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');
      });
  });
開發者ID:kevoree,項目名稱:kevoree-js,代碼行數:60,代碼來源:dus.ts

示例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);
      });
  });
開發者ID:kevoree,項目名稱:kevoree-js,代碼行數:34,代碼來源:tdefs.ts

示例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');
  });
開發者ID:kevoree,項目名稱:kevoree-js,代碼行數:16,代碼來源:namespaces.ts


注:本文中的mock-http-server.on函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。