Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeEach(() => controller = createController(/* upperFirstCamelName */Controller));
beforeEach(async () => {
controller = createController(TestFooBarController);
const repository = getRepository(TestFooBar);
await repository.clear();
[ testFooBar1, testFooBar2 ] = await repository.save([
{
text: 'TestFooBar 1'
},
{
text: 'TestFooBar 2'
},
]);
});
beforeEach(async () => {
controller = createController(TestFooBarController);
const repository = getRepository(TestFooBar);
await repository.clear();
[ testFooBar1, testFooBar2 ] = await repository.save([
{
text: 'TestFooBar 1'
},
{
text: 'TestFooBar 2'
},
]);
});
it('with a "data" property if the GraphQL schema validates the query (with resolvers).', async () => {
class ConcreteController extends GraphQLController {
schema = buildSchema(`type Query {
hello: String
}
`);
resolvers = {
hello: () => {
return 'Hello world!';
},
};
}
controller = createController(ConcreteController);
const query = `{ hello }`;
const ctx = new Context({
query: { query }
});
const response = await controller.post(ctx);
if (!isHttpResponseOK(response)) {
throw new Error('The controller should have returned an HttpResponseOK instance.');
}
deepStrictEqual(response.body, {
data: {
hello: 'Hello world!'
}
});
it('should return a HttpResponseOK.', () => {
const controller = createController(ApiController);
const ctx = new Context({});
const response = controller.index(ctx);
if (!isHttpResponseOK(response)) {
throw new Error('The response should be an instance of HttpResponseOK.');
}
strictEqual(response.body, 'Hello world!');
});
beforeEach(() => controller = createController(ApiController));
beforeEach(async () => {
controller = createController(ProductController);
const repository = getRepository(Product);
await repository.clear();
[ product1, product2 ] = await repository.save([
{
text: 'Product 1'
},
{
text: 'Product 2'
},
]);
});
@ApiInfo(info)
class ApiController {
static count = 0;
constructor() {
ApiController.count++;
}
}
class ConcreteClass extends SwaggerController {
options = [
{ name: 'v2', controllerClass: ApiController },
];
}
const servicesAndControllers = new ServiceManager();
servicesAndControllers.get(ApiController);
const controller = createController(ConcreteClass, servicesAndControllers);
const ctx = new Context({ query: { name: 'v2' } });
strictEqual(ApiController.count, 1);
controller.getOpenApiDefinition(ctx);
strictEqual(ApiController.count, 1);
});
beforeEach(() => controller = createController(ConcreteController));
beforeEach(() => controller = createController(ApiController));