How to use the @loopback/testlab.createRestAppClient function in @loopback/testlab

To help you get started, we’ve selected a few @loopback/testlab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strongloop / loopback-next / packages / boot / src / __tests__ / acceptance / model-api.booter.acceptance.ts View on Github external
'model-endpoints/product.rest-config.js',
      `
const {Product} = require('../models/product.model');
module.exports = {
  model: Product,
  pattern: 'CrudRest',
  dataSource: 'db',
  basePath: '/products',
};
      `,
    );

    // Boot & start the application
    await app.boot();
    await app.start();
    const client = createRestAppClient(app);

    // Verify that we have REST API for our model
    const created = await client
      .post('/products')
      .send({name: 'a name'})
      .expect(200);
    const found = await client.get('/products').expect(200);
    expect(found.body).to.deepEqual([{id: created.body.id, name: 'a name'}]);

    // Verify that we have a repository class to use e.g. in tests
    const repo = await app.get<
      DefaultCrudRepository
    >('repositories.ProductRepository');
    const stored = await repo.find();
    expect(toJSON(stored)).to.deepEqual(found.body);
  });
github strongloop / loopback-next / examples / soap-calculator / src / __tests__ / acceptance / application.acceptance.ts View on Github external
before(async () => {
    await app.boot();
    await app.start();
    client = createRestAppClient(app);
  });
github strongloop / loopback-next / packages / rest-explorer / src / __tests__ / acceptance / rest-explorer.acceptance.ts View on Github external
async function givenAppWithCustomExplorerConfig(
    config?: RestServerConfig,
    explorerConfig?: RestExplorerConfig,
  ) {
    app = givenRestApplication(config);
    if (explorerConfig) {
      app.bind(RestExplorerBindings.CONFIG).to(explorerConfig);
    }
    app.component(RestExplorerComponent);
    await app.start();
    request = createRestAppClient(app);
  }
});
github strongloop / loopback-next / packages / rest / src / __tests__ / acceptance / validation / validation.acceptance.ts View on Github external
async function givenAnAppAndAClient(
    controller: ControllerClass,
    validationOptions?: RequestBodyValidationOptions,
  ) {
    app = new RestApplication({rest: givenHttpServerConfig()});
    if (validationOptions)
      app
        .bind(RestBindings.REQUEST_BODY_PARSER_OPTIONS)
        .to({validation: validationOptions});
    app.controller(controller);
    await app.start();

    client = createRestAppClient(app);
  }
});
github strongloop / loopback-next / packages / rest / src / __tests__ / acceptance / file-upload / file-upload-with-parser.acceptance.ts View on Github external
async function givenAClient() {
    app = new RestApplication({rest: givenHttpServerConfig()});
    app.bodyParser(MultipartFormDataBodyParser);
    app.controller(FileUploadController);
    await app.start();
    client = createRestAppClient(app);
  }
});
github strongloop / loopback-next / examples / hello-world / src / __tests__ / acceptance / application.acceptance.ts View on Github external
before(async () => {
    await app.start();
    client = createRestAppClient(app);
  });
  after(async () => {
github strongloop / loopback-next / extensions / health / src / __tests__ / acceptance / health.acceptance.ts View on Github external
async function givenAppWithCustomConfig(config: HealthConfig) {
    app = givenRestApplication();
    app.bind(HealthBindings.CONFIG).to(config);
    app.component(HealthComponent);
    await app.start();
    request = createRestAppClient(app);
  }
github strongloop / loopback-next / examples / soap-calculator / src / __tests__ / acceptance / test-helper.ts View on Github external
export async function setupApplication(): Promise {
  const app = new SoapCalculatorApplication({
    rest: givenHttpServerConfig(),
  });

  await app.boot();
  await app.start();

  const client = createRestAppClient(app);

  return {app, client};
}
github strongloop / loopback-next / packages / rest / src / __tests__ / acceptance / request-parsing / request-parsing.acceptance.ts View on Github external
async function givenAClient() {
    app = new RestApplication({rest: givenHttpServerConfig()});
    app.controller(
      givenBodyParamController('/show-body-json', 'json'),
      'Controller1',
    );
    app.controller(givenBodyParamController('/show-body'), 'Controller2');
    await app.start();
    client = createRestAppClient(app);
  }