How to use the @foal/core.createController function in @foal/core

To help you get started, we’ve selected a few @foal/core 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 FoalTS / foal / packages / cli / src / generate / templates / controller / controller.spec.empty.ts View on Github external
  beforeEach(() => controller = createController(/* upperFirstCamelName */Controller));
github FoalTS / foal / packages / cli / src / generate / specs / rest-api / test-foo-bar.controller.spec.current-dir.ts View on Github external
beforeEach(async () => {
    controller = createController(TestFooBarController);

    const repository = getRepository(TestFooBar);
    await repository.clear();
    [ testFooBar1, testFooBar2 ] = await repository.save([
      {
        text: 'TestFooBar 1'
      },
      {
        text: 'TestFooBar 2'
      },
    ]);
  });
github FoalTS / foal / packages / cli / src / generate / specs / rest-api / test-foo-bar.controller.spec.ts View on Github external
beforeEach(async () => {
    controller = createController(TestFooBarController);

    const repository = getRepository(TestFooBar);
    await repository.clear();
    [ testFooBar1, testFooBar2 ] = await repository.save([
      {
        text: 'TestFooBar 1'
      },
      {
        text: 'TestFooBar 2'
      },
    ]);
  });
github FoalTS / foal / packages / graphql / src / graphql.controller.spec.ts View on Github external
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!'
            }
          });
github FoalTS / foal / packages / cli / src / generate / specs / app / src / app / controllers / api.controller.spec.ts View on Github external
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!');
    });
github FoalTS / foal / packages / examples / src / app / controllers / product.controller.spec.ts View on Github external
beforeEach(async () => {
    controller = createController(ProductController);

    const repository = getRepository(Product);
    await repository.clear();
    [ product1, product2 ] = await repository.save([
      {
        text: 'Product 1'
      },
      {
        text: 'Product 2'
      },
    ]);
  });
github FoalTS / foal / packages / swagger / src / swagger-controller.spec.ts View on Github external
@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);
      });
github FoalTS / foal / packages / graphql / src / graphql.controller.spec.ts View on Github external
  beforeEach(() => controller = createController(ConcreteController));