Skip to content
Snippets Groups Projects
Select Git revision
  • d7f3ce27533071427644338d20c51b1635ebd4d2
  • dev default protected
  • 722-envsubst-client-side-conf
  • renovate/major-nest-monorepo
  • renovate/luxon-3.x
  • renovate/gouvfr-anct-timetable-to-osm-opening-hours-2.x
  • renovate/major-typescript-eslint-monorepo
  • renovate/npm-11.x
  • renovate/mysql-9.x
  • renovate/mongo-express-1.x
  • renovate/major-jest-monorepo
  • renovate/tsconfig-paths-4.x
  • renovate/jest-junit-16.x
  • renovate/express-5.x
  • renovate/bitnami-mongodb-8.x
  • renovate/elastic-elasticsearch-8.x
  • renovate/ghost-5.x
  • renovate/ghcr.io-browserless-chromium-2.x
  • renovate/elasticsearch-7.x
  • renovate/devdependencies-(non-major)
  • 718-evenement-filtre-commune
  • v4.0.3
  • v4.0.1
  • v4.0.0
  • v3.4.3
  • v3.4.2
  • v3.4.1
  • v3.4.0
  • v3.3.1
  • v3.3.0
  • v3.2.0
  • v3.1.0
  • v3.0.1
  • v3.0.0
  • v2.5.0
  • v2.4.2
  • v2.4.1
  • v2.4.0
  • v2.3.2
  • v2.3.1
  • v2.3.0
41 results

pages.controller.spec.ts

Blame
  • pages.controller.spec.ts 3.13 KiB
    import { HttpModule, HttpService } from '@nestjs/common';
    import { Test, TestingModule } from '@nestjs/testing';
    import { of } from 'rxjs';
    import { ConfigurationModule } from '../configuration/configuration.module';
    import { PagesController } from './pages.controller';
    import { AxiosResponse } from 'axios';
    
    describe('PagesController', () => {
      let controller: PagesController;
    
      const httpServiceMock = {
        get: jest.fn(),
      };
      beforeEach(async () => {
        const module: TestingModule = await Test.createTestingModule({
          imports: [ConfigurationModule, HttpModule],
          providers: [
            {
              provide: HttpService,
              useValue: httpServiceMock,
            },
          ],
          controllers: [PagesController],
        }).compile();
    
        controller = module.get<PagesController>(PagesController);
      });
    
      it('should be defined', () => {
        expect(controller).toBeDefined();
      });
    
      describe('getPagebySlug', () => {
        it('should get page Hello by Slug hello', async () => {
          const data = [
            {
              id: '61c4847b0ff4550001505090',
              uuid: 'f4ee5a37-a343-4cad-8a32-3f6cf87f9569',
              title: 'Hello',
              slug: 'hello',
              html: '<p>Test</p>',
              comment_id: '61c4847b0ff4550001505090',
              feature_image: 'http://localhost:2368/content/images/2021/12/dacc-4.png',
              featured: false,
              visibility: 'public',
              created_at: '2022-01-25T09:35:07.000+00:00',
              updated_at: '2022-01-26T15:24:24.000+00:00',
              published_at: '2022-01-25T09:35:16.000+00:00',
              custom_excerpt: null,
              codeinjection_head: null,
              codeinjection_foot: null,
              custom_template: null,
              canonical_url: null,
              url: 'http://localhost:2368/hello/',
              excerpt:
                '« Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus.\n' +
                'Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed,\n' +
                'dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper\n' +
                'congue, euismod non, mi. Proin porttitor, orci nec nonummy molestie, enim est\n' +
                'eleifend mi, non fermentum diam nisl sit amet erat. Duis semper. Duis arcu\n' +
                'massa, scelerisque vitae, consequat in, pretium a, enim. Pellentesque congue. Ut\n' +
                'in risus volutpat libero pharetra tem',
              reading_time: 1,
              page: true,
              access: true,
              og_image: null,
              og_title: null,
              og_description: null,
              twitter_image: null,
              twitter_title: null,
              twitter_description: null,
              meta_title: null,
              meta_description: null,
              frontmatter: null,
            },
          ];
          const axiosResult: AxiosResponse = {
            data: {
              pages: data,
            },
            status: 200,
            statusText: 'OK',
            headers: {},
            config: {},
          };
          httpServiceMock.get.mockImplementationOnce(() => of(axiosResult));
          const result = await (await controller.getPagebySlug('hello')).toPromise();
          expect(result.pages).toStrictEqual(data);
        });
      });
    });