Newer
Older
import { HttpModule, HttpService } from '@nestjs/axios';

Marlène SIMONDANT
committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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);
});
});
});