Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'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);
});
before(async () => {
await app.boot();
await app.start();
client = createRestAppClient(app);
});
before(() => {
client = createRestAppClient(app);
});
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);
}
});
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);
}
});
async function givenAClient() {
app = new RestApplication({rest: givenHttpServerConfig()});
app.bodyParser(MultipartFormDataBodyParser);
app.controller(FileUploadController);
await app.start();
client = createRestAppClient(app);
}
});
before(async () => {
await app.start();
client = createRestAppClient(app);
});
after(async () => {
async function givenAppWithCustomConfig(config: HealthConfig) {
app = givenRestApplication();
app.bind(HealthBindings.CONFIG).to(config);
app.component(HealthComponent);
await app.start();
request = createRestAppClient(app);
}
export async function setupApplication(): Promise {
const app = new SoapCalculatorApplication({
rest: givenHttpServerConfig(),
});
await app.boot();
await app.start();
const client = createRestAppClient(app);
return {app, client};
}
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);
}