@newskit-render/core 2.37.2 → 2.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/components/article/__tests__/__snapshots__/index.test.tsx.snap +164 -156
- package/package.json +3 -3
- package/pages/preview/[articleId]/version/[versionId]/index.tsx +19 -26
- package/public/ads.min.js +8175 -1
- package/helpers/__tests__/getRecommendation.test.ts +0 -56
- package/helpers/getRecommendations.ts +0 -30
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { Publisher } from '@newskit-render/api'
|
|
2
|
-
import { getRecommendations, fetcher } from '../getRecommendations'
|
|
3
|
-
import { recomendationsMock } from '../mocks/getRecommendationsMock'
|
|
4
|
-
|
|
5
|
-
jest.mock('@newskit-render/standalone-components', () => {
|
|
6
|
-
return {
|
|
7
|
-
recommendationsProvider: jest.fn().mockResolvedValueOnce([
|
|
8
|
-
{
|
|
9
|
-
href: 'https://www.thesun.co.uk/wp-content/uploads/2022/03/image-656eaa885d.jpg?strip=all&w=600&h=338&crop=1',
|
|
10
|
-
tag: 'FOOT ON THE GAZ',
|
|
11
|
-
text: 'Bale considering short deal with new club before RETIRING after World Cup',
|
|
12
|
-
title: 'FOOT ON THE GAZ',
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
href: 'https://www.thesun.co.uk/wp-content/uploads/2022/03/image-a21f115694-1.jpg?strip=all&w=600&h=338&crop=1',
|
|
16
|
-
tag: 'TOUGH TIMES',
|
|
17
|
-
text: 'I only made £5k last year - I sold £801k villa for cash, says Claire Sweeney',
|
|
18
|
-
title: 'TOUGH TIMES',
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
href: null,
|
|
22
|
-
tag: 'TOUGH TIMES',
|
|
23
|
-
text: 'I only made £5k last year - I sold £801k villa for cash, says Claire Sweeney',
|
|
24
|
-
title: 'TOUGH TIMES',
|
|
25
|
-
},
|
|
26
|
-
]),
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
describe('getRecommendations function', () => {
|
|
31
|
-
it('should return recomendations', async () => {
|
|
32
|
-
const result = await getRecommendations({
|
|
33
|
-
articleId: 'test-1',
|
|
34
|
-
publisher: Publisher.SUN_UK,
|
|
35
|
-
userId: 'user-1',
|
|
36
|
-
})
|
|
37
|
-
expect(result).toEqual(recomendationsMock)
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
describe('fetcher function', () => {
|
|
41
|
-
it('should retun json object', async () => {
|
|
42
|
-
global.fetch = jest.fn().mockImplementation(() => {
|
|
43
|
-
return {
|
|
44
|
-
json: () => recomendationsMock,
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
const result = await fetcher({
|
|
48
|
-
url: 'http://localhost:3000',
|
|
49
|
-
args: { articleId: 'test-2' },
|
|
50
|
-
})
|
|
51
|
-
expect(result).toEqual(recomendationsMock)
|
|
52
|
-
// @ts-ignore
|
|
53
|
-
global.fetch.mockClear()
|
|
54
|
-
delete global.fetch
|
|
55
|
-
})
|
|
56
|
-
})
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Fetcher } from 'swr'
|
|
2
|
-
import {
|
|
3
|
-
recommendationsProvider,
|
|
4
|
-
Article,
|
|
5
|
-
} from '@newskit-render/standalone-components'
|
|
6
|
-
import { Publisher } from '@newskit-render/api'
|
|
7
|
-
|
|
8
|
-
interface Recommendations {
|
|
9
|
-
publisher: Publisher
|
|
10
|
-
articleId: string
|
|
11
|
-
userId?: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const fetcher: Fetcher<Article[]> = async (url): Promise<Article[]> => {
|
|
15
|
-
const res = await fetch(url)
|
|
16
|
-
return res.json()
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const getRecommendations = async ({
|
|
20
|
-
articleId,
|
|
21
|
-
publisher,
|
|
22
|
-
userId,
|
|
23
|
-
}: Recommendations): Promise<Article[]> => {
|
|
24
|
-
const recommendations = await recommendationsProvider({
|
|
25
|
-
articleId,
|
|
26
|
-
publisher,
|
|
27
|
-
userId,
|
|
28
|
-
})
|
|
29
|
-
return recommendations
|
|
30
|
-
}
|