@playpilot/tpi 5.2.0-beta.1 → 5.2.0-beta.2
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/package.json +1 -1
- package/src/lib/api.ts +4 -4
- package/src/tests/lib/api.test.js +22 -18
package/package.json
CHANGED
package/src/lib/api.ts
CHANGED
|
@@ -29,15 +29,15 @@ export async function fetchLinkInjections(
|
|
|
29
29
|
|
|
30
30
|
if (!apiToken) throw new Error('No token was provided')
|
|
31
31
|
|
|
32
|
-
// Add additional parameters if request is made to run the AI.
|
|
33
|
-
//
|
|
34
|
-
// override the hash, page_text, and/or meta data unintentionally, making comparisons impossible.
|
|
32
|
+
// Add additional parameters if request is made to run the AI. We only include these when saving new data.
|
|
33
|
+
// Most requests will not include these.
|
|
35
34
|
if (params.run_ai) {
|
|
36
35
|
params.hash = hash
|
|
37
36
|
params.page_text = pageText
|
|
38
|
-
params.metadata = getPageMetaData()
|
|
39
37
|
}
|
|
40
38
|
|
|
39
|
+
params.metadata = getPageMetaData()
|
|
40
|
+
|
|
41
41
|
const response = await fetch(apiBaseUrl + `/external-pages/?api-token=${apiToken}&include_title_details=true${isEditorialMode ? '&editorial_mode_enabled=true' : ''}&language=${language}`, {
|
|
42
42
|
headers,
|
|
43
43
|
method: 'POST',
|
|
@@ -28,24 +28,28 @@ describe('$lib/api', () => {
|
|
|
28
28
|
window.PlayPilotLinkInjections = { token: 'a' }
|
|
29
29
|
})
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
31
|
+
it('Should call fetch with given url and body', async () => {
|
|
32
|
+
fakeFetch({ response: 'Some response' })
|
|
33
|
+
|
|
34
|
+
const response = await fetchLinkInjections('Some text', { url: 'https://some-url', hash: 'some-hash' })
|
|
35
|
+
|
|
36
|
+
expect(response).toBe('Some response')
|
|
37
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
38
|
+
expect.stringContaining('api-token'),
|
|
39
|
+
expect.objectContaining({
|
|
40
|
+
body: JSON.stringify({
|
|
41
|
+
url: 'https://some-url',
|
|
42
|
+
metadata: {
|
|
43
|
+
content_heading: null,
|
|
44
|
+
content_modified_time: null,
|
|
45
|
+
content_published_time: null,
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
method: 'POST',
|
|
49
|
+
headers: expect.any(Object),
|
|
50
|
+
}),
|
|
51
|
+
)
|
|
52
|
+
})
|
|
49
53
|
|
|
50
54
|
it('Should call fetch with full details when fetching with run_ai as true', async () => {
|
|
51
55
|
fakeFetch({ response: 'Some response' })
|